changeset 818:7250d2be26d6

add prefix support, make RawQuery unicode-compatible
author Franz Pletz <fpletz AT franz-pletz DOT org>
date Sat, 10 Jun 2006 10:43:48 +0200
parents 0842d11e0f01
children cbdf642bc58e
files MoinMoin/Xapian.py MoinMoin/search.py MoinMoin/support/xapwrap/index.py
diffstat 3 files changed, 40 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Xapian.py	Sat Jun 10 09:11:14 2006 +0200
+++ b/MoinMoin/Xapian.py	Sat Jun 10 10:43:48 2006 +0200
@@ -205,6 +205,41 @@
 
 
 class Index:
+    indexValueMap = {
+        # mapping the value names we can easily fetch from the index to
+        # integers required by xapian. 0 and 1 are reserved by xapwrap!
+        'pagename': 2,
+        'attachment': 3,
+        'mtime': 4,
+        'wikiname': 5,
+    }
+    prefixMap = {
+        # http://svn.xapian.org/*checkout*/trunk/xapian-applications/omega/docs/termprefixes.txt
+        'author': 'A',
+        'date':   'D', # numeric format: YYYYMMDD or "latest" - e.g. D20050224 or Dlatest
+                       #G   newsGroup (or similar entity - e.g. a web forum name)
+        'hostname': 'H',
+        'keyword': 'K',
+        'lang': 'L',   # ISO Language code
+                       #M   Month (numeric format: YYYYMM)
+                       #N   ISO couNtry code (or domaiN name)
+                       #P   Pathname
+                       #Q   uniQue id
+                       #R   Raw (i.e. unstemmed) term
+        'title': 'S',  # Subject (or title)
+        'mimetype': 'T',
+        'url': 'U',    # full URL of indexed document - if the resulting term would be > 240
+                       # characters, a hashing scheme is used to prevent overflowing
+                       # the Xapian term length limit (see omindex for how to do this).
+                       #W   "weak" (approximately 10 day intervals, taken as YYYYMMD from
+                       #  the D term, and changing the last digit to a '2' if it's a '3')
+                       #X   longer prefix for user-defined use
+        'linkto': 'XLINKTO', # this document links to that document
+                       #Y   year (four digits)
+    }
+
+
+
     class LockedException(Exception):
         pass
     
@@ -227,38 +262,6 @@
         ## if not self.exists():
         ##    self.indexPagesInNewThread(request)
 
-        self.indexValueMap = {
-            # mapping the value names we can easily fetch from the index to
-            # integers required by xapian. 0 and 1 are reserved by xapwrap!
-            'pagename': 2,
-            'attachment': 3,
-            'mtime': 4,
-            'wikiname': 5,
-        }
-        self.prefixMap = { # http://svn.xapian.org/*checkout*/trunk/xapian-applications/omega/docs/termprefixes.txt
-            'author': 'A',
-            'date':   'D', # numeric format: YYYYMMDD or "latest" - e.g. D20050224 or Dlatest
-                           #G   newsGroup (or similar entity - e.g. a web forum name)
-            'hostname': 'H',
-            'keyword': 'K',
-            'lang': 'L',   # ISO Language code
-                           #M   Month (numeric format: YYYYMM)
-                           #N   ISO couNtry code (or domaiN name)
-                           #P   Pathname
-                           #Q   uniQue id
-                           #R   Raw (i.e. unstemmed) term
-            'title': 'S',  # Subject (or title)
-            'mimetype': 'T',
-            'url': 'U',    # full URL of indexed document - if the resulting term would be > 240
-                           # characters, a hashing scheme is used to prevent overflowing
-                           # the Xapian term length limit (see omindex for how to do this).
-                           #W   "weak" (approximately 10 day intervals, taken as YYYYMMD from
-                           #  the D term, and changing the last digit to a '2' if it's a '3')
-                           #X   longer prefix for user-defined use
-            'linkto': 'XLINKTO', # this document links to that document
-                           #Y   year (four digits)
-        }
-        
     def exists(self):
         """ Check if index exists """        
         return os.path.exists(self.sig_file)
--- a/MoinMoin/search.py	Sat Jun 10 09:11:14 2006 +0200
+++ b/MoinMoin/search.py	Sat Jun 10 10:43:48 2006 +0200
@@ -375,7 +375,7 @@
             queries = []
             for t in terms:
                 t = [i.encode('utf-8') for i in list(analyzer.tokenize(t))]
-                t = ['title:%s' % i for i in t]
+                t = ['%s%s' % (Xapian.Index.prefixMap['title'], i) for i in t]
                 if len(t) < 2:
                     queries.append(xapian.Query(t[0]))
                 else:
@@ -468,7 +468,7 @@
         if self.use_re:
             return None # xapian doesnt support regex search
         else:
-            term = xapian.Query(('linkto:%s' % pattern.lower()).encode('utf-8'))
+            term = xapian.Query(('%s%s' % (Xapian.Index.prefixMap['linkto'], pattern.lower())).encode('utf-8'))
             return term
 
 ############################################################################
--- a/MoinMoin/support/xapwrap/index.py	Sat Jun 10 09:11:14 2006 +0200
+++ b/MoinMoin/support/xapwrap/index.py	Sat Jun 10 10:43:48 2006 +0200
@@ -872,6 +872,9 @@
 
 class RawQuery(Query):
     def __init__(self, queryString):
+        if isinstance(queryString, unicode):
+            queryString = queryString.encode('utf-8')
+
         assert isinstance(queryString, str)
         self.queryString = queryString