- res = query.execute()
- return [SearchResult(found, how_found='search_some', query_terms=query_terms) for found in res]
-
-
- def search_everywhere(self, searched, query_terms=None):
- """
- Tries to use search terms to match different fields of book (or its parts).
- E.g. one word can be an author survey, another be a part of the title, and the rest
- are some words from third chapter.
- """
- books = []
- # content only query : themes x content
- q = self.make_term_query(searched, 'text')
- q_themes = self.make_term_query(searched, 'themes_pl')
-
- query = self.index.query(q).query(q_themes).field_limit(score=True, all_fields=True)
- res = query.execute()
-
- for found in res:
- books.append(SearchResult(found, how_found='search_everywhere_themesXcontent', query_terms=query_terms))
-
- # query themes/content x author/title/tags
- in_content = self.index.Q()
- in_meta = self.index.Q()
-
- for fld in ['themes_pl', 'text']:
- in_content |= self.make_term_query(searched, field=fld)
-
- for fld in ['tags', 'authors', 'title']:
- in_meta |= self.make_term_query(searched, field=fld)
-
- q = in_content & in_meta
- res = self.index.query(q).field_limit(score=True, all_fields=True).execute()
-
- for found in res:
- books.append(SearchResult(found, how_found='search_everywhere', query_terms=query_terms))
-
- return books