changeset 857:d93a8a6a4559

now searching works without having xapian installed
author Franz Pletz <fpletz AT franz-pletz DOT org>
date Mon, 19 Jun 2006 11:31:00 +0200
parents e69f2c2a238d
children db0e4edcb6ac
files MoinMoin/Xapian.py MoinMoin/search.py docs/CHANGES.fpletz
diffstat 3 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Xapian.py	Mon Jun 19 11:16:04 2006 +0200
+++ b/MoinMoin/Xapian.py	Mon Jun 19 11:31:00 2006 +0200
@@ -12,6 +12,7 @@
 from pprint import pprint
 
 import xapian
+from xapian import Query
 from MoinMoin.support.xapwrap import document as xapdoc
 from MoinMoin.support.xapwrap import index as xapidx
 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
--- a/MoinMoin/search.py	Mon Jun 19 11:16:04 2006 +0200
+++ b/MoinMoin/search.py	Mon Jun 19 11:31:00 2006 +0200
@@ -15,9 +15,12 @@
 from MoinMoin import wikiutil, config
 from MoinMoin.Page import Page
 
-import Xapian
-from xapian import Query
-from Xapian import UnicodeQuery
+try:
+    import Xapian
+    from Xapian import Query, UnicodeQuery
+    use_stemming = Xapian.use_stemming
+except ImportError:
+    use_stemming = False
 
 #############################################################################
 ### query objects
@@ -272,7 +275,7 @@
         # Search in page body
         body = page.get_raw_body()
         for match in self.search_re.finditer(body):
-            if Xapian.use_stemming:
+            if use_stemming:
                 # somewhere in regular word
                 if body[match.start()] not in config.chars_upper and \
                         body[match.start()-1] in config.chars_lower:
@@ -314,7 +317,7 @@
             queries = []
             stemmed = []
             for t in terms:
-                if Xapian.use_stemming:
+                if use_stemming:
                     # stemmed OR not stemmed
                     tmp = []
                     for i in analyzer.tokenize(t, flat_stemming=False):
@@ -376,7 +379,7 @@
         # Get matches in page name
         matches = []
         for match in self.search_re.finditer(page.page_name):
-            if Xapian.use_stemming:
+            if use_stemming:
                 # somewhere in regular word
                 if page.page_name[match.start()] not in config.chars_upper and \
                         page.page_name[match.start()-1] in config.chars_lower:
@@ -418,7 +421,7 @@
             queries = []
             stemmed = []
             for t in terms:
-                if Xapian.use_stemming:
+                if use_stemming:
                     # stemmed OR not stemmed
                     tmp = []
                     for i in analyzer.tokenize(t, flat_stemming=False):
--- a/docs/CHANGES.fpletz	Mon Jun 19 11:16:04 2006 +0200
+++ b/docs/CHANGES.fpletz	Mon Jun 19 11:31:00 2006 +0200
@@ -77,4 +77,5 @@
         Possible extension: Xapian can handle multiple databases, maybe
         allow searching across defined wikis on a wikifarm?
     * All stemming/matching issues resolved (hopefully)
+    * Works now without xapian installed (enhance error reporting)