less fields to index
authorMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Mon, 2 Apr 2012 12:55:21 +0000 (14:55 +0200)
committerMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Mon, 2 Apr 2012 12:55:21 +0000 (14:55 +0200)
apps/search/index.py
apps/search/views.py
wolnelektury/settings/__init__.py

index 4e71e25..e8b7a5c 100644 (file)
@@ -339,7 +339,10 @@ class Index(BaseIndex):
             self.remove_book(book, remove_snippets=False)
 
         book_doc = self.create_book_doc(book)
-        meta_fields = self.extract_metadata(book, book_info)
+        meta_fields = self.extract_metadata(book, book_info, dc_only=['source_name', 'authors', 'title'])
+        # let's not index it - it's only used for extracting publish date
+        del meta_fields['source_name']
+        
         for f in meta_fields.values():
             if isinstance(f, list) or isinstance(f, tuple):
                 for elem in f:
@@ -373,7 +376,7 @@ class Index(BaseIndex):
 
     published_date_re = re.compile("([0-9]+)[\]. ]*$")
 
-    def extract_metadata(self, book, book_info=None):
+    def extract_metadata(self, book, book_info=None, dc_only=None):
         """
         Extract metadata from book and returns a map of fields keyed by fieldname
         """
@@ -388,6 +391,8 @@ class Index(BaseIndex):
 
         # validator, name
         for field in dcparser.BookInfo.FIELDS:
+            if dc_only and field.name not in dc_only:
+                continue
             if hasattr(book_info, field.name):
                 if not getattr(book_info, field.name):
                     continue
index 09f217f..fd5883e 100644 (file)
@@ -14,6 +14,7 @@ from catalogue.views import JSONResponse
 from search import Search, JVM, SearchResult
 from lucene import StringReader
 from suggest.forms import PublishingSuggestForm
+from time import sleep
 import re
 import enchant
 
@@ -50,8 +51,21 @@ def did_you_mean(query, tokens):
 
     return query
 
+
 JVM.attachCurrentThread()
-search = Search()
+_search = None
+
+
+def get_search():
+    global _search
+
+    while _search is False:
+        sleep(1)
+
+    if _search is None:
+        _search = False
+        _search = Search()
+    return _search
 
 
 def hint(request):
@@ -60,6 +74,7 @@ def hint(request):
         return JSONResponse([])
     JVM.attachCurrentThread()
 
+    search = get_search()
     hint = search.hint()
     try:
         tags = request.GET.get('tags', '')
@@ -117,6 +132,7 @@ def main(request):
         return render_to_response('catalogue/search_too_short.html', {'prefix': query},
                                   context_instance=RequestContext(request))
 
+    search = get_search()
     # hint.tags(tag_list)
     # if book:
     #     hint.books(book)
index be82e3d..ed7bda0 100644 (file)
@@ -64,6 +64,7 @@ INSTALLED_APPS_OUR = [
     'picture',
     'social',
     'waiter',
+    'search',
     ]
 
 INSTALLED_APPS_CONTRIB = [