- theme_terms = search.index.analyze(text=query, field="themes_pl") \
- + search.index.analyze(text=query, field="themes")
-
- # change hints
- tags = search.hint_tags(query, pdcounter=True, prefix=False)
- tags = split_tags(tags)
-
- author_results = search.search_phrase(query, 'authors', book=True)
- translator_results = search.search_phrase(query, 'translators', book=True)
-
- title_results = search.search_phrase(query, 'title', book=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 = search.search_some(query, ['authors', 'translators', 'title', 'tags'], query_terms=theme_terms)
- author_title_rest = []
-
- for b in author_title_mixed:
- also_in_mixed = filter(lambda ba: ba.book_id == b.book_id, author_results + translator_results + title_results)
- for b2 in also_in_mixed:
- b2.boost *= 1.1
- if also_in_mixed is []:
- author_title_rest.append(b)
-
- # Do a phrase search but a term search as well - this can give us better snippets then search_everywhere,
- # Because the query is using only one field.
- text_phrase = SearchResult.aggregate(
- search.search_phrase(query, 'text', snippets=True, book=False),
- search.search_some(query, ['text'], snippets=True, book=False, query_terms=theme_terms))
-
- everywhere = search.search_everywhere(query, query_terms=theme_terms)
-
- def already_found(results):
- def f(e):
- for r in results:
- if e.book_id == r.book_id:
- e.boost = 0.9
- results.append(e)
- return True
+ def ensure_exists(r):
+ try:
+ if not r.book:
+ return False
+ except Book.DoesNotExist:
+ return False
+
+ if lang and r.book.language != lang:
+ return False
+ if only_audio and not r.book.has_mp3_file():
+ return False
+ if only_synchro and not r.book.has_daisy_file():
+ return False
+ if epoch and not r.book.tags.filter(category='epoch', slug=epoch).exists():
+ return False
+ if kind and not r.book.tags.filter(category='kind', slug=kind).exists():
+ return False
+ if genre and not r.book.tags.filter(category='genre', slug=genre).exists():