Skip to content

Commit e7224f1

Browse files
authored
Fix code snippets in README.md (#203)
1 parent fd642f4 commit e7224f1

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import tantivy
6969
schema_builder = tantivy.SchemaBuilder()
7070
schema_builder.add_text_field("title", stored=True)
7171
schema_builder.add_text_field("body", stored=True)
72-
schema_builder.add_integer_field("doc_id",stored=True)
72+
schema_builder.add_integer_field("doc_id", stored=True, indexed=True)
7373
schema = schema_builder.build()
7474

7575
# Creating our index (in memory)
@@ -80,7 +80,11 @@ To have a persistent index, use the path
8080
parameter to store the index on the disk, e.g:
8181

8282
```python
83-
index = tantivy.Index(schema, path=os.getcwd() + '/index')
83+
import os
84+
85+
index_path = os.path.abspath("index")
86+
os.makedirs(index_path)
87+
index = tantivy.Index(schema, path=index_path)
8488
```
8589

8690
By default, tantivy offers the following tokenizers
@@ -152,13 +156,14 @@ Some basic query Formats.
152156
query = index.parse_query('(Old AND Man) OR Stream', ["title", "body"])
153157
(best_score, best_doc_address) = searcher.search(query, 3).hits[0]
154158
best_doc = searcher.doc(best_doc_address)
159+
print(best_doc)
155160
```
156161

157162
- +(includes) and -(excludes) operators.
158163
```python
159164
query = index.parse_query('+Old +Man chef -fished', ["title", "body"])
160-
(best_score, best_doc_address) = searcher.search(query, 3).hits[0]
161-
best_doc = searcher.doc(best_doc_address)
165+
hits = searcher.search(query, 3).hits
166+
print(len(hits))
162167
```
163168
Note: in a query like above, a word with no +/- acts like an OR.
164169

@@ -167,14 +172,16 @@ Note: in a query like above, a word with no +/- acts like an OR.
167172
query = index.parse_query('"eighty-four days"', ["title", "body"])
168173
(best_score, best_doc_address) = searcher.search(query, 3).hits[0]
169174
best_doc = searcher.doc(best_doc_address)
175+
print(best_doc)
170176
```
171177

172178
- integer search
173179
```python
174-
query = index.parse_query('"eighty-four days"', ["doc_id"])
180+
query = index.parse_query("1", ["doc_id"])
175181
(best_score, best_doc_address) = searcher.search(query, 3).hits[0]
176182
best_doc = searcher.doc(best_doc_address)
183+
print(best_doc)
177184
```
178185
Note: for integer search, the integer field should be indexed.
179186

180-
For more possible query formats and possible query options, see [Tantivy Query Parser Docs.](https://docs.rs/tantivy/latest/tantivy/query/struct.QueryParser.html)
187+
For more possible query formats and possible query options, see [Tantivy Query Parser Docs.](https://docs.rs/tantivy/latest/tantivy/query/struct.QueryParser.html)

0 commit comments

Comments
 (0)