From 7ce637d5cb7f14805424960b4634a80c722071f4 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sun, 6 Oct 2019 12:47:50 +0100 Subject: [PATCH] Fix TypeErrors in readme example --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 18e3b8e..8f8e5de 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,10 @@ index = tantivy.Index(schema) # Adding one document. writer = index.writer() -writer.add_document({ - "title": "The Old Man and the Sea", - "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.""" -}) +writer.add_document(tantivy.Document( + title=["The Old Man and the Sea"], + 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."""], +)) # ... and committing writer.commit() @@ -51,10 +49,11 @@ writer.commit() # Reload the index to ensure it points to the last commit. index.reload(); searcher = index.searcher() -query = index.parse_query("sea whale", ["title", "body"]) +query = index.parse_query("fish days", ["title", "body"]) 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) assert best_doc["title"] == ["The Old Man and the Sea"] +print(best_doc) ```