changeset 5272:a728d059c78e

search package: docstring cleanup, src code formatting fixes
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 09 Nov 2009 03:09:29 +0100
parents 4a4c2471b419
children c3b272d83749
files MoinMoin/search/Xapian/indexing.py MoinMoin/search/Xapian/tokenizer.py MoinMoin/search/__init__.py MoinMoin/search/builtin.py MoinMoin/search/results.py
diffstat 5 files changed, 14 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/search/Xapian/indexing.py	Mon Nov 09 01:04:00 2009 +0100
+++ b/MoinMoin/search/Xapian/indexing.py	Mon Nov 09 03:09:29 2009 +0100
@@ -2,8 +2,8 @@
 """
     MoinMoin - xapian search engine indexing
 
-    @copyright: 2006-2008 MoinMoin:ThomasWaldmann,
-                2006 MoinMoin:FranzPletz
+    @copyright: 2006-2009 MoinMoin:ThomasWaldmann,
+                2006 MoinMoin:FranzPletz,
                 2009 MoinMoin:DmitrijsMilajevs
     @license: GNU GPL, see COPYING for details.
 """
@@ -31,7 +31,7 @@
 
     def __init__(self, *args, **kwargs):
         """
-        @keyword encoding: specifiy the encoding manually (default: value of config.charset)
+        @keyword encoding: specify the encoding manually (default: value of config.charset)
         """
         self.encoding = kwargs.get('encoding', config.charset)
 
@@ -67,9 +67,7 @@
 class MoinIndexerConnection(xappy.IndexerConnection):
 
     def __init__(self, *args, **kwargs):
-
         super(MoinIndexerConnection, self).__init__(*args, **kwargs)
-
         self._define_fields_actions()
 
     def _define_fields_actions(self):
@@ -111,17 +109,13 @@
 class StemmedField(xappy.Field):
 
     def __init__(self, name, value, request):
-
         analyzer = WikiAnalyzer(request=request, language=request.cfg.language_default)
-
         value = ' '.join(unicode('%s %s' % (word, stemmed)).strip() for word, stemmed in analyzer.tokenize(value))
-
         super(StemmedField, self).__init__(name, value)
 
 
 class XapianIndex(BaseIndex):
 
-
     def _main_dir(self):
         """ Get the directory of the xapian index """
         if self.request.cfg.xapian_index_dir:
@@ -136,11 +130,11 @@
 
     def _search(self, query, sort='weight', historysearch=0):
         """
-        Perform the search using xapian (read-lock acquired)
+        Perform the search using xapian
 
         @param query: the search query objects
-        @keyword sort: the sorting of the results (default: 'weight')
-        @keyword historysearch: whether to search in all page revisions (default: 0) TODO: use/implement this
+        @param sort: the sorting of the results (default: 'weight')
+        @param historysearch: whether to search in all page revisions (default: 0) TODO: use/implement this
         """
         while True:
             try:
@@ -442,7 +436,6 @@
         pagename = page.page_name
 
         if not attachment:
-
             search_connection = MoinSearchConnection(self.dir)
             docs_to_delete = search_connection.get_all_documents_with_field('fulltitle', pagename)
             ids_to_delete = [d.id for d in docs_to_delete]
@@ -450,22 +443,19 @@
 
             for id_ in ids_to_delete:
                 connection.delete(id_)
-                logging.debug('%s removed from xapian index' % pagename)
+                logging.debug('page %s removed from xapian index' % pagename)
         else:
             # Only remove a single attachment
             id_ = "%s:%s//%s" % (wikiname, pagename, attachment)
             connection.delete(id_)
 
-            logging.debug('attachment %s from %s removed from index' % (attachment, pagename))
+            logging.debug('attachment %s (page %s) removed from index' % (attachment, pagename))
 
     def _index_pages(self, request, files=None, mode='update', pages=None):
         """ Index pages (and all given files)
 
         This should be called from indexPages or indexPagesInNewThread only!
 
-        This may take some time, depending on the size of the wiki and speed
-        of the machine.
-
         When called in a new thread, lock is acquired before the call,
         and this method must release it when it finishes or fails.
 
--- a/MoinMoin/search/Xapian/tokenizer.py	Mon Nov 09 01:04:00 2009 +0100
+++ b/MoinMoin/search/Xapian/tokenizer.py	Mon Nov 09 03:09:29 2009 +0100
@@ -17,7 +17,7 @@
 class WikiAnalyzer(object):
     """ A text analyzer for wiki syntax
 
-    The purpose of this class is to anaylze texts/pages in wiki syntax
+    The purpose of this class is to analyze texts/pages in wiki syntax
     and yield single terms to feed into the xapian database.
     """
 
--- a/MoinMoin/search/__init__.py	Mon Nov 09 01:04:00 2009 +0100
+++ b/MoinMoin/search/__init__.py	Mon Nov 09 03:09:29 2009 +0100
@@ -32,7 +32,6 @@
     @rtype: SearchResults instance
     @return: search results
     """
-
     return _get_searcher(request, query, sort, mtime, historysearch, **kw).run()
 
 
--- a/MoinMoin/search/builtin.py	Mon Nov 09 01:04:00 2009 +0100
+++ b/MoinMoin/search/builtin.py	Mon Nov 09 03:09:29 2009 +0100
@@ -126,11 +126,6 @@
         self.update_queue = PageQueue(request, main_dir, 'update-queue')
         self.remove_queue = PageQueue(request, main_dir, 'remove-queue')
 
-        # Disabled until we have a sane way to build the index with a
-        # queue in small steps.
-        ## if not self.exists():
-        ##    self.indexPagesInNewThread(request)
-
     def _main_dir(self):
         raise NotImplemented('...')
 
@@ -147,7 +142,7 @@
         filesys.touch(self.dir)
 
     def _search(self, query):
-        """ Actually perfom the search (read-lock acquired)
+        """ Actually perfom the search
 
         @param query: the search query objects tree
         """
@@ -234,9 +229,6 @@
 
         This should be called from indexPages or indexPagesInNewThread only!
 
-        This may take some time, depending on the size of the wiki and speed
-        of the machine.
-
         When called in a new thread, lock is acquired before the call,
         and this method must release it when it finishes or fails.
 
@@ -296,7 +288,7 @@
             raise
 
     def _do_queued_updates(self, request, amount=5):
-        """ Perform updates in the queues (read-lock acquired)
+        """ Perform updates in the queues
 
         @param request: the current request
         @keyword amount: how many updates to perform at once (default: 5)
@@ -412,7 +404,7 @@
         Search pages.
 
         Return list of tuples (wikiname, page object, attachment,
-        matches, revision) and estimated number of search results (If
+        matches, revision) and estimated number of search results (if
         there is no estimate, None should be returned).
 
         The list may contain deleted pages or pages the user may not read.
--- a/MoinMoin/search/results.py	Mon Nov 09 01:04:00 2009 +0100
+++ b/MoinMoin/search/results.py	Mon Nov 09 03:09:29 2009 +0100
@@ -202,7 +202,7 @@
 
 
 class FoundRemote(FoundPage):
-    """ Represents an attachment in search results """
+    """ Represents a remote search result """
 
     def __init__(self, wikiname, page_name, attachment, matches=None, page=None, rev=0):
         self.wikiname = wikiname
@@ -382,11 +382,6 @@
                             maxlines=1, paging=True, hitsFrom=0, hitsInfo=0):
         """ Format a list of found pages with context
 
-        The default parameter values will create Google-like search
-        results, as this is the most known search interface. Good
-        interface is familiar interface, so unless we have much better
-        solution (we don't), being like Google is the way.
-
         @param request: current request
         @param formatter: formatter to use
         @param info: show match info near the page link
@@ -801,8 +796,7 @@
 
         Do not call this, it should be called only by the instance code.
 
-        Each request might need different translations or other user
-        preferences.
+        Each request might need different translations or other user preferences.
 
         @param request: current request
         @param formatter: the formatter instance to use