/
keyword.py
59 lines (38 loc) · 1.24 KB
/
keyword.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from zope.interface import implements
from zope.index.keyword import KeywordIndex
from ..interfaces import ICatalogIndex
from .common import CatalogIndex
class CatalogKeywordIndex(CatalogIndex, KeywordIndex):
"""
Keyword index.
Query types supported:
- Eq
- NotEq
- In
- NotIn
- Any
- NotAny
- All
- NotAll
"""
implements(ICatalogIndex)
def __init__(self, discriminator):
if not callable(discriminator):
if not isinstance(discriminator, basestring):
raise ValueError('discriminator value must be callable or a '
'string')
self.discriminator = discriminator
self._not_indexed = self.family.IF.Set()
self.clear()
def reindex_doc(self, docid, value):
# the base index' index_doc method special-cases a reindex
return self.index_doc(docid, value)
def _indexed(self):
return self._rev_index.keys()
def applyAny(self, values):
return self.apply({'query': values, 'operator': 'or'})
applyIn = applyAny
def applyAll(self, values):
return self.apply({'query': values, 'operator': 'and'})
def applyEq(self, value):
return self.apply([value])