[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GMG-Devel] [PATCH 31/83] Refactor SearchIndex and add method to update
From: |
Alon Levy |
Subject: |
[GMG-Devel] [PATCH 31/83] Refactor SearchIndex and add method to update an index. |
Date: |
Tue, 25 Feb 2014 21:58:14 +0200 |
From: Praveen Kumar <address@hidden>
---
mediagoblin/plugins/search/base.py | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/mediagoblin/plugins/search/base.py
b/mediagoblin/plugins/search/base.py
index 9172d26..2b6e2b6 100644
--- a/mediagoblin/plugins/search/base.py
+++ b/mediagoblin/plugins/search/base.py
@@ -131,7 +131,7 @@ class SearchIndex(object):
writer.commit()
- def update_document(self, document={}):
+ def update_document(self, **document):
"""
Updates an existing document in the index.
@@ -142,8 +142,8 @@ class SearchIndex(object):
writer = self._get_writer()
writer.update_document(**document)
writer.commit()
-
- def add_document_from_model_obj(self, model_obj):
+
+ def _prepare_document_from_model_obj(self, model_obj):
document = {}
for name in self.field_names:
try:
@@ -160,10 +160,19 @@ class SearchIndex(object):
except AttributeError:
_log.info("Attribute %s not found in %s"%(
name, model_obj.__class__.__name__))
- _log.info("Adding document %s"%document['title'])
-
+ return document
+
+
+ def add_document_from_model_obj(self, model_obj):
+ document = self._prepare_document_from_model_obj(model_obj)
self.add_document(**document)
+ _log.info("Added document %s"%document['title'])
+ def update_document_from_model_obj(self, model_obj):
+ document = self._prepare_document_from_model_obj(model_obj)
+ self.update_document(**document)
+ _log.info("Updated document %s"%(document['title']))
+
def _process_query(self, query):
query = unicode(query)
query = MultifieldParser(self.field_names,
--
1.8.5.3
- [GMG-Devel] [PATCH 21/83] Fix bugs and add search method in SearchIndex, (continued)
- [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
- [GMG-Devel] [PATCH 24/83] Correct indentations in search.__init__, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 25/83] Add search forms., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 26/83] Add view to handle search queries., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 27/83] Add html template for search page., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 28/83] Fix bugs, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 29/83] Add methods to interpret results by the SearchIndex object, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 30/83] fix parameters in search views, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 31/83] Refactor SearchIndex and add method to update an index.,
Alon Levy <=
- [GMG-Devel] [PATCH 32/83] Add event listener for model update, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 33/83] Add listener for model delete event., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 34/83] Fix bugs in SearchIndex, Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 35/83] Add indices for MediaEntry and MediaTag., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 36/83] Add schema for MediaTag., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 37/83] Register schemas for MediaEntry and MediaTag., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 38/83] Add gmg command to delete all indices., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 39/83] Clean up and add docstring to search methods., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 40/83] Add try-except block to event listeners., Alon Levy, 2014/02/25
- [GMG-Devel] [PATCH 42/83] Store attributes from a model only it its available., Alon Levy, 2014/02/25