fc14b067d432a3d69cb026e4dc12805dc25de95e
[wolnelektury.git] / apps / search / views.py
1
2
3 from django.shortcuts import render_to_response, get_object_or_404
4 from django.template import RequestContext
5 from django.contrib.auth.decorators import login_required
6 from django.views.decorators import cache
7
8 from catalogue.utils import get_random_hash
9 from catalogue.models import Book, Tag
10 from catalogue import forms
11 from search import MultiSearch, JVM, SearchResult
12
13
14 def main(request):
15     results = {}
16     JVM.attachCurrentThread()  # where to put this?
17     srch = MultiSearch()
18
19     results = None
20     if 'q' in request.GET:
21         toks = srch.get_tokens(request.GET['q'])
22         results = SearchResult.aggregate(srch.search_perfect_book(toks),
23                                          srch.search_perfect_parts(toks),
24                                          srch.search_everywhere(toks))
25         results.sort(reverse=True)
26
27         for r in results:
28             print r.parts
29
30     return render_to_response('newsearch/search.html', {"results": results},
31                               context_instance=RequestContext(request))