Commit e00f486a authored by Chris McDonough's avatar Chris McDonough

Added logic to use the value of 'textindex_operator' as passed in the request...

Added logic to use the value of 'textindex_operator' as passed in the request to determine which query operator to use (and, near, andnot, or).  Valid values to pass in to textindex_operator are 'and', 'or', 'near', and 'andnot' (capitalization is ignored).  This is a near-term workaround for the inability to specify a default text index query operator on a per-index basis.  It provides the ability to override the currently module-defined default 'Or' operator for textindexes on a per-search basis.

An example of the utility of textindex_operator used with a ZCatalog instance:

zcatalog.searchResults(PrincipiaSearchSource='foo', textindex_operator='and')
parent 4173d042
......@@ -91,8 +91,7 @@ undo information so that objects can be unindexed when the old value
is no longer known.
"""
__version__ = '$Revision: 1.43 $'[11:-2]
__version__ = '$Revision: 1.44 $'[11:-2]
import string, regex, regsub, ts_regex
import operator
......@@ -478,12 +477,26 @@ class UnTextIndex(Persistent, Implicit):
records. The second object is a tuple containing the names of
all data fields used.
"""
if request.has_key(self.id):
keys = request[self.id]
else:
return None
operators = {
'andnot':AndNot,
'and':And,
'near':Near,
'or':Or
}
query_operator = Or
# We default to 'or' if we aren't passed an operator in the request
# or if we can't make sense of the passed-in operator
if request.has_key('textindex_operator'):
op=string.lower(str(request['textindex_operator']))
query_operator = operators.get(op, query_operator)
if type(keys) is StringType:
if not keys or not string.strip(keys):
return None
......@@ -496,7 +509,7 @@ class UnTextIndex(Persistent, Implicit):
if not key:
continue
b = self.query(key).bucket()
b = self.query(key, query_operator).bucket()
w, r = weightedIntersection(r, b)
if r is not None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment