X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/94924a2ca60f4f045c739cdb19d859cdcf8959af..ba08b7b1c9b48ce1d0ebde7d259dc777ff98162a:/apps/search/views.py diff --git a/apps/search/views.py b/apps/search/views.py index 623b311fb..527ca8224 100644 --- a/apps/search/views.py +++ b/apps/search/views.py @@ -37,7 +37,9 @@ def did_you_mean(query, tokens): if not dictionary.check(t): try: - change[t] = dictionary.suggest(t)[0] + change_to = dictionary.suggest(t)[0].lower() + if change_to != t.lower(): + change[t] = change_to except IndexError: pass @@ -72,11 +74,14 @@ def hint(request): tags = s.hint_tags(prefix, pdcounter=True) books = s.hint_books(prefix) - # TODO DODAC TU HINTY + def category_name(c): + if c.startswith('pd_'): + c=c[len('pd_'):] + return _(c) return JSONResponse( [{'label': t.name, - 'category': _(t.category), + 'category': category_name(t.category), 'id': t.id, 'url': t.get_absolute_url()} for t in tags] + \ @@ -94,7 +99,7 @@ def main(request): results = None query = None - fuzzy = False + fuzzy = False #0.8 if 'q' in request.GET: # tags = request.GET.get('tags', '') @@ -117,14 +122,11 @@ def main(request): # hint.tags(tag_list) # if book: # hint.books(book) - tags = srch.hint_tags(query, pdcounter=True, prefix=False) + tags = srch.hint_tags(query, pdcounter=True, prefix=False, fuzzy=fuzzy) tags = split_tags(tags) toks = StringReader(query) tokens_cache = {} - fuzzy = 'fuzzy' in request.GET - if fuzzy: - fuzzy = 0.7 author_results = srch.search_phrase(toks, 'authors', fuzzy=fuzzy, tokens_cache=tokens_cache) title_results = srch.search_phrase(toks, 'title', fuzzy=fuzzy, tokens_cache=tokens_cache) @@ -182,9 +184,9 @@ def main(request): if len(results) == 1: fragment_hits = filter(lambda h: 'fragment' in h, results[0].hits) if len(fragment_hits) == 1: - anchor = fragment_hits[0]['fragment'] - frag = Fragment.objects.get(anchor=anchor) - return HttpResponseRedirect(frag.get_absolute_url()) + #anchor = fragment_hits[0]['fragment'] + #frag = Fragment.objects.get(anchor=anchor) + return HttpResponseRedirect(fragment_hits[0]['fragment'].get_absolute_url()) return HttpResponseRedirect(results[0].book.get_absolute_url()) elif len(results) == 0: form = PublishingSuggestForm(initial={"books": query + ", "})