Test reading an index from dir
Created and committed an index dir with 3 documents
This commit is contained in:
parent
9864053cf8
commit
b2a769f1d7
@ -123,3 +123,54 @@ class TestClass(object):
|
||||
# no "bod" field
|
||||
with pytest.raises(ValueError):
|
||||
q_parser.parse_query("bod:title")
|
||||
|
||||
|
||||
class TestFromDiskClass(object):
|
||||
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
builder = tantivy.SchemaBuilder()
|
||||
title = builder.add_text_field("title", stored=True)
|
||||
body = builder.add_text_field("body")
|
||||
cls.default_args = [title, body]
|
||||
schema = builder.build()
|
||||
cls.schema = schema
|
||||
cls.index = tantivy.Index(schema)
|
||||
|
||||
def test_exists(self):
|
||||
# prefer to keep it separate in case anyone deletes this
|
||||
# runs from the root directory
|
||||
path_to_index = "tests/test_index/"
|
||||
assert self.index.exists(path_to_index)
|
||||
|
||||
def test_opens_from_dir(self):
|
||||
path_to_index = "tests/test_index/"
|
||||
tantivy.Index(self.schema, path_to_index)
|
||||
|
||||
def test_create_readers(self):
|
||||
path_to_index = "tests/test_index/"
|
||||
idx = tantivy.Index(self.schema, path_to_index)
|
||||
reload_policy = "OnCommit" # or "Manual"
|
||||
assert idx.reader(reload_policy, 4)
|
||||
assert idx.reader("Manual", 4)
|
||||
|
||||
def test_create_writer_and_reader(self):
|
||||
path_to_index = "tests/test_index/"
|
||||
idx = tantivy.Index(self.schema, path_to_index)
|
||||
writer = idx.writer()
|
||||
reload_policy = "OnCommit" # or "Manual"
|
||||
reader = idx.reader(reload_policy, 4)
|
||||
|
||||
# check against the opstamp in the meta file
|
||||
with open("tests/test_index/meta.json") as f:
|
||||
expected_last_opstamp = json.load(f)["opstamp"]
|
||||
assert writer.commit_opstamp == expected_last_opstamp
|
||||
|
||||
q_parser = tantivy.QueryParser.for_index(idx, self.default_args)
|
||||
# get all documents
|
||||
query = q_parser.parse_query("*")
|
||||
top_docs = tantivy.TopDocs(10)
|
||||
|
||||
docs = reader.searcher().search(query, top_docs)
|
||||
for (_score, doc_addr) in docs:
|
||||
print(reader.searcher().doc(doc_addr))
|
||||
|
||||
1
tests/test_index/.managed.json
Normal file
1
tests/test_index/.managed.json
Normal file
@ -0,0 +1 @@
|
||||
["1fc74026b3954090b69817d58bcce59a.fieldnorm","f79c6d0a68e04210a4d026ecf151a1e7.pos","1fc74026b3954090b69817d58bcce59a.store","meta.json","f79c6d0a68e04210a4d026ecf151a1e7.fieldnorm","8949f79450d349e2bd51d885f44c354f.fieldnorm","f79c6d0a68e04210a4d026ecf151a1e7.posidx","8949f79450d349e2bd51d885f44c354f.store","8949f79450d349e2bd51d885f44c354f.term","8949f79450d349e2bd51d885f44c354f.pos","1fc74026b3954090b69817d58bcce59a.posidx","1fc74026b3954090b69817d58bcce59a.pos","8949f79450d349e2bd51d885f44c354f.posidx","f79c6d0a68e04210a4d026ecf151a1e7.idx","1fc74026b3954090b69817d58bcce59a.fast","f79c6d0a68e04210a4d026ecf151a1e7.fast","f79c6d0a68e04210a4d026ecf151a1e7.term","1fc74026b3954090b69817d58bcce59a.term","8949f79450d349e2bd51d885f44c354f.idx","1fc74026b3954090b69817d58bcce59a.idx","f79c6d0a68e04210a4d026ecf151a1e7.store","8949f79450d349e2bd51d885f44c354f.fast"]
|
||||
0
tests/test_index/.tantivy-meta.lock
Normal file
0
tests/test_index/.tantivy-meta.lock
Normal file
0
tests/test_index/.tantivy-writer.lock
Normal file
0
tests/test_index/.tantivy-writer.lock
Normal file
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.fast
Normal file
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.fast
Normal file
Binary file not shown.
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.fieldnorm
Normal file
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.fieldnorm
Normal file
Binary file not shown.
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.idx
Normal file
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.idx
Normal file
Binary file not shown.
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.pos
Normal file
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.pos
Normal file
Binary file not shown.
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.posidx
Normal file
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.posidx
Normal file
Binary file not shown.
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.store
Normal file
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.store
Normal file
Binary file not shown.
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.term
Normal file
BIN
tests/test_index/1fc74026b3954090b69817d58bcce59a.term
Normal file
Binary file not shown.
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.fast
Normal file
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.fast
Normal file
Binary file not shown.
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.fieldnorm
Normal file
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.fieldnorm
Normal file
Binary file not shown.
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.idx
Normal file
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.idx
Normal file
Binary file not shown.
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.pos
Normal file
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.pos
Normal file
Binary file not shown.
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.posidx
Normal file
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.posidx
Normal file
Binary file not shown.
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.store
Normal file
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.store
Normal file
Binary file not shown.
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.term
Normal file
BIN
tests/test_index/8949f79450d349e2bd51d885f44c354f.term
Normal file
Binary file not shown.
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.fast
Normal file
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.fast
Normal file
Binary file not shown.
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.fieldnorm
Normal file
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.fieldnorm
Normal file
Binary file not shown.
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.idx
Normal file
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.idx
Normal file
Binary file not shown.
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.pos
Normal file
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.pos
Normal file
Binary file not shown.
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.posidx
Normal file
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.posidx
Normal file
Binary file not shown.
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.store
Normal file
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.store
Normal file
Binary file not shown.
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.term
Normal file
BIN
tests/test_index/f79c6d0a68e04210a4d026ecf151a1e7.term
Normal file
Binary file not shown.
44
tests/test_index/meta.json
Normal file
44
tests/test_index/meta.json
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"segments": [
|
||||
{
|
||||
"segment_id": "1fc74026-b395-4090-b698-17d58bcce59a",
|
||||
"max_doc": 1,
|
||||
"deletes": null
|
||||
},
|
||||
{
|
||||
"segment_id": "8949f794-50d3-49e2-bd51-d885f44c354f",
|
||||
"max_doc": 1,
|
||||
"deletes": null
|
||||
},
|
||||
{
|
||||
"segment_id": "f79c6d0a-68e0-4210-a4d0-26ecf151a1e7",
|
||||
"max_doc": 1,
|
||||
"deletes": null
|
||||
}
|
||||
],
|
||||
"schema": [
|
||||
{
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"options": {
|
||||
"indexing": {
|
||||
"record": "position",
|
||||
"tokenizer": "default"
|
||||
},
|
||||
"stored": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"type": "text",
|
||||
"options": {
|
||||
"indexing": {
|
||||
"record": "position",
|
||||
"tokenizer": "default"
|
||||
},
|
||||
"stored": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"opstamp": 6
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user