mediagoblin-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GMG-Devel] [PATCH 11/83] Add indexer for MediaEntry objects.


From: Alon Levy
Subject: [GMG-Devel] [PATCH 11/83] Add indexer for MediaEntry objects.
Date: Tue, 25 Feb 2014 21:57:54 +0200

From: Praveen Kumar <address@hidden>

---
 mediagoblin/plugins/search/indexer.py | 27 +++++++++++++++++++++++++--
 mediagoblin/plugins/search/indices.py | 18 ++++++++++++++++--
 mediagoblin/plugins/search/schemas.py |  2 +-
 3 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/mediagoblin/plugins/search/indexer.py 
b/mediagoblin/plugins/search/indexer.py
index d01d734..86f74dd 100644
--- a/mediagoblin/plugins/search/indexer.py
+++ b/mediagoblin/plugins/search/indexer.py
@@ -1,3 +1,26 @@
-from whoosh.index import create_in
-from whoosh.index import open_dir
+from mediagoblin.plugins.search.indices import MediaEntrySearchIndex
+from mediagoblin.plugins.search import schemas
+
+
+class IndexerAndSearcher(object):
+    """
+    Encapsulates methods that runs the indexing and searching
+    tasks.
+    """
+
+    def __init__(self, search_index=None, searcher=None):
+        self.search_index = search_index
+
+    def search(self, query):
+        pass
+
+    def add_document(self, document):
+        pass
+
+    def add_documents(self, documents):
+        pass
+
+
+
+media_entry_indexer = IndexerAndSearcher(MediaEntrySearchIndex)
 
diff --git a/mediagoblin/plugins/search/indices.py 
b/mediagoblin/plugins/search/indices.py
index 086271b..e3ad16c 100644
--- a/mediagoblin/plugins/search/indices.py
+++ b/mediagoblin/plugins/search/indices.py
@@ -2,6 +2,7 @@ import os
 
 from mediagoblin.tools import pluginapi
 from mediagoblin.plugins.search.exceptions import IndexDoesNotExistsError
+from mediagoblin.plugins.search.schemas import MediaEntryIndexSchema
 
 import whoosh
 
@@ -19,9 +20,11 @@ class SearchIndex(object):
     index.
     """
     
-    def __init__(self, search_index_dir=None, use_multiprocessing=None):
-        self.schema = None
+    def __init__(self, schema=None, search_index_dir=None, 
use_multiprocessing=None):
+        self.schema = schema
         self.field_names = None
+        self.create_index(self.schema)
+
         self.search_index = None
         self.search_index_name = self.__class__.__name__.lower()
         
@@ -71,6 +74,9 @@ class SearchIndex(object):
 
         `schema` should be an object of whoosh.fields.Schema.
         """
+        if not schema:
+            return
+
         if not os.path.exists(self.search_index_dir):
             os.mkdir(self.search_index_dir)
 
@@ -113,3 +119,11 @@ class SearchIndex(object):
         writer.update_document(**document)
         writer.commit()
 
+class MediaEntrySearchIndex(SearchIndex):
+    def __init__(self, schema=MediaEntryIndexSchema, 
+            search_index_dir=None, use_multiprocessing=None):
+        super(MediaEntrySearchIndex, self).__init__(
+            schema=schema
+            search_index_dir=search_index_dir,
+            use_multiprocessing=use_multiprocessing
+        )
diff --git a/mediagoblin/plugins/search/schemas.py 
b/mediagoblin/plugins/search/schemas.py
index 6b976c3..c4cbb5e 100644
--- a/mediagoblin/plugins/search/schemas.py
+++ b/mediagoblin/plugins/search/schemas.py
@@ -4,7 +4,7 @@ from whoosh.fields import TEXT
 from whoosh.fields import DATETIME
 
 
-class MediaEntrySearchSchema(SchemaClass):
+class MediaEntryIndexSchema(SchemaClass):
     """
     Represents the schema of the search index corresponding 
     to db.models.MediaEntry objects.
-- 
1.8.5.3



reply via email to

[Prev in Thread] Current Thread [Next in Thread]