Created
August 17, 2012 02:47
-
-
Save mozillalives/3375468 to your computer and use it in GitHub Desktop.
Search and Serve
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from whoosh import index, qparser | |
def search(blah, page, length): | |
ix = index.open_dir(INDEX_DIR) | |
with ix.searcher() as s: | |
q = qparser.QueryParser("content", ix.schema).parse(blah) | |
r = s.search_page(q, page, pagelen=length) | |
t = [] | |
for res in r: | |
t.append({'field1': res['field1'], | |
'field2': res['field2'], | |
'highlights': res.highlights("content")}) | |
return t |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import search | |
class SearchHandler(RequestHandler): | |
@tornado.web.authenticated | |
def get(self): | |
query = self.get_argument("q") | |
page = int(self.get_argument("p", '1')) | |
results = search.search(query, page, 10) | |
self.render("templates/searchresults.html", results=results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment