[Zope-Checkins] CVS: Zope2 - UnTextIndex.py:1.44

Chris McDonough chrism@digicool.com
Thu, 22 Mar 2001 02:05:20 -0500 (EST)


Update of /cvs-repository/Zope2/lib/python/SearchIndex
In directory korak:/home/chrism/sandboxes/TrunkBranch/lib/python/SearchIndex

Modified Files:
	UnTextIndex.py 
Log Message:
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')



--- Updated File UnTextIndex.py in package Zope2 --
--- UnTextIndex.py	2001/03/21 22:05:04	1.43
+++ UnTextIndex.py	2001/03/22 07:05:20	1.44
@@ -93,7 +93,6 @@
 
 __version__ = '$Revision$'[11:-2]
 
-
 import string, regex, regsub, ts_regex
 import operator
 
@@ -117,7 +116,7 @@
 Near = '...'
 QueryError = 'TextIndex.QueryError'
 
-            
+
 class UnTextIndex(Persistent, Implicit):
     """Full-text index.
 
@@ -478,12 +477,26 @@
         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 @@
             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: