changeset 437:dccbd79260ce

Added several dynamic fields Fixes #17.
author Michael Mayorov <marchael@kb.csu.ru>
date Mon, 15 Aug 2011 00:12:52 +0000
parents 6d1f88659ab1
children 33249607fd48
files MoinMoin/search/indexing.py
diffstat 1 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/search/indexing.py	Sun Aug 14 18:10:28 2011 +0000
+++ b/MoinMoin/search/indexing.py	Mon Aug 15 00:12:52 2011 +0000
@@ -9,7 +9,7 @@
 
 from flask import current_app as app
 
-from whoosh.fields import Schema, TEXT, ID, IDLIST, NUMERIC, DATETIME
+from whoosh.fields import Schema, TEXT, ID, IDLIST, NUMERIC, DATETIME, KEYWORD, BOOLEAN
 from whoosh.index import open_dir, create_in, EmptyIndexError
 
 from MoinMoin.search.analyzers import *
@@ -63,12 +63,19 @@
         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)
+        # Define dynamic fields
+        dynamic_fields = [("*_id", ID),
+                          ("*_text", TEXT),
+                          ("*_keyword", KEYWORD),
+                          ("*_numeric", NUMERIC),
+                          ("*_datetime", DATETIME),
+                          ("*_boolean", BOOLEAN)
+                         ]
 
-        self.all_revisions_schema.add("*_id", ID, glob=True)
-        self.all_revisions_schema.add("*_text", TEXT, glob=True)
+        # Adding dynamic fields to schemas
+        for glob, field_type in dynamic_fields:
+            self.latest_revisions_schema.add(glob, field_type, glob=True)
+            self.all_revisions_schema.add(glob, field_type, 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)