[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GMG-Devel] [PATCH 13/83] Clean up plugins.search.indices
From: |
Alon Levy |
Subject: |
[GMG-Devel] [PATCH 13/83] Clean up plugins.search.indices |
Date: |
Tue, 25 Feb 2014 21:57:56 +0200 |
From: Praveen Kumar <address@hidden>
---
mediagoblin/plugins/search/indices.py | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/mediagoblin/plugins/search/indices.py
b/mediagoblin/plugins/search/indices.py
index e3ad16c..648cebf 100644
--- a/mediagoblin/plugins/search/indices.py
+++ b/mediagoblin/plugins/search/indices.py
@@ -1,6 +1,8 @@
+import logging
import os
from mediagoblin.tools import pluginapi
+from mediagoblin.plugins.search.base import IndexRegistry
from mediagoblin.plugins.search.exceptions import IndexDoesNotExistsError
from mediagoblin.plugins.search.schemas import MediaEntryIndexSchema
@@ -9,6 +11,7 @@ import whoosh
from whoosh.filedb.multiproc import MultiSegmentWriter
config = pluginapi.get_config('mediagoblin.plugins.search')
+_log = logging.getLogger(__name__)
class SearchIndex(object):
@@ -20,10 +23,9 @@ class SearchIndex(object):
index.
"""
- def __init__(self, schema=None, search_index_dir=None,
use_multiprocessing=None):
+ def __init__(self, model, schema, search_index_dir=None,
use_multiprocessing=None):
self.schema = schema
- self.field_names = None
- self.create_index(self.schema)
+ self.field_names = self.schema.field_names
self.search_index = None
self.search_index_name = self.__class__.__name__.lower()
@@ -35,6 +37,8 @@ class SearchIndex(object):
self.use_multiprocessing = use_multiprocessing
if not self.use_multiprocessing:
self.use_multiprocessing = config['use_multiprocessing']
+
+ self.create_index()
def _index_exists(self):
"""
@@ -68,7 +72,7 @@ class SearchIndex(object):
return writer
- def create_index(self, schema):
+ def create_index(self):
"""
Creates an index from the supplied `schema`.
@@ -81,9 +85,8 @@ class SearchIndex(object):
os.mkdir(self.search_index_dir)
self.search_index = whoosh.index.create_in(self.search_index_dir,
- indexname=self.search_index_name, schema=schema)
+ indexname=self.search_index_name, schema=self.schema)
- self.field_names = schema.names()
def add_document(self, **document):
"""
@@ -119,11 +122,3 @@ 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
- )
--
1.8.5.3
- [GMG-Devel] [PATCH 03/83] Refactor exceptions raised by the search plugin, (continued)
- [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, 2014/02/25
- [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 <=
- [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
- [GMG-Devel] [PATCH 23/83] Add ORMEventsListener class to implement the ORM Events, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 22/83] Add ListenerRegistry class to collect all the listeners., Alon Levy, 2014/02/25