+ def search_phrase(self, searched, field, book=True, max_results=20, fuzzy=False,
+ filters=None, tokens_cache=None, boost=None, snippets=False, slop=2):
+ if filters is None: filters = []
+ if tokens_cache is None: tokens_cache = {}
+
+ tokens = self.get_tokens(searched, field, cached=tokens_cache)
+
+ query = self.make_phrase(tokens, field=field, fuzzy=fuzzy, slop=slop)
+ if book:
+ filters.append(self.term_filter(Term('is_book', 'true')))
+ top = self.searcher.search(query, self.chain_filters(filters), max_results)
+
+ return [SearchResult(self, found, snippets=(snippets and self.get_snippets(found, query) or None), searched=searched) for found in top.scoreDocs]
+
+ def search_some(self, searched, fields, book=True, max_results=20, fuzzy=False,
+ filters=None, tokens_cache=None, boost=None, snippets=True):
+ if filters is None: filters = []
+ if tokens_cache is None: tokens_cache = {}
+
+ if book:
+ filters.append(self.term_filter(Term('is_book', 'true')))
+
+ query = BooleanQuery()
+
+ for fld in fields:
+ tokens = self.get_tokens(searched, fld, cached=tokens_cache)
+
+ query.add(BooleanClause(self.make_term_query(tokens, field=fld,
+ fuzzy=fuzzy), BooleanClause.Occur.SHOULD))
+
+ top = self.searcher.search(query, self.chain_filters(filters), max_results)
+
+ return [SearchResult(self, found, searched=searched, tokens_cache=tokens_cache,
+ snippets=(snippets and self.get_snippets(found, query) or None)) for found in top.scoreDocs]