X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/dbb6eb3883a5f5e371f4bf7c89e74326feca0fd1..eb8bbc1d780d405e2cc105d057c9e5186510ba9f:/apps/search/views.py?ds=sidebyside diff --git a/apps/search/views.py b/apps/search/views.py index dcd80b29f..56eef0976 100644 --- a/apps/search/views.py +++ b/apps/search/views.py @@ -10,11 +10,12 @@ from django.utils.translation import ugettext as _ from catalogue.utils import split_tags from catalogue.models import Book, Tag, Fragment -from catalogue.fields import dumps +from pdcounter.models import Author as PDCounterAuthor, BookStub as PDCounterBook 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 @@ -51,8 +52,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): @@ -61,6 +75,7 @@ def hint(request): return JSONResponse([]) JVM.attachCurrentThread() + search = get_search() hint = search.hint() try: tags = request.GET.get('tags', '') @@ -76,6 +91,18 @@ def hint(request): tags = search.hint_tags(prefix, pdcounter=True) books = search.hint_books(prefix) + + def is_dupe(tag): + if isinstance(tag, PDCounterAuthor): + if filter(lambda t: t.slug == tag.slug and t != tag, tags): + return True + elif isinstance(tag, PDCounterBook): + if filter(lambda b: b.slug == tag.slug, tags): + return True + return False + + tags = filter(lambda t: not is_dupe(t), tags) + def category_name(c): if c.startswith('pd_'): c = c[len('pd_'):] @@ -118,6 +145,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)