[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
- [GMG-Devel] [PATCH 01/83] Register search plugin with mediagoblin.ini, (continued)
- [GMG-Devel] [PATCH 01/83] Register search plugin with mediagoblin.ini, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 02/83] Correct indices storage dictionary in config_spec.ini, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 03/83] Refactor exceptions raised by the search plugin, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 04/83] Fix typos in search.models, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 05/83] Rename models.py to indices.py as these will not be stored in db., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 06/83] Remove global constants from the top of indices.py, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 07/83] Fix imports and other bugs in indices.py, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 08/83] Add schemas.py which will store all index schemas., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 09/83] Store also the field names in the SearchIndex object which is also necessary while searching., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 10/83] Correct the class index schema class., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 11/83] Add indexer for MediaEntry objects.,
Alon Levy <=
- [GMG-Devel] [PATCH 12/83] Add IndexRegistry class to maintain the search indices., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 13/83] Clean up plugins.search.indices, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 14/83] Rename base.py to registry.py and indices.py to base.py., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 15/83] Add index identifier to SearchIndex., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 16/83] Correct the index identifier., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 17/83] Collect all indices in indices.py, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 18/83] Add method to create a document from a model instance, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 19/83] Add event listeners for tracking ORM events for indices., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 20/83] Register indices and orm events for search., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 21/83] Fix bugs and add search method in SearchIndex, Alon Levy, 2014/02/25