Skip to content

Commit

Permalink
Test using tensor fields as part of document selections
Browse files Browse the repository at this point in the history
  • Loading branch information
vekterli committed Dec 5, 2024
1 parent 7a51d9e commit bb501a4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/search/tensor_feed/tensor_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ def test_tensor_json_feed
puts "search_docs: #{search_docs}"
assert_tensor_docs(search_docs)

visit_response = vespa.document_api_v1.visit(:selection => "test.my_tensor", :fieldSet => "test:[document]", :cluster => "search", :wantedDocumentCount => 10)
puts "visit_response: #{visit_response}"
visit_docs = extract_visit_docs(visit_response)
puts "visit_docs: #{visit_docs}"
assert_visit_result_tensor_present(visit_docs)

visit_response = vespa.document_api_v1.visit(:selection => "not test.my_tensor", :fieldSet => "test:[document]", :cluster => "search", :wantedDocumentCount => 10)
puts "visit_response: #{visit_response}"
visit_docs = extract_visit_docs(visit_response)
puts "visit_docs: #{visit_docs}"
assert_visit_result_tensor_not_present(visit_docs)

visit_response = vespa.document_api_v1.visit(:selection => "test", :fieldSet => "test:[document]", :cluster => "search", :wantedDocumentCount => 10)
puts "visit_response: #{visit_response}"
visit_docs = extract_visit_docs(visit_response)
Expand Down Expand Up @@ -86,6 +98,20 @@ def run_tensor_json_feed_attribute
assert_tensor_docs_after_updates(search_docs)
end

def extract_doc_ids(docs)
docs.map { |d| d['id'] }.to_a
end

def assert_visit_result_tensor_present(docs)
ids = extract_doc_ids(docs)
assert_equal(ids, ['id:test:test::1', 'id:test:test::2', 'id:test:test::3'])
end

def assert_visit_result_tensor_not_present(docs)
ids = extract_doc_ids(docs)
assert_equal(ids, ['id:test:test::0'])
end

def assert_tensor_docs(docs)
assert_nil(get_tensor_field(docs[0]))
assert_tensor_field([], docs[1])
Expand Down

0 comments on commit bb501a4

Please sign in to comment.