- results = SearchResult.aggregate(srch.search_perfect_book(toks, fuzzy=fuzzy, hint=hint),
- srch.search_book(toks, fuzzy=fuzzy, hint=hint),
- srch.search_perfect_parts(toks, fuzzy=fuzzy, hint=hint),
- srch.search_everywhere(toks, fuzzy=fuzzy, hint=hint))
-
- for r in results:
- r.process_hits()
-
- results.sort(reverse=True)
+ 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))
+ [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]