- filters = []
-
- if author:
- log.info( "narrow to author %s" % author)
- hint.tags(srch.search_tags(srch.make_phrase(srch.get_tokens(author, field='authors'), field='authors'),
- filt=srch.term_filter(Term('tag_category', 'author'))))
-
- if translator:
- log.info( "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:
- log.info( "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)
- log.info("tokens for query: %s" % toks)
-
- 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)
- books = []
- for r in results:
- try:
- books.append(r.book)
- except Book.DoesNotExist:
- pass
- log.info("books: %s" % books)
- return books