Skip to content

Commit

Permalink
Extend not support to keyword indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Mar 25, 2012
1 parent 054ef93 commit cdaba62
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
7 changes: 4 additions & 3 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Changelog
3.0 (unreleased)
----------------

- Added support for `not` queries to FieldIndexes. Both restrictions of normal
queries and range queries are supported, as well as purely exclusive
queries. For example: `{'foo': {'query': ['a', 'ab'], 'not': 'a'}}`,
- Added support for `not` queries in field and keyword indexes. Both
restrictions of normal queries and range queries are supported, as well as
purely exclusive queries. For example:
`{'foo': {'query': ['a', 'ab'], 'not': 'a'}}`,
`{'query': 'a', 'range': 'min', 'not': ['a', 'e', 'f']}}` and
`{'foo': {'not': ['a', 'b']}}`.

Expand Down
2 changes: 1 addition & 1 deletion src/Products/PluginIndexes/KeywordIndex/KeywordIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class KeywordIndex(UnIndex):
{'label': 'Browse', 'action': 'manage_browse'},
)

query_options = ("query", "operator", "range")
query_options = ("query", "operator", "range", "not")

def _index_object(self, documentId, obj, threshold=None, attr=''):
""" index an object 'obj' with integer id 'i'
Expand Down
14 changes: 14 additions & 0 deletions src/Products/PluginIndexes/KeywordIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ def setUp(self):
self._string_req = {'foo': 'a'}
self._zero_req = {'foo': [0]}

self._not_1 = {'foo': {'query': 'f', 'not': 'f'}}
self._not_2 = {'foo': {'query': ['e', 'f'], 'not': 'f'}}
self._not_3 = {'foo': {'not': 0}}
self._not_4 = {'foo': {'not': [0, 'e']}}
self._not_5 = {'foo': {'not': [0, 'no-value']}}
self._not_6 = {'foo': 'c', 'bar': {'query': 123, 'not': 1}}

def _populateIndex(self):
for k, v in self._values:
self._index.index_object(k, v)
Expand Down Expand Up @@ -137,6 +144,13 @@ def testPopulated(self):
self._checkApply(self._overlap_req, values[2:7])
self._checkApply(self._string_req, values[:-1])

self._checkApply(self._not_1, [])
self._checkApply(self._not_2, values[5:6])
self._checkApply(self._not_3, values[:7])
self._checkApply(self._not_4, values[:5])
self._checkApply(self._not_5, values[:7])
self._checkApply(self._not_6, values[2:7])

def testZero(self):
self._populateIndex()
values = self._values
Expand Down
1 change: 0 additions & 1 deletion src/Products/PluginIndexes/common/UnIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ def _apply_index(self, request, resultset=None):
if not record.keys and not_parm:
# we have only a 'not' query
record.keys = [k for k in index.keys() if k not in not_parm]
not_parm = None

# experimental code for specifing the operator
operator = record.get('operator',self.useOperator)
Expand Down

0 comments on commit cdaba62

Please sign in to comment.