Commits

marchael committed 6d1f886

Add dynamic fields support(may be don't work for last revs after rebuilding)

Comments (0)

Files changed (4)

MoinMoin/script/maint/index.py

                                 for rev_no in item.list_revisions():
                                     revision = item.get_revision(rev_no)
                                     rev_content = convert_to_indexable(revision)
-                                    metadata = backend_to_index(revision, rev_no, all_rev_field_names, rev_content, interwikiname)
+                                    metadata = backend_to_index(revision, rev_no, all_rev_schema, rev_content, interwikiname)
                                     all_rev_writer.add_document(**metadata)
                             else:
                                 revision = item.get_revision(-1)
                             continue
                         # revision is now the latest revision of this item
                         if "latest_revisions_index" in indexnames and "rev_no" in locals():
-                            metadata = backend_to_index(revision, rev_no, latest_rev_field_names, rev_content, interwikiname)
+                            metadata = backend_to_index(revision, rev_no, latest_rev_schema, rev_content, interwikiname)
                             latest_rev_writer.add_document(**metadata)
 
         def update_index(indexnames_schemas):
                     for item, rev_no in latest_documents:
                         revision = item.get_revision(rev_no)
                         rev_content = convert_to_indexable(revision)
-                        converted_rev = backend_to_index(revision, rev_no, latest_rev_field_names, rev_content, interwikiname)
+                        converted_rev = backend_to_index(revision, rev_no, latest_rev_schema, rev_content, interwikiname)
                         found = latest_rev_searcher.document(name_exact=item.name,
                                                              wikiname=interwikiname
                                                             )
                         for rev_no in rev_nos:
                             revision = item.get_revision(rev_no)
                             rev_content = convert_to_indexable(revision)
-                            converted_rev = backend_to_index(revision, rev_no, all_rev_field_names, rev_content, interwikiname)
+                            converted_rev = backend_to_index(revision, rev_no, all_rev_schema, rev_content, interwikiname)
                             all_rev_writer.add_document(**converted_rev)
 
         def clean_index(indexnames_schemas):
             for indexname, schema in indexnames_schemas:
                 if not exists_in(app.cfg.index_dir_tmp, indexname=indexname):
                     raise FatalError(u"Can't find %s in %s" % (indexname, app.cfg.index_dir_tmp))
-                for filename in latest_rev_index.storage.list():
+                for filename in all_rev_index.storage.list():
                     src_file = os.path.join(app.cfg.index_dir_tmp, filename)
                     dst_file = os.path.join(app.cfg.index_dir, filename)
                     if indexname in filename and os.path.exists(src_file):
         latest_rev_index = index_object.latest_revisions_index
         all_rev_index = index_object.all_revisions_index
 
-        latest_rev_field_names = latest_rev_index.schema.names()
-        all_rev_field_names = all_rev_index.schema.names()
+        latest_rev_schema = latest_rev_index.schema
+        all_rev_schema = all_rev_index.schema
 
         latest_rev_searcher = latest_rev_index.searcher()
         all_rev_searcher = all_rev_index.searcher()

MoinMoin/search/indexing.py

         self.all_revisions_schema = Schema(uuid=ID(stored=True),
                                            **common_fields)
 
+        # Add dynamic fields there
+        self.latest_revisions_schema.add("*_id", ID, glob=True)
+        self.latest_revisions_schema.add("*_text", TEXT, glob=True)
+
+        self.all_revisions_schema.add("*_id", ID, glob=True)
+        self.all_revisions_schema.add("*_text", TEXT, glob=True)
+
         for index_name, index_schema in self._indexes.items():
             self.open_index(index_name, index_schema, create=True, index_dir=self._index_dir)
 

MoinMoin/search/revision_converter.py

 
 from MoinMoin.config import MTIME, NAME
 
-def backend_to_index(backend_rev, rev_no, schema_fields, content, wikiname=u''):
+def backend_to_index(backend_rev, rev_no, schema, content, wikiname=u''):
     """
     Convert fields from backend format to whoosh schema
 
 
     doc = dict([(str(key), value)
                 for key, value in backend_rev.items()
-                if key in schema_fields])
+                if key in schema])
     doc[MTIME] = datetime.datetime.fromtimestamp(backend_rev[MTIME])
     doc["name_exact"] = backend_rev[NAME]
     doc["rev_no"] = rev_no

MoinMoin/storage/backends/indexing.py

         rev_content = convert_to_indexable(rev)
         logging.debug("Indexable content: %r" % (rev_content[:250], ))
         if not all_found_document:
-            field_names = self.index_object.all_revisions_index.schema.names()
+            schema = self.index_object.all_revisions_index.schema
             with AsyncWriter(self.index_object.all_revisions_index) as async_writer:
-                converted_rev = backend_to_index(rev, revno, field_names, rev_content, self.wikiname)
+                converted_rev = backend_to_index(rev, revno, schema, rev_content, self.wikiname)
                 logging.debug("All revisions: adding %s %s", converted_rev[NAME], converted_rev["rev_no"])
                 async_writer.add_document(**converted_rev)
         if not latest_found_document or int(revno) > latest_found_document["rev_no"]:
-            field_names = self.index_object.latest_revisions_index.schema.names()
+            schema = self.index_object.latest_revisions_index.schema
             with AsyncWriter(self.index_object.latest_revisions_index) as async_writer:
-                converted_rev = backend_to_index(rev, revno, field_names, rev_content, self.wikiname)
+                converted_rev = backend_to_index(rev, revno, schema, rev_content, self.wikiname)
                 logging.debug("Latest revisions: updating %s %s", converted_rev[NAME], converted_rev["rev_no"])
                 async_writer.update_document(**converted_rev)