- # queryreader = StringReader(query)
- # tokens = self.get_tokens(queryreader)
-
- # top_level = BooleanQuery()
- # Should = BooleanClause.Occur.SHOULD
-
- # phrase_level = BooleanQuery()
- # phrase_level.setBoost(1.3)
-
- # p_content = self.make_phrase(tokens, joined=True)
- # p_title = self.make_phrase(tokens, 'title')
- # p_author = self.make_phrase(tokens, 'author')
-
- # phrase_level.add(BooleanClause(p_content, Should))
- # phrase_level.add(BooleanClause(p_title, Should))
- # phrase_level.add(BooleanClause(p_author, Should))
-
- # kw_level = BooleanQuery()
-
- # kw_level.add(self.make_term_query(tokens, 'author'), Should)
- # j_themes = self.make_term_query(tokens, 'themes', joined=True)
- # kw_level.add(j_themes, Should)
- # kw_level.add(self.make_term_query(tokens, 'tags'), Should)
- # j_con = self.make_term_query(tokens, joined=True)
- # kw_level.add(j_con, Should)
-
- # top_level.add(BooleanClause(phrase_level, Should))
- # top_level.add(BooleanClause(kw_level, Should))
-
- return None
-
- def book_search(self, query, filter=None, max_results=50, collector=None):
- tops = self.searcher.search(query, filter, max_results)
- #tops = self.searcher.search(p_content, max_results)
-
- bks = []
- for found in tops.scoreDocs:
- doc = self.searcher.doc(found.doc)
- b = catalogue.models.Book.objects.get(id=doc.get("book_id"))
- bks.append(b)
- print "%s (%d) -> %f" % (b, b.id, found.score)
- return bks
-
- def get_snippets(self, scoreDoc, query, field='content'):
- htmlFormatter = SimpleHTMLFormatter()
- highlighter = Highlighter(htmlFormatter, QueryScorer(query))
-
- stored = self.searcher.doc(scoreDoc.doc)
-
- # locate content.
- snippets = Snippets(stored.get('book_id')).open()