store contents in index for highlighting fragments
[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
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 = srch.search_perfect(toks) + srch.search_everywhere(toks)
23         results.sort(lambda a, b: cmp(a[0], b[0]) < 0)
24         print("searched, results are: %s\n" % results)
25
26     return render_to_response('newsearch/search.html', {"results": results},
27                               context_instance=RequestContext(request))