Fix TypeErrors in readme example

master
Dima Gerasimov 2019-10-06 12:47:50 +01:00
parent 75f0670dd6
commit 7ce637d5cb
1 changed files with 7 additions and 8 deletions

View File

@ -38,12 +38,10 @@ index = tantivy.Index(schema)
# Adding one document. # Adding one document.
writer = index.writer() writer = index.writer()
writer.add_document({ writer.add_document(tantivy.Document(
"title": "The Old Man and the Sea", title=["The Old Man and the Sea"],
"body": """He was an old man who fished alone in a skiff in body=["""He was an old man who fished alone in a skiff in the Gulf Stream and he had gone eighty-four days now without taking a fish."""],
the Gulf Stream and he had gone eighty-four days ))
now without taking a fish."""
})
# ... and committing # ... and committing
writer.commit() writer.commit()
@ -51,10 +49,11 @@ writer.commit()
# Reload the index to ensure it points to the last commit. # Reload the index to ensure it points to the last commit.
index.reload(); index.reload();
searcher = index.searcher() searcher = index.searcher()
query = index.parse_query("sea whale", ["title", "body"]) query = index.parse_query("fish days", ["title", "body"])
top_docs = tantivy.TopDocs(3) top_docs = tantivy.TopDocs(3)
(best_score, best_doc_address) = searcher.search(query, nhits=3)[0] (best_score, best_doc_address) = searcher.search(query, top_docs)[0]
best_doc = searcher.doc(best_doc_address) best_doc = searcher.doc(best_doc_address)
assert best_doc["title"] == ["The Old Man and the Sea"] assert best_doc["title"] == ["The Old Man and the Sea"]
print(best_doc)
``` ```