Skip to content

Commit

Permalink
Merge pull request #4345 from vespa-engine/vekterli/add-sameelement-f…
Browse files Browse the repository at this point in the history
…uzzy-test

Add system test for sameElement + fuzzy combination
  • Loading branch information
vekterli authored Feb 13, 2025
2 parents 00aa789 + 179d2f4 commit 8116226
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/search/fuzzy_matching/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"array_slow": ["ThisIsAFox", "Bear"],
"array_fast": ["ThisIsAFox", "Bear"],
"wset_slow": {"ThisIsAFox": 100, "Bear": 100},
"wset_fast": {"ThisIsAFox": 100, "Bear": 100}
"wset_fast": {"ThisIsAFox": 100, "Bear": 100},
"my_struct_array": [
{"f1": "aaa", "f2": "bbb"},
{"f1": "ccc", "f2": "ddd"}
]
}
},
{
Expand All @@ -16,7 +20,11 @@
"array_slow": ["ThisIsAFox", "Beaver"],
"array_fast": ["ThisIsAFox", "Beaver"],
"wset_slow": {"ThisIsAFox": 100, "Beaver": 100},
"wset_fast": {"ThisIsAFox": 100, "Beaver": 100}
"wset_fast": {"ThisIsAFox": 100, "Beaver": 100},
"my_struct_array": [
{"f1": "xaa", "f2": "bbb"},
{"f1": "aaa", "f2": "ddd"}
]
}
},
{
Expand Down
52 changes: 52 additions & 0 deletions tests/search/fuzzy_matching/fuzzy_same_element.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright Vespa.ai. All rights reserved.
require 'indexed_search_test'
require 'cgi'

# sameElement+fuzzy is in a dedicated test that does _not_ check streaming mode,
# as this combination does not currently work.
# TODO make it work with both modes and move to other test.
class FuzzySameElementSearch < SearchTest

def setup
set_owner('vekterli')
end

def teardown
stop
end

def make_query(a)
yql_query = CGI::escape("select * from sources * where #{a}")
my_query = "query=" + yql_query + "&type=yql"
my_query
end

def assert_documents(query, exp_docids)
result = search(query)
assert_hitcount(result, exp_docids.size)
result.sort_results_by("documentid")
for i in 0...exp_docids.size do
exp_docid = "id:test:test::#{exp_docids[i]}"
assert_field_value(result, "documentid", exp_docid, i)
end
end

def assert_fuzzy_same_element(max_edits, term1, term2, expected_docs)
q = "my_struct_array contains sameElement(" +
"f1 contains ({maxEditDistance:#{max_edits}}fuzzy(\"#{term1}\")), " +
"f2 contains ({maxEditDistance:#{max_edits}}fuzzy(\"#{term2}\")))"
assert_documents(make_query(q), expected_docs)
end

def test_fuzzysearch_with_sameelement
set_description('Test that the fuzzy() operator can be used as part of sameElement')
deploy_app(SearchApp.new.sd(selfdir+'test.sd'))
start
feed_and_wait_for_docs('test', 6, :file => selfdir + 'docs.json')

assert_fuzzy_same_element(1, 'aax', 'bbx', [1])
assert_fuzzy_same_element(2, 'aax', 'bbx', [1, 2])
assert_fuzzy_same_element(2, 'aax', 'ddx', [2])
end

end
14 changes: 14 additions & 0 deletions tests/search/fuzzy_matching/test.sd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ schema test {
indexing: attribute
attribute: fast-search
}
struct my_struct {
field f1 type string {}
field f2 type string {}
}
field my_struct_array type array<my_struct> {
struct-field f1 {
indexing: attribute
attribute: fast-search
}
struct-field f2 {
indexing: attribute
attribute: fast-search
}
}
}


Expand Down

0 comments on commit 8116226

Please sign in to comment.