content=fix_format(u' '.join(filter(lambda s: s is not None, content))))
self.index.addDocument(doc)
content=fix_format(u' '.join(filter(lambda s: s is not None, content))))
self.index.addDocument(doc)
hits.sort(lambda a, b: cmp(a['score'], b['score']), reverse=True)
hits.sort(lambda a, b: cmp(a['score'], b['score']), reverse=True)
return q
def search_phrase(self, searched, field, book=True, max_results=20, fuzzy=False,
return q
def search_phrase(self, searched, field, book=True, max_results=20, fuzzy=False,
- filters=None, tokens_cache=None, boost=None):
+ filters=None, tokens_cache=None, boost=None, snippets=False):
filters.append(self.term_filter(Term('is_book', 'true')))
top = self.searcher.search(query, self.chain_filters(filters), max_results)
filters.append(self.term_filter(Term('is_book', 'true')))
top = self.searcher.search(query, self.chain_filters(filters), max_results)
- return [SearchResult(self.searcher, found) for found in top.scoreDocs]
+ return [SearchResult(self.searcher, found, snippets=(snippets and self.get_snippets(found, query) or None)) 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):
def search_some(self, searched, fields, book=True, max_results=20, fuzzy=False,
filters=None, tokens_cache=None, boost=None):
- return [SearchResult(self.searcher, found, searched=searched, tokens_cache=tokens_cache) for found in top.scoreDocs]
+ return [SearchResult(self.searcher, found, searched=searched, tokens_cache=tokens_cache, snippets=self.get_snippets(found, query)) for found in top.scoreDocs]
def search_perfect_book(self, searched, max_results=20, fuzzy=False, hint=None):
"""
def search_perfect_book(self, searched, max_results=20, fuzzy=False, hint=None):
"""