Skip to content

Instantly share code, notes, and snippets.

@voidfiles
Last active March 9, 2019 14:58
Show Gist options
  • Select an option

  • Save voidfiles/7549435 to your computer and use it in GitHub Desktop.

Select an option

Save voidfiles/7549435 to your computer and use it in GitHub Desktop.
Can whoosh do something like percolate
# 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