Last active
March 9, 2019 14:58
-
-
Save voidfiles/7549435 to your computer and use it in GitHub Desktop.
Can whoosh do something like percolate
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
| # This is a notepad to see if whoosh could do something like percolate for for elastic search | |
| from whoosh.fields import Schema, TEXT | |
| from whoosh.filedb.filestore import RamStorage | |
| from whoosh.index import FileIndex | |
| from whoosh.qparser import QueryParser | |
| schema = Schema(title=TEXT(stored=True), content=TEXT) | |
| def create_in(schema, indexname): | |
| storage = RamStorage() | |
| return FileIndex.create(storage, schema, indexname) | |
| ix = create_in(schema, "index") | |
| writer = ix.writer() | |
| writer.add_document(title=u"First document", content=u"This is the first document we've added!") | |
| writer.commit() | |
| with ix.searcher() as searcher: | |
| query = QueryParser("content", ix.schema).parse("first") | |
| results = searcher.search(query) | |
| if results: | |
| for hit in results: | |
| print '%s %s %s' % (hit.rank, hit.score, hit) | |
| else: | |
| print 'no results' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment