- results = SearchResult.aggregate(srch.search_perfect_book(toks, fuzzy=fuzzy),
- srch.search_perfect_parts(toks, fuzzy=fuzzy),
- srch.search_everywhere(toks, fuzzy=fuzzy))
- results.sort(reverse=True)
+ # Boost main author/title results with mixed search, and save some of its results for end of list.
+ # boost author, title results
+ author_title_mixed = srch.search_some(toks, ['authors', 'title', 'tags'], fuzzy=fuzzy, tokens_cache=tokens_cache)
+ author_title_rest = []
+ for b in author_title_mixed:
+ bks = filter(lambda ba: ba.book_id == b.book_id, author_results + title_results)
+ for b2 in bks:
+ b2.boost *= 1.1
+ if bks is []:
+ author_title_rest.append(b)
+
+ text_phrase = SearchResult.aggregate(srch.search_phrase(toks, 'content', fuzzy=fuzzy, tokens_cache=tokens_cache))
+ [r.process_hits() for r in text_phrase]
+
+ everywhere = SearchResult.aggregate(srch.search_everywhere(toks, fuzzy=fuzzy, tokens_cache=tokens_cache), author_title_rest)
+ [r.process_hits() for r in everywhere]
+
+ for res in [author_results, title_results, text_phrase, everywhere]:
+ res.sort(reverse=True)