[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG - TextIndexNG.py:1.2.2.12

Andreas Jung andreas@digicool.com
Tue, 15 Jan 2002 16:05:39 -0500


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG
In directory cvs.zope.org:/tmp/cvs-serv20329

Modified Files:
      Tag: ajung-textindexng-branch
	TextIndexNG.py 
Log Message:
- added ProximityLockup()
- minor changes


=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/TextIndexNG.py 1.2.2.11 => 1.2.2.12 ===
 
 
+class QueryException(Exception): pass
+
+
 class TextIndexNG(PluggableIndex.PluggableIndex, Persistent,
      Implicit, SimpleItem):
 
@@ -418,54 +421,6 @@
         del invIDX[documentID]
             
 
-    def __getitem__(self, word):
-        """Return an InvertedIndex-style result "list"
-
-        Note that this differentiates between being passed an Integer
-        and a String.  Strings are looked up in the lexicon, whereas
-        Integers are assumed to be resolved word ids. """
-
-        if isinstance(word, IntType):
-
-            # We have a word ID
-
-            r = {}
-
-            res = self._IDX.get(word, None)
-
-            for docId in  res.keys():
-                r[docId] = self._IDX[word][docId]
-
-            return ResultListNG(r , (word,), self)
-
-        else:
-
-            # We need to stem
-
-            if self._v_stemmerfunc:
-                word = self._v_stemmerfunc(word)
-
-            wids = self._v_getIdByWord(word)
-
-            if wids:
-                r = {}
-
-                res  = self._IDX.get(wids[0], None)
-
-                if self.nearStorage == 'internal':
-                    for docId in  res.keys():
-                        r[docId] = self._IDX[wids[0]][docId]
-
-                else: 
-                    for docId in res:
-                        r[docId] = IISet()
-
-            else:
-                r={}
-        
-            return ResultListNG(r, (word,), self)
-
-
     def getLexicon(self):
         return self._LEXICON
 
@@ -511,6 +466,7 @@
         """ to be finished """
 
         LL             = self.LexiconLookup
+        PL             = self.ProximityLookup
         txIntersection = self.txIntersection
         txUnion        = self.txUnion
         txNear         = self.txNear
@@ -518,6 +474,7 @@
         print "query",q
 
         self._parser.DoParse1( q )
+
         # XXX: Hack !!!
         parsed_query = C.getResult()
         print "parsed query", parsed_query
@@ -560,6 +517,36 @@
 
         return r
 
+    def ProximityLookup(self,word):
+        """ search a word in the proximity lexicon and return 
+            a ResultSet of found documents.
+        """
+
+        debug("ProximityLexionLookup: ",word)
+
+        if not self.useProximity:
+            raise QueryException, 'proximity search is not enabled'
+
+
+        # Lookup list of wordIds (usually should contain only *one*)
+        wids = self._PROX_LEX.get(word)
+        debug("\tWids: ", wids)
+
+        # Retrieve list of docIds for that wordId 
+        # XXX: internal storage only !
+        
+        # docIds is an IOBTree and contains the mapping
+        # (documentId, list of positions) for one word/wid
+        docIds = self._PROX_IDX.get(wids[0])
+
+        debug('\tDocIds: ', list(docIds.keys()))
+        debug('\tPositions: ', list(docIds.values()))
+
+        r = ResultSet( docIds, (word,))
+
+        return r
+
+
 
     def txIntersection(self, *sets):
         """ perform intersection of ResultSets """
@@ -604,8 +591,16 @@
         return r
         
 
-    def txNear(self, r1, r2):
+    def txNear(self, *sets):
         """ perform near intersection of two ResultSets """
+
+        # first we perform an intersection
+
+        r = self.txIntersection(*sets)
+
+        # XXX: Near search ...
+
+        return