- filters = []
-
- if author:
- print "narrow to author %s" % author
- hint.tags(srch.search_tags(author, filt=srch.term_filter(Term('tag_category', 'author'))))
-
- if translator:
- print "filter by translator %s" % translator
- filters.append(QueryWrapperFilter(
- srch.make_phrase(srch.get_tokens(translator, field='translators'),
- field='translators')))
-
- if categories:
- filters.append(QueryWrapperFilter(
- srch.make_phrase(srch.get_tokens(categories, field="tag_name_pl"),
- field='tag_name_pl')))
-
- flt = srch.chain_filters(filters)
- if title:
- print "hint by book title %s" % title
- q = srch.make_phrase(srch.get_tokens(title, field='title'), field='title')
- hint.books(*srch.search_books(q, filt=flt))
-
- toks = srch.get_tokens(query)
- print "tokens: %s" % toks
- # import pdb; pdb.set_trace()
- results = SearchResult.aggregate(srch.search_perfect_book(toks, fuzzy=fuzzy, hint=hint),
- srch.search_perfect_parts(toks, fuzzy=fuzzy, hint=hint),
- srch.search_everywhere(toks, fuzzy=fuzzy, hint=hint))
- results.sort(reverse=True)
- return [r.book for r in results]