-
- results = SearchResult.aggregate(srch.search_perfect_book(toks, fuzzy=fuzzy),
- srch.search_perfect_parts(toks, fuzzy=fuzzy),
- srch.search_everywhere(toks, fuzzy=fuzzy))
+ 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)
+
+ # 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, snippets=True, book=False))
+
+ everywhere = SearchResult.aggregate(srch.search_everywhere(toks, fuzzy=fuzzy, tokens_cache=tokens_cache), author_title_rest)
+
+ for res in [author_results, title_results, text_phrase, everywhere]:
+ res.sort(reverse=True)
+
+ suggestion = did_you_mean(query, srch.get_tokens(toks, field="SIMPLE"))
+
+ results = author_results + title_results + text_phrase + everywhere