changeset 4969:75cbff83e907

Xapian2009:Part of xapian search code was refactored. Search._xapianMatch is broken must be refactored.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Mon, 27 Jul 2009 21:37:15 +0200
parents b0afbf750a24
children b78a768f142b
files MoinMoin/search/Xapian.py MoinMoin/search/builtin.py
diffstat 2 files changed, 16 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/search/Xapian.py	Mon Jul 27 19:20:08 2009 +0200
+++ b/MoinMoin/search/Xapian.py	Mon Jul 27 21:37:15 2009 +0200
@@ -311,29 +311,22 @@
         """
         while True:
             try:
-                searcher, timestamp = self.request.cfg.xapian_searchers.pop()
+                connection, timestamp = self.request.cfg.xapian_searchers.pop()
                 if timestamp != self.mtime():
-                    searcher.close()
+                    connection.close()
                 else:
                     break
             except IndexError:
-                searcher = xapidx.ReadOnlyIndex(self.dir)
-                searcher.configure(self.prefixMap, self.indexValueMap)
+                connection = xappy.SearchConnection(self.dir)
                 timestamp = self.mtime()
                 break
 
         kw = {}
-        if sort == 'weight':
-            # XXX: we need real weight here, like _moinSearch
-            # (TradWeight in xapian)
-            kw['sortByRelevence'] = True
-            kw['sortKey'] = 'revision'
         if sort == 'page_name':
-            kw['sortKey'] = 'pagename'
+            kw['sortby'] = 'pagename'
 
-        hits = searcher.search(query, valuesWanted=['pagename',
-            'attachment', 'mtime', 'wikiname', 'revision'], **kw)
-        self.request.cfg.xapian_searchers.append((searcher, timestamp))
+        hits = connection.search(query, 0, 1000, **kw) # XXX which value should be for the endrank parameter (now it is 1000)?
+        self.request.cfg.xapian_searchers.append((connection, timestamp))
         return hits
 
     def _do_queued_updates(self, request, amount=5):
--- a/MoinMoin/search/builtin.py	Mon Jul 27 19:20:08 2009 +0200
+++ b/MoinMoin/search/builtin.py	Mon Jul 27 21:37:15 2009 +0200
@@ -516,34 +516,22 @@
         if index and self.query.xapian_wanted():
             clock.start('_xapianSearch')
             try:
-                from MoinMoin.support import xapwrap
 
                 clock.start('_xapianQuery')
                 query = self.query.xapian_term(self.request, index.allterms)
                 description = str(query)
                 logging.debug("_xapianSearch: query = %r" % description)
-                query = xapwrap.index.QObjQuery(query)
-                enq, mset, hits = index.search(query, sort=self.sort,
-                        historysearch=self.historysearch)
+                hits = index.search(query, sort=self.sort,
+                                    historysearch=self.historysearch)
                 clock.stop('_xapianQuery')
-
                 logging.debug("_xapianSearch: finds: %r" % hits)
-                def dict_decode(d):
-                    """ decode dict values to unicode """
-                    for key in d:
-                        d[key] = d[key].decode(config.charset)
-                    return d
-                pages = [dict_decode(hit['values']) for hit in hits]
+
+                pages = [hit.data for hit in hits]
                 logging.debug("_xapianSearch: finds pages: %r" % pages)
 
-                self._xapianEnquire = enq
-                self._xapianMset = mset
                 self._xapianIndex = index
             except BaseIndex.LockedException:
                 pass
-            #except AttributeError:
-            #    pages = []
-
             try:
                 # xapian handled the full query
                 if not self.query.xapian_need_postproc():
@@ -627,22 +615,14 @@
         hits = []
         revisionCache = {}
         fs_rootpage = self.fs_rootpage
-        for hit in pages:
-            if 'values' in hit:
-                valuedict = hit['values']
-                uid = hit['uid']
-            else:
-                valuedict = hit
-                uid = None
 
-            wikiname = valuedict['wikiname']
-            pagename = valuedict['pagename']
-            attachment = valuedict['attachment']
+        for hit in pages:
 
-            if 'revision' in valuedict and valuedict['revision']:
-                revision = int(valuedict['revision'])
-            else:
-                revision = 0
+            uid = hit.id
+            wikiname = hit.data['wikiname'][0]
+            pagename = hit.data['pagename'][0]
+            attachment = hit.data['attachment'][0]
+            revision = int(hit.data.get('revision', [0])[0])
             logging.debug("_getHits processing %r %r %d %r" % (wikiname, pagename, revision, attachment))
 
             if wikiname in (self.request.cfg.interwikiname, 'Self'): # THIS wiki