changeset 5036:4b2ef153ad4f

Xapian2009: pep8 and typo fixes.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Sun, 23 Aug 2009 13:37:27 +0200
parents 93becb451375
children 712677d7023c
files MoinMoin/search/Xapian/_tests/test_wiki_analyzer.py MoinMoin/search/Xapian/indexing.py MoinMoin/search/Xapian/tokenizer.py MoinMoin/search/_tests/test_search.py MoinMoin/search/builtin.py MoinMoin/search/queryparser/expressions.py
diffstat 6 files changed, 33 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/search/Xapian/_tests/test_wiki_analyzer.py	Sat Aug 22 20:54:24 2009 +0200
+++ b/MoinMoin/search/Xapian/_tests/test_wiki_analyzer.py	Sun Aug 23 13:37:27 2009 +0200
@@ -82,6 +82,7 @@
 
         xapian_stemming = True
 
+
 class TestWikiAnalyzerStemmedHelpOnEditing(TestWikiAnalyzer):
 
     word = u'HelpOnEditing'
--- a/MoinMoin/search/Xapian/indexing.py	Sat Aug 22 20:54:24 2009 +0200
+++ b/MoinMoin/search/Xapian/indexing.py	Sun Aug 23 13:37:27 2009 +0200
@@ -15,7 +15,6 @@
 logging = log.getLogger(__name__)
 
 from MoinMoin.support import xappy
-from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
 from MoinMoin.search.builtin import BaseIndex
 from MoinMoin.search.Xapian.tokenizer import WikiAnalyzer
 
@@ -108,13 +107,13 @@
         self.add_field_action('category', INDEX_EXACT)
         self.add_field_action('category', STORE_CONTENT)
 
+
 class StemmedField(xappy.Field):
 
     def __init__(self, name, value, request):
 
         analyzer = WikiAnalyzer(request=request, language=request.cfg.language_default)
 
-        tokens = analyzer.tokenize(value)
         value = ' '.join(unicode('%s %s' % (word, stemmed)).strip() for word, stemmed in analyzer.tokenize(value))
 
         super(StemmedField, self).__init__(name, value)
@@ -172,16 +171,17 @@
                 timestamp = self.mtime()
                 break
 
-        kw = {}
-        if sort == 'page_name':
-            kw['sortby'] = 'pagename'
-
         # Refresh connection, since it may be outdated.
         searcher.reopen()
         query = query.xapian_term(self.request, searcher)
 
         # Get maximum possible amount of hits from xappy, which is number of documents in the index.
         document_count = searcher.get_doccount()
+
+        kw = {}
+        if sort == 'page_name':
+            kw['sortby'] = 'pagename'
+
         hits = searcher.search(query, 0, document_count, **kw)
 
         self.request.cfg.xapian_searchers.append((searcher, timestamp))
@@ -201,7 +201,7 @@
         items = self.remove_queue.pages()[:amount]
         for item in items:
             assert len(item.split('//')) == 2
-            pagename,  attachment = item.split('//')
+            pagename, attachment = item.split('//')
             page = Page(request, pagename)
             self._remove_item(request, connection, page, attachment)
             self.remove_queue.remove([item])
@@ -244,8 +244,7 @@
             for value in values:
                 document.fields.append(xappy.Field(field, value))
 
-
-    def _index_file(self, request, writer, filename, mode='update'):
+    def _index_file(self, request, connection, filename, mode='update'):
         """ index a file as it were a page named pagename
             Assumes that the write lock is acquired
         """
@@ -267,15 +266,15 @@
 
                 fields['wikiname'] = wikiname
                 fields['pagename'] = fs_rootpage
-                fileds['attachment'] = filename # XXX we should treat files like real pages, not attachments
+                fields['attachment'] = filename # XXX we should treat files like real pages, not attachments
                 fields['mtime'] = str(mtime)
                 fields['revision'] = '0'
                 fields['title'] = " ".join(os.path.join(fs_rootpage, filename).split("/"))
                 fields['content'] = file_content
 
-                multivalued_fileds['mimetype'] = [mt for mt in [mimetype] + mimetype.split('/')]
+                multivalued_fields['mimetype'] = [mt for mt in [mimetype] + mimetype.split('/')]
 
-                self._add_fields_to_document(request, doc, fields, multivalued_fields, stemed_fields)
+                self._add_fields_to_document(request, doc, fields, multivalued_fields)
 
                 connection.replace(doc)
 
@@ -348,16 +347,16 @@
         @arg mode: 'add' = just add, no checks
                    'update' = check if already in index and update if needed (mtime)
         """
-        p = Page(request, pagename)
+        page = Page(request, pagename)
         if request.cfg.xapian_index_history:
-            for rev in p.getRevList():
+            for rev in page.getRevList():
                 updated = self._index_page_rev(request, connection, Page(request, pagename, rev=rev), mode=mode)
                 logging.debug("updated page %r rev %d (updated==%r)" % (pagename, rev, updated))
                 if not updated:
                     # we reached the revisions that are already present in the index
                     break
         else:
-            self._index_page_rev(request, connection, p, mode=mode)
+            self._index_page_rev(request, connection, page, mode=mode)
 
         self._index_attachments(request, connection, pagename, mode)
 
@@ -382,16 +381,16 @@
                 mimetype, att_content = self.contentfilter(filename)
 
                 fields['wikiname'] = wikiname
-                fileds['pagename'] = pagename
-                fileds['attachment'] = att
+                fields['pagename'] = pagename
+                fields['attachment'] = att
                 fields['mtime'] = str(mtime)
-                fileds['revision'] = '0'
+                fields['revision'] = '0'
                 fields['title'] = '%s/%s' % (pagename, att)
                 fields['content'] = att_content
-                fileds['fulltitle'] = pagename
+                fields['fulltitle'] = pagename
                 fields['lang'], fields['stem_lang'] = self._get_languages(page)
 
-                multivalued_fileds['mimetype'] = [mt for mt in [mimetype] + mimetype.split('/')]
+                multivalued_fields['mimetype'] = [mt for mt in [mimetype] + mimetype.split('/')]
                 multivalued_fields['domain'] = self._get_domains(page)
 
                 self._add_fields_to_document(request, doc, fields, multivalued_fields)
@@ -456,13 +455,13 @@
             ids_to_delete = [d.id for d in docs_to_delete]
             search_connection.close()
 
-            for id in ids_to_delete:
-                connection.delete(id)
+            for id_ in ids_to_delete:
+                connection.delete(id_)
                 logging.debug('%s removed from xapian index' % pagename)
         else:
             # Only remove a single attachment
-            id = "%s:%s//%s" % (wikiname, pagename, attachment)
-            connection.delete(id)
+            id_ = "%s:%s//%s" % (wikiname, pagename, attachment)
+            connection.delete(id_)
 
             logging.debug('attachment %s from %s removed from index' % (attachment, pagename))
 
@@ -489,8 +488,8 @@
 
         # rebuilding the DB: delete it and add everything
         if mode == 'rebuild':
-            for f in os.listdir(self.dir):
-                os.unlink(os.path.join(self.dir, f))
+            for fname in os.listdir(self.dir):
+                os.unlink(os.path.join(self.dir, fname))
             mode = 'add'
 
         connection = MoinIndexerConnection(self.dir)
--- a/MoinMoin/search/Xapian/tokenizer.py	Sat Aug 22 20:54:24 2009 +0200
+++ b/MoinMoin/search/Xapian/tokenizer.py	Sun Aug 23 13:37:27 2009 +0200
@@ -13,6 +13,7 @@
 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
 from MoinMoin import config
 
+
 class WikiAnalyzer(object):
     """ A text analyzer for wiki syntax
 
@@ -106,6 +107,7 @@
                       unicode objects
         """
         if self.stemmer:
+
             def stemmer(value):
                 stemmed = self.stemmer(value)
                 if stemmed != value:
--- a/MoinMoin/search/_tests/test_search.py	Sat Aug 22 20:54:24 2009 +0200
+++ b/MoinMoin/search/_tests/test_search.py	Sun Aug 23 13:37:27 2009 +0200
@@ -282,6 +282,7 @@
         del self.pages['TestCreatePage']
         assert len(result.hits) == 1
 
+
 class TestMoinSearch(BaseSearchTest):
 
     def get_searcher(self, query):
@@ -377,6 +378,7 @@
         result = self.search(u"title:editing")
         assert len(result.hits) == 2
 
+
 class TestXapianIndexingInNewThread(object):
     """ search: test Xapian indexing """
 
--- a/MoinMoin/search/builtin.py	Sat Aug 22 20:54:24 2009 +0200
+++ b/MoinMoin/search/builtin.py	Sun Aug 23 13:37:27 2009 +0200
@@ -553,7 +553,7 @@
                     matches = self._get_match(page=page, uid=uid)
                     logging.debug("self._get_match %r" % matches)
                     if matches:
-                        if not self.historysearch and  pagename in revisionCache and revisionCache[pagename][0] < revision:
+                        if not self.historysearch and pagename in revisionCache and revisionCache[pagename][0] < revision:
                             hits.remove(revisionCache[pagename][1])
                             del revisionCache[pagename]
                         hits.append((wikiname, page, attachment, matches, revision))
--- a/MoinMoin/search/queryparser/expressions.py	Sat Aug 22 20:54:24 2009 +0200
+++ b/MoinMoin/search/queryparser/expressions.py	Sun Aug 23 13:37:27 2009 +0200
@@ -305,6 +305,7 @@
         # XXX: negated terms managed by _moinSearch?
         return Query(OP_OR, [term.xapian_term(request, connection) for term in self._subterms])
 
+
 class BaseTextFieldSearch(BaseExpression):
 
     _field_to_search = None
@@ -393,6 +394,7 @@
 
     def pageFilter(self):
         """ Page filter function for single title search """
+
         def filter(name):
             match = self.search_re.search(name)
             result = bool(self.negated) ^ bool(match)