Merge branch 'fix-readme'
commit
f8d43502c3
17
README.md
17
README.md
|
@ -38,23 +38,22 @@ 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()
|
||||||
|
|
||||||
|
|
||||||
# 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)
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue