changeset 1778:d56cd193cca0

whoosh: do not use convenience functions open_dir and create_in these whoosh convenience functions are hardcoded to just support the FileStorage (stores the whoosh index into a filesystem directory). if we want to use another whoosh backend, we can't use them. this first and quite simple changeset only replaces: create_in(...) -> storage = FileStorage(dir) ; storage.create_index(schema, name) open_dir(...) -> storage = FileStorage(dir) ; storage.open_index(name) More refactorings to make it really flexible will follow...
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 08 Sep 2012 19:54:54 +0200
parents 1db99f8f5144
children 082581e8688c
files MoinMoin/storage/middleware/indexing.py
diffstat 1 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/storage/middleware/indexing.py	Fri Sep 07 23:34:57 2012 +0200
+++ b/MoinMoin/storage/middleware/indexing.py	Sat Sep 08 19:54:54 2012 +0200
@@ -63,13 +63,14 @@
 from flask import current_app as app
 
 from whoosh.fields import Schema, TEXT, ID, IDLIST, NUMERIC, DATETIME, KEYWORD, BOOLEAN
-from whoosh.index import open_dir, create_in, EmptyIndexError
+from whoosh.index import EmptyIndexError
 from whoosh.writing import AsyncWriter
 from whoosh.qparser import QueryParser, MultifieldParser, RegexPlugin, \
                            PseudoFieldPlugin
 from whoosh.qparser import WordNode
 from whoosh.query import Every, Term
 from whoosh.sorting import FieldFacet
+from whoosh.filedb.filestore import FileStorage
 
 from MoinMoin import log
 logging = log.getLogger(__name__)
@@ -329,8 +330,9 @@
         """
         index_dir = self.index_dir
         try:
+            storage = FileStorage(index_dir)
             for name in INDEXES:
-                self.ix[name] = open_dir(index_dir, indexname=name)
+                self.ix[name] = storage.open_index(name)
         except (IOError, OSError, EmptyIndexError) as err:
             logging.error(u"{0!s} [while trying to open index '{1}' in '{2}']".format(err, name, index_dir))
             raise
@@ -355,8 +357,9 @@
             # in case there are problems with the index_dir
             pass
         try:
+            storage = FileStorage(index_dir)
             for name in INDEXES:
-                create_in(index_dir, self.schemas[name], indexname=name)
+                storage.create_index(self.schemas[name], indexname=name)
         except (IOError, OSError) as err:
             logging.error(u"{0!s} [while trying to create index '{1}' in '{2}']".format(err, name, index_dir))
             raise
@@ -491,7 +494,8 @@
               create (tmp), rebuild wiki1, rebuild wiki2, ..., move
         """
         index_dir = self.index_dir_tmp if tmp else self.index_dir
-        index = open_dir(index_dir, indexname=ALL_REVS)
+        storage = FileStorage(index_dir)
+        index = storage.open_index(ALL_REVS)
         try:
             # build an index of all we have (so we know what we have)
             all_revids = self.backend # the backend is an iterator over all revids
@@ -500,7 +504,7 @@
         finally:
             index.close()
         # now build the index of the latest revisions:
-        index = open_dir(index_dir, indexname=LATEST_REVS)
+        index = storage.open_index(LATEST_REVS)
         try:
             self._modify_index(index, self.schemas[LATEST_REVS], self.wikiname, latest_names_revids, 'add', procs, limitmb)
         finally:
@@ -520,7 +524,8 @@
         :returns: index changed (bool)
         """
         index_dir = self.index_dir_tmp if tmp else self.index_dir
-        index_all = open_dir(index_dir, indexname=ALL_REVS)
+        storage = FileStorage(index_dir)
+        index_all = storage.open_index(ALL_REVS)
         try:
             # NOTE: self.backend iterator gives (mountpoint, revid) tuples, which is NOT
             # the same as (name, revid), thus we do the set operations just on the revids.
@@ -542,7 +547,7 @@
             backend_latest_names_revids = set(self._find_latest_names_revids(index_all))
         finally:
             index_all.close()
-        index_latest = open_dir(index_dir, indexname=LATEST_REVS)
+        index_latest = storage.open_index(LATEST_REVS)
         try:
             # now update LATEST_REVS index:
             with index_latest.searcher() as searcher:
@@ -573,8 +578,9 @@
         Optimize whoosh index.
         """
         index_dir = self.index_dir_tmp if tmp else self.index_dir
+        storage = FileStorage(index_dir)
         for name in INDEXES:
-            ix = open_dir(index_dir, indexname=name)
+            ix = storage.open_index(name)
             try:
                 ix.optimize()
             finally:
@@ -585,7 +591,8 @@
         Yield key/value tuple lists for all documents in the indexes, fields sorted.
         """
         index_dir = self.index_dir_tmp if tmp else self.index_dir
-        ix = open_dir(index_dir, indexname=idx_name)
+        storage = FileStorage(index_dir)
+        ix = storage.open_index(idx_name)
         try:
             with ix.searcher() as searcher:
                 for doc in searcher.all_stored_fields():