From 3aac7bad02036393444a9fedd930be9f08c65a8a Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Sat, 24 Mar 2018 11:38:52 +0100 Subject: Cleanup formatting. --- .../attribute_searchable_adapter_test.cpp | 50 ++++++++-------------- 1 file changed, 18 insertions(+), 32 deletions(-) (limited to 'searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp') diff --git a/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp b/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp index a6e06af1b71..89f6bb5d88e 100644 --- a/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp +++ b/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp @@ -64,6 +64,7 @@ using search::queryeval::PostingInfo; using search::queryeval::SearchIterator; using std::vector; using vespalib::string; +using vespalib::make_string; using namespace search::attribute; using namespace search; @@ -318,17 +319,13 @@ TEST("requireThatLocationTermsWork") { // 0xcc is z-curve for (10, 10). MyAttributeManager attribute_manager = makeAttributeManager(int64_t(0xcc)); - SimpleLocationTerm node(Location(Point(10, 10), 3, 0), - field, 0, Weight(0)); + SimpleLocationTerm node(Location(Point(10, 10), 3, 0), field, 0, Weight(0)); EXPECT_TRUE(search(node, attribute_manager)); - node = SimpleLocationTerm(Location(Point(100, 100), 3, 0), - field, 0, Weight(0)); + node = SimpleLocationTerm(Location(Point(100, 100), 3, 0), field, 0, Weight(0)); EXPECT_TRUE(!search(node, attribute_manager)); - node = SimpleLocationTerm(Location(Point(13, 13), 4, 0), - field, 0, Weight(0)); + node = SimpleLocationTerm(Location(Point(13, 13), 4, 0), field, 0, Weight(0)); EXPECT_TRUE(!search(node, attribute_manager)); - node = SimpleLocationTerm(Location(Point(10, 13), 3, 0), - field, 0, Weight(0)); + node = SimpleLocationTerm(Location(Point(10, 13), 3, 0), field, 0, Weight(0)); EXPECT_TRUE(search(node, attribute_manager)); } @@ -336,17 +333,13 @@ TEST("requireThatOptimizedLocationTermsWork") { // 0xcc is z-curve for (10, 10). MyAttributeManager attribute_manager = makeFastSearchLongAttributeManager(int64_t(0xcc)); - SimpleLocationTerm node(Location(Point(10, 10), 3, 0), - field, 0, Weight(0)); + SimpleLocationTerm node(Location(Point(10, 10), 3, 0), field, 0, Weight(0)); EXPECT_TRUE(search(node, attribute_manager, true)); - node = SimpleLocationTerm(Location(Point(100, 100), 3, 0), - field, 0, Weight(0)); + node = SimpleLocationTerm(Location(Point(100, 100), 3, 0), field, 0, Weight(0)); EXPECT_TRUE(!search(node, attribute_manager, true)); - node = SimpleLocationTerm(Location(Point(13, 13), 4, 0), - field, 0, Weight(0)); + node = SimpleLocationTerm(Location(Point(13, 13), 4, 0), field, 0, Weight(0)); EXPECT_TRUE(!search(node, attribute_manager, true)); - node = SimpleLocationTerm(Location(Point(10, 13), 3, 0), - field, 0, Weight(0)); + node = SimpleLocationTerm(Location(Point(10, 13), 3, 0), field, 0, Weight(0)); EXPECT_TRUE(search(node, attribute_manager, true)); } @@ -368,7 +361,7 @@ TEST("require that optimized location search works with wrapped bounding box (no } void set_weights(StringAttribute *attr, uint32_t docid, - int32_t foo_weight, int32_t bar_weight, int32_t baz_weight) + int32_t foo_weight, int32_t bar_weight, int32_t baz_weight) { attr->clearDoc(docid); if (foo_weight > 0) attr->append(docid, "foo", foo_weight); @@ -456,13 +449,11 @@ TEST("require that direct attribute iterators work") { EXPECT_TRUE(result.has_minmax); EXPECT_EQUAL(100, result.min_weight); EXPECT_EQUAL(1000, result.max_weight); - EXPECT_TRUE(result.iterator_dump.find("DocumentWeightSearchIterator") - != vespalib::string::npos); + EXPECT_TRUE(result.iterator_dump.find("DocumentWeightSearchIterator") != vespalib::string::npos); } else { EXPECT_EQUAL(num_docs, result.est_hits); EXPECT_FALSE(result.has_minmax); - EXPECT_TRUE(result.iterator_dump.find("DocumentWeightSearchIterator") - == vespalib::string::npos); + EXPECT_TRUE(result.iterator_dump.find("DocumentWeightSearchIterator") == vespalib::string::npos); } ASSERT_EQUAL(3u, result.hits.size()); EXPECT_FALSE(result.est_empty); @@ -551,10 +542,7 @@ TEST("require that predicate query in non-predicate field yields empty.") { } TEST("require that predicate query in predicate field yields results.") { - PredicateAttribute *attr = - new PredicateAttribute( - field, Config(BasicType::PREDICATE, - CollectionType::SINGLE)); + PredicateAttribute *attr = new PredicateAttribute(field, Config(BasicType::PREDICATE, CollectionType::SINGLE)); add_docs(attr, num_docs); attr->getIndex().indexEmptyDocument(2); // matches anything attr->getIndex().commit(); @@ -611,10 +599,8 @@ void set_attr_value(AttributeVector &attr, uint32_t docid, size_t value) { } } -MyAttributeManager make_diversity_setup(BasicType::Type field_type, - bool field_fast_search, - BasicType::Type other_type, - bool other_fast_search) +MyAttributeManager make_diversity_setup(BasicType::Type field_type, bool field_fast_search, + BasicType::Type other_type, bool other_fast_search) { Config field_cfg(field_type, CollectionType::SINGLE); field_cfg.setFastSearch(field_fast_search); @@ -663,9 +649,9 @@ TEST("require that diversity range searches work for various types") { for (bool other_fast_search: std::vector({true, false})) { MyAttributeManager manager = make_diversity_setup(field_type, true, other_type, other_fast_search); for (bool strict: std::vector({true, false})) { - TEST_STATE(vespalib::make_string("field_type: %s, other_type: %s, other_fast_search: %s, strict: %s", - BasicType(field_type).asString(), BasicType(other_type).asString(), - other_fast_search ? "true" : "false", strict ? "true" : "false").c_str()); + TEST_STATE(make_string("field_type: %s, other_type: %s, other_fast_search: %s, strict: %s", + BasicType(field_type).asString(), BasicType(other_type).asString(), + other_fast_search ? "true" : "false", strict ? "true" : "false").c_str()); EXPECT_EQUAL(999u, diversity_hits(manager, "[;;1000;other;10]", strict)); EXPECT_EQUAL(999u, diversity_hits(manager, "[;;-1000;other;10]", strict)); EXPECT_EQUAL(100u, diversity_hits(manager, "[;;1000;other;1]", strict)); -- cgit v1.2.3 From 9e70b2520ace7245a949553f9f92646db910b804 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 3 Apr 2018 13:52:54 +0200 Subject: Add test to prove that the filter aspect is correctly handled also for the DirectAttributeBlueprint --- .../attribute_searchable_adapter_test.cpp | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp') diff --git a/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp b/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp index 89f6bb5d88e..d8e295cb469 100644 --- a/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp +++ b/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp @@ -370,9 +370,10 @@ void set_weights(StringAttribute *attr, uint32_t docid, attr->commit(); } -MyAttributeManager make_weighted_string_attribute_manager(bool fast_search) { +MyAttributeManager make_weighted_string_attribute_manager(bool fast_search, bool isFilter = false) { Config cfg(BasicType::STRING, CollectionType::WSET); cfg.setFastSearch(fast_search); + cfg.setIsFilter(isFilter); AttributeVector::SP attr_ptr = AttributeFactory::createAttribute(field, cfg); StringAttribute *attr = static_cast(attr_ptr.get()); add_docs(attr, num_docs); @@ -463,6 +464,26 @@ TEST("require that direct attribute iterators work") { } } +TEST("require that single weighted set turns filter on filter fields") { + bool fast_search = true; + bool strict = true; + bool isFilter = true; + MyAttributeManager attribute_manager = make_weighted_string_attribute_manager(fast_search, isFilter); + SimpleStringTerm empty_node("notfoo", "", 0, Weight(1)); + Result empty_result = do_search(attribute_manager, empty_node, strict); + EXPECT_EQUAL(0u, empty_result.hits.size()); + SimpleStringTerm node("foo", "", 0, Weight(1)); + Result result = do_search(attribute_manager, node, strict); + EXPECT_EQUAL(3u, result.est_hits); + EXPECT_TRUE(result.iterator_dump.find("DocumentWeightSearchIterator") == vespalib::string::npos); + EXPECT_TRUE(result.iterator_dump.find("FilterAttributePostingListIteratorT") == vespalib::string::npos); + ASSERT_EQUAL(3u, result.hits.size()); + EXPECT_FALSE(result.est_empty); + EXPECT_EQUAL(20u, result.hits[0].docid); + EXPECT_EQUAL(40u, result.hits[1].docid); + EXPECT_EQUAL(50u, result.hits[2].docid); +} + const char *as_str(bool flag) { return flag? "true" : "false"; } TEST("require that attribute parallel wand works") { -- cgit v1.2.3 From 057bcb5ca301f475208552c75d527ee8ccade6d4 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 3 Apr 2018 18:22:40 +0200 Subject: make the test pass again as the code was already correct. --- .../tests/attribute/searchable/attribute_searchable_adapter_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp') diff --git a/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp b/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp index d8e295cb469..1306a0aaaac 100644 --- a/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp +++ b/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp @@ -476,7 +476,7 @@ TEST("require that single weighted set turns filter on filter fields") { Result result = do_search(attribute_manager, node, strict); EXPECT_EQUAL(3u, result.est_hits); EXPECT_TRUE(result.iterator_dump.find("DocumentWeightSearchIterator") == vespalib::string::npos); - EXPECT_TRUE(result.iterator_dump.find("FilterAttributePostingListIteratorT") == vespalib::string::npos); + EXPECT_TRUE(result.iterator_dump.find("FilterAttributePostingListIteratorT") != vespalib::string::npos); ASSERT_EQUAL(3u, result.hits.size()); EXPECT_FALSE(result.est_empty); EXPECT_EQUAL(20u, result.hits[0].docid); -- cgit v1.2.3