[GMG-Devel] [PATCH 28/83] Fix bugs

Alon Levy alon at pobox.com
Tue Feb 25 14:58:11 EST 2014


From: Praveen Kumar <praveen97uma at gmail.com>

---
 mediagoblin/plugins/search/base.py  | 13 +++++++++----
 mediagoblin/plugins/search/views.py |  2 +-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/mediagoblin/plugins/search/base.py b/mediagoblin/plugins/search/base.py
index c3a3cae..f4d2b54 100644
--- a/mediagoblin/plugins/search/base.py
+++ b/mediagoblin/plugins/search/base.py
@@ -46,6 +46,11 @@ class SearchIndex(object):
     
         self.create_index()
 
+    def _open_search_index(self):
+         self.search_index = whoosh.index.open_dir(self.search_index_dir,
+                indexname=self.search_index_name)
+        
+
     def _index_exists(self):
         """
         Returns whether a valid index exists in self.search_index_dir.
@@ -69,6 +74,7 @@ class SearchIndex(object):
 
 
     def _get_writer(self):
+        self._open_search_index()
         writer = None
         if self.use_multiprocessing:
             writer = MultiSegmentWriter(self.search_index)
@@ -88,13 +94,11 @@ class SearchIndex(object):
             return
 
         if not os.path.exists(self.search_index_dir):
-            os.mkdir(self.search_index_dir)
+            os.mkdirs(self.search_index_dir)
 
         self.search_index = whoosh.index.create_in(self.search_index_dir,
                 indexname=self.search_index_name, schema=self.schema)
-        self.search_index = whoosh.index.open_dir(self.search_index_dir,
-                indexname=self.search_index_name)
-        
+       
 
     def add_document(self, **document):
         """
@@ -146,6 +150,7 @@ class SearchIndex(object):
         self.add_document(**document)
 
     def search(self, query):
+        self._open_search_index()
         query = unicode(query)
         with self.search_index.searcher() as searcher:
             query = MultifieldParser(self.field_names,
diff --git a/mediagoblin/plugins/search/views.py b/mediagoblin/plugins/search/views.py
index 028c91d..6030206 100644
--- a/mediagoblin/plugins/search/views.py
+++ b/mediagoblin/plugins/search/views.py
@@ -47,4 +47,4 @@ def search(request):
         return render_to_response(request, 'mediagoblin/search/search.html',
                 context)
 
-    render_to_response(request, 'mediagoblin/search/search.html', context)
+    return render_to_response(request, 'mediagoblin/search/search.html', context)
-- 
1.8.5.3



More information about the devel mailing list