diff options
author | Henning Baldersheim <balder@oath.com> | 2018-05-23 18:21:01 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2018-05-23 23:21:04 +0200 |
commit | fad8b5a92af2c3bc5749f8196f8f1f954b0d7171 (patch) | |
tree | 352fc9fbe1b16a12a82af0c7f4a14b94105151b0 /searchlib | |
parent | ec25fafaa3b922c688113bdefac2d12feb9fdca8 (diff) |
Only return the weight of the first match. Accumulate on the outside.
Diffstat (limited to 'searchlib')
6 files changed, 55 insertions, 57 deletions
diff --git a/searchlib/src/tests/attribute/searchcontext/searchcontext.cpp b/searchlib/src/tests/attribute/searchcontext/searchcontext.cpp index 70fde827a6b..2f819905492 100644 --- a/searchlib/src/tests/attribute/searchcontext/searchcontext.cpp +++ b/searchlib/src/tests/attribute/searchcontext/searchcontext.cpp @@ -194,12 +194,8 @@ private: // test search iterator functionality - void testStrictSearchIterator(SearchContext & threeHits, - SearchContext & noHits, - const IteratorTester & typeTester); - void testNonStrictSearchIterator(SearchContext & threeHits, - SearchContext & noHits, - const IteratorTester & typeTester); + void testStrictSearchIterator(SearchContext & threeHits, SearchContext & noHits, const IteratorTester & typeTester); + void testNonStrictSearchIterator(SearchContext & threeHits, SearchContext & noHits, const IteratorTester & typeTester); void fillForSearchIteratorTest(IntegerAttribute * ia); void fillForSemiNibbleSearchIteratorTest(IntegerAttribute * ia); void testSearchIterator(); @@ -207,17 +203,19 @@ private: // test search iterator unpacking void fillForSearchIteratorUnpackingTest(IntegerAttribute * ia, bool extra); - void testSearchIteratorUnpacking(const AttributePtr & ptr, - SearchContext & sc, - bool extra, - bool strict); + void testSearchIteratorUnpacking(const AttributePtr & ptr, SearchContext & sc, bool extra, bool strict) { + for (bool withElementId : {false, true}) { + testSearchIteratorUnpacking(ptr, sc, extra, strict, withElementId); + } + } + void testSearchIteratorUnpacking(const AttributePtr & ptr, SearchContext & sc, + bool extra, bool strict, bool withElementId); void testSearchIteratorUnpacking(); // test range search template <typename VectorType> - void performRangeSearch(const VectorType & vec, const vespalib::string & term, - const DocSet & expected); + void performRangeSearch(const VectorType & vec, const vespalib::string & term, const DocSet & expected); template <typename VectorType, typename ValueType> void testRangeSearch(const AttributePtr & ptr, uint32_t numDocs, std::vector<ValueType> values); void testRangeSearch(); @@ -225,8 +223,7 @@ private: // test case insensitive search - void performCaseInsensitiveSearch(const StringAttribute & vec, const vespalib::string & term, - const DocSet & expected); + void performCaseInsensitiveSearch(const StringAttribute & vec, const vespalib::string & term, const DocSet & expected); void testCaseInsensitiveSearch(const AttributePtr & ptr); void testCaseInsensitiveSearch(); void testRegexSearch(const AttributePtr & ptr); @@ -253,25 +250,19 @@ private: void requireThatSearchIsWorkingAfterLoadAndClearDoc(); template <typename VectorType, typename ValueType> - void requireThatSearchIsWorkingAfterUpdates(const vespalib::string & name, - const Config & cfg, - ValueType value1, - ValueType value2); + void requireThatSearchIsWorkingAfterUpdates(const vespalib::string & name, const Config & cfg, + ValueType value1, ValueType value2); void requireThatSearchIsWorkingAfterUpdates(); void requireThatFlagAttributeIsWorkingWhenNewDocsAreAdded(); template <typename VectorType, typename ValueType> - void requireThatInvalidSearchTermGivesZeroHits(const vespalib::string & name, - const Config & cfg, - ValueType value); + void requireThatInvalidSearchTermGivesZeroHits(const vespalib::string & name, const Config & cfg, ValueType value); void requireThatInvalidSearchTermGivesZeroHits(); void requireThatFlagAttributeHandlesTheByteRange(); - void requireThatOutOfBoundsSearchTermGivesZeroHits(const vespalib::string &name, - const Config &cfg, - int64_t maxValue); + void requireThatOutOfBoundsSearchTermGivesZeroHits(const vespalib::string &name, const Config &cfg, int64_t maxValue); void requireThatOutOfBoundsSearchTermGivesZeroHits(); // init maps with config objects @@ -948,13 +939,10 @@ SearchContextTest::fillForSearchIteratorUnpackingTest(IntegerAttribute * ia, } void -SearchContextTest::testSearchIteratorUnpacking(const AttributePtr & attr, - SearchContext & sc, - bool extra, - bool strict) +SearchContextTest::testSearchIteratorUnpacking(const AttributePtr & attr, SearchContext & sc, + bool extra, bool strict, bool withElementId) { - LOG(info, - "testSearchIteratorUnpacking: vector '%s'", attr->getName().c_str()); + LOG(info, "testSearchIteratorUnpacking: vector '%s'", attr->getName().c_str()); TermFieldMatchData md; md.reset(100); @@ -965,6 +953,9 @@ SearchContextTest::testSearchIteratorUnpacking(const AttributePtr & attr, sc.fetchPostings(strict); SearchBasePtr sb = sc.createIterator(&md, strict); + if (withElementId) { + sb = std::make_unique<attribute::ElementIterator>(std::move(sb), sc, md); + } sb->initFullRange(); std::vector<int32_t> weights(3); @@ -993,12 +984,30 @@ SearchContextTest::testSearchIteratorUnpacking(const AttributePtr & attr, sb->unpack(2); EXPECT_EQUAL(sb->getDocId(), 2u); EXPECT_EQUAL(md.getDocId(), 2u); - EXPECT_EQUAL(md.getWeight(), weights[1]); + if (withElementId && attr->hasMultiValue() && !attr->hasWeightedSetType()) { + EXPECT_EQUAL(2, md.end()- md.begin()); + EXPECT_EQUAL(md.begin()[0].getElementId(), 0u); + EXPECT_EQUAL(md.begin()[0].getElementWeight(), 1); + EXPECT_EQUAL(md.begin()[1].getElementId(), 1u); + EXPECT_EQUAL(md.begin()[1].getElementWeight(), 1); + } else { + EXPECT_EQUAL(md.getWeight(), weights[1]); + } sb->unpack(3); EXPECT_EQUAL(sb->getDocId(), 3u); EXPECT_EQUAL(md.getDocId(), 3u); - EXPECT_EQUAL(md.getWeight(), weights[2]); + if (withElementId && attr->hasMultiValue() && !attr->hasWeightedSetType()) { + EXPECT_EQUAL(3, md.end()- md.begin()); + EXPECT_EQUAL(md.begin()[0].getElementId(), 0u); + EXPECT_EQUAL(md.begin()[0].getElementWeight(), 1); + EXPECT_EQUAL(md.begin()[1].getElementId(), 1u); + EXPECT_EQUAL(md.begin()[1].getElementWeight(), 1); + EXPECT_EQUAL(md.begin()[2].getElementId(), 2u); + EXPECT_EQUAL(md.begin()[2].getElementWeight(), 1); + } else { + EXPECT_EQUAL(md.getWeight(), weights[2]); + } if (extra) { sb->unpack(4); EXPECT_EQUAL(sb->getDocId(), 4u); diff --git a/searchlib/src/vespa/searchlib/attribute/elementiterator.cpp b/searchlib/src/vespa/searchlib/attribute/elementiterator.cpp index 68fb178105e..0050919ac8c 100644 --- a/searchlib/src/vespa/searchlib/attribute/elementiterator.cpp +++ b/searchlib/src/vespa/searchlib/attribute/elementiterator.cpp @@ -17,9 +17,8 @@ ElementIterator::doSeek(uint32_t docid) { void ElementIterator::doUnpack(uint32_t docid) { _tfmda.reset(docid); - _search->doUnpack(docid); int32_t weight(0); - for (int32_t id = _searchContext.find(docid, 0, weight); id >= 0; id = _searchContext.find(docid, 0, weight)) { + for (int32_t id = _searchContext.find(docid, 0, weight); id >= 0; id = _searchContext.find(docid, id+1, weight)) { _tfmda.appendPosition(TermFieldMatchDataPosition(id, 0, weight, 1)); } } diff --git a/searchlib/src/vespa/searchlib/attribute/multinumericattribute.h b/searchlib/src/vespa/searchlib/attribute/multinumericattribute.h index a03bc74a44a..dec8ca43143 100644 --- a/searchlib/src/vespa/searchlib/attribute/multinumericattribute.h +++ b/searchlib/src/vespa/searchlib/attribute/multinumericattribute.h @@ -133,20 +133,16 @@ public: public: ArraySearchContext(std::unique_ptr<QueryTermSimple> qTerm, const NumericAttribute & toBeSearched); int32_t find(DocId doc, int32_t elemId, int32_t & weight) const { - uint32_t hitCount = 0; MultiValueArrayRef values(_toBeSearched._mvMapping.get(doc)); - int32_t firstMatch = -1; for (uint32_t i(elemId); i < values.size(); i++) { if (this->match(values[i].value())) { - if (firstMatch == -1) { - firstMatch = i; - } - hitCount++; + weight = 1; + return i; } } - weight = hitCount; + weight = 0; - return firstMatch; + return -1; } int32_t find(DocId doc, int32_t elemId) const { diff --git a/searchlib/src/vespa/searchlib/attribute/multinumericenumattribute.h b/searchlib/src/vespa/searchlib/attribute/multinumericenumattribute.h index 35a81dafb51..3a7b20c686b 100644 --- a/searchlib/src/vespa/searchlib/attribute/multinumericenumattribute.h +++ b/searchlib/src/vespa/searchlib/attribute/multinumericenumattribute.h @@ -73,7 +73,7 @@ protected: T v = _toBeSearched._enumStore.getValue(indices[i].value()); if (this->match(v)) { weight = indices[i].weight(); - return elemId; + return i; } } return -1; @@ -122,21 +122,17 @@ protected: int32_t find(DocId doc, int32_t elemId, int32_t & weight) const { - uint32_t hitCount = 0; WeightedIndexArrayRef indices(_toBeSearched._mvMapping.get(doc)); - int32_t firstMatch = -1; for (uint32_t i(elemId); i < indices.size(); i++) { T v = _toBeSearched._enumStore.getValue(indices[i].value()); if (this->match(v)) { - if (firstMatch == -1) { - firstMatch = i; - } - hitCount++; + weight = 1; + return i; } } - weight = hitCount; + weight = 0; - return firstMatch; + return -1; } bool diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp index 48f9d0404c5..15c6b1933ee 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp +++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp @@ -113,7 +113,8 @@ template <typename DataT> void PostingListSearchContextT<DataT>::fetchPostings(bool strict) { - assert(!_fetchPostingsDone); + if (_fetchPostingsDone) return; + _fetchPostingsDone = true; if (_uniqueValues < 2u) { return; diff --git a/searchlib/src/vespa/searchlib/attribute/stringbase.h b/searchlib/src/vespa/searchlib/attribute/stringbase.h index 4176d172ab0..d3394b8280d 100644 --- a/searchlib/src/vespa/searchlib/attribute/stringbase.h +++ b/searchlib/src/vespa/searchlib/attribute/stringbase.h @@ -148,16 +148,13 @@ private: template<typename WeightedT, typename Accessor, typename Collector> int32_t collectMatches(vespalib::ConstArrayRef<WeightedT> w, int32_t elemId, const Accessor & ac, Collector & collector) const { - int firstMatch = -1; for (uint32_t i(elemId); i < w.size(); i++) { if (isMatch(ac.get(w[i].value()))) { collector.addWeight(w[i].weight()); - if (firstMatch == -1) { - firstMatch = i; - } + return i; } } - return firstMatch; + return -1; } |