aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-11-14 12:37:47 +0100
committerTor Egge <Tor.Egge@online.no>2022-11-14 12:37:47 +0100
commit3cd84044662d3770bb580e89e39e7c699b19823a (patch)
tree2234a662e74f1d99e7fc8df1839c3caf28a2b255 /searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
parent64aa97631e1ac9c2b968efcfeb84be89a15666fc (diff)
Improve hit estimate for ImportedSearchContext.
Diffstat (limited to 'searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp')
-rw-r--r--searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp47
1 files changed, 46 insertions, 1 deletions
diff --git a/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp b/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
index 6cb0dec3c1f..847a992d241 100644
--- a/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
+++ b/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
@@ -6,6 +6,7 @@
#include <vespa/searchlib/query/query_term_ucs4.h>
#include <vespa/searchlib/queryeval/simpleresult.h>
#include <vespa/searchlib/test/imported_attribute_fixture.h>
+#include <vespa/searchlib/test/mock_gid_to_lid_mapping.h>
#include <vespa/vespalib/test/insertion_operators.h>
#include <vespa/searchlib/queryeval/executeinfo.h>
@@ -75,13 +76,57 @@ bool is_strict_hit_with_weight(Iterator& iter, TermFieldMatchData& match,
EXPECT_EQUAL(weight, match.getWeight()));
}
-TEST_F("approximateHits() returns document count of reference attribute", Fixture) {
+TEST_F("approximateHits() returns document count of reference attribute when not using fast-search target attribute", Fixture) {
+ add_n_docs_with_undefined_values(*f.target_attr, 10);
add_n_docs_with_undefined_values(*f.reference_attr, 101);
auto ctx = f.create_context(word_term("foo"));
EXPECT_EQUAL(101u, ctx->approximateHits());
}
+TEST_F("approximateHits() estimates hits when using fast-search target attribute", Fixture(false, FastSearchConfig::ExplicitlyEnabled))
+{
+ constexpr uint32_t target_docs = 1000;
+ constexpr uint32_t docs = 10000;
+ constexpr uint32_t target_gids = 200;
+ f.target_attr->addReservedDoc();
+ add_n_docs_with_undefined_values(*f.target_attr, target_docs);
+ f.reference_attr->addReservedDoc();
+ add_n_docs_with_undefined_values(*f.reference_attr, docs);
+ auto target_attr = dynamic_cast<IntegerAttribute *>(f.target_attr.get());
+ // 2 documents with value 20, 110 documents with value 30.
+ for (uint32_t i = 1; i < 3; ++i) {
+ target_attr->update(i, 20);
+ }
+ for (uint32_t i = 10; i < 120; ++i) {
+ target_attr->update(i, 30);
+ }
+ f.target_attr->commit();
+ // Assign target gids
+ for (uint32_t i = 1; i <= target_gids; ++i) {
+ auto target_gid = dummy_gid(i);
+ f.mapper_factory->_map[target_gid] = i;
+ f.reference_attr->notifyReferencedPut(target_gid, i);
+ }
+ // Add 2 references to each target gid
+ for (uint32_t i = 1; i <= target_gids * 2; ++i) {
+ f.reference_attr->update(i, dummy_gid(((i - 1) % target_gids) + 1));
+ }
+ f.reference_attr->commit();
+ auto ctx = f.create_context(word_term("10"));
+ // Exact count: 0 target hits => 0
+ EXPECT_EQUAL(0u, ctx->approximateHits());
+ TermFieldMatchData match;
+ auto iter = f.create_iterator(*ctx, match, false);
+ EXPECT_TRUE(iter->matches_any() == Trinary::False);
+ ctx = f.create_context(word_term("20"));
+ // Exact count: 2 target hits, 2 docs / target doc => 2 * 2 = 4
+ EXPECT_EQUAL(4u, ctx->approximateHits());
+ ctx = f.create_context(word_term("30"));
+ // Approximation: 110 target hits => 110 * 10001 / 1001 = 1099
+ EXPECT_EQUAL(1099u, ctx->approximateHits());
+}
+
TEST_F("attributeName() returns imported attribute name", Fixture) {
auto ctx = f.create_context(word_term("foo"));
EXPECT_EQUAL(f.default_imported_attr_name(), ctx->attributeName());