diff options
author | Håvard Pettersen <havardpe@oath.com> | 2017-09-08 09:56:37 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2017-09-19 12:31:41 +0000 |
commit | 19cfc9e6f58107d0868c4823e60dca38f0570d8b (patch) | |
tree | 4af67418b37170e3c68e09303ee21b750d266c35 /searchlib | |
parent | 5dfbc2dbfc08fbe79704e210f210a27782a05ee1 (diff) |
added soft_reset to MatchData to prepare for re-use
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/tests/fef/termfieldmodel/termfieldmodel_test.cpp | 22 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/fef/matchdata.cpp | 9 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/fef/matchdata.h | 9 |
3 files changed, 40 insertions, 0 deletions
diff --git a/searchlib/src/tests/fef/termfieldmodel/termfieldmodel_test.cpp b/searchlib/src/tests/fef/termfieldmodel/termfieldmodel_test.cpp index 2a6cc2501d8..01c72497246 100644 --- a/searchlib/src/tests/fef/termfieldmodel/termfieldmodel_test.cpp +++ b/searchlib/src/tests/fef/termfieldmodel/termfieldmodel_test.cpp @@ -220,4 +220,26 @@ TEST("require that TermFieldMatchData can be tagged as needed or not") { EXPECT_TRUE(!tfmd.isNotNeeded()); } +TEST("require that MatchData soft_reset retains appropriate state") { + auto md = MatchData::makeTestInstance(10, 10); + md->set_termwise_limit(0.5); + auto *old_term = md->resolveTermField(7); + old_term->tagAsNotNeeded(); + old_term->populate_fixed()->setElementWeight(21); + old_term->resetOnlyDocId(42); + EXPECT_EQUAL(md->get_termwise_limit(), 0.5); + EXPECT_TRUE(old_term->isNotNeeded()); + EXPECT_EQUAL(old_term->getFieldId(), 7u); + EXPECT_EQUAL(old_term->getWeight(), 21); + EXPECT_EQUAL(old_term->getDocId(), 42u); + md->soft_reset(); + auto *new_term = md->resolveTermField(7); + EXPECT_EQUAL(new_term, old_term); + EXPECT_EQUAL(md->get_termwise_limit(), 1.0); + EXPECT_TRUE(!new_term->isNotNeeded()); + EXPECT_EQUAL(new_term->getFieldId(), 7u); + EXPECT_EQUAL(new_term->getWeight(), 21); + EXPECT_EQUAL(new_term->getDocId(), TermFieldMatchData::invalidId()); +} + TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/searchlib/src/vespa/searchlib/fef/matchdata.cpp b/searchlib/src/vespa/searchlib/fef/matchdata.cpp index 4ce2a7c9299..0c589749112 100644 --- a/searchlib/src/vespa/searchlib/fef/matchdata.cpp +++ b/searchlib/src/vespa/searchlib/fef/matchdata.cpp @@ -11,6 +11,15 @@ MatchData::MatchData(const Params &cparams) { } +void +MatchData::soft_reset() +{ + for (auto &tfmd: _termFields) { + tfmd.resetOnlyDocId(TermFieldMatchData::invalidId()).tagAsNeeded(); + } + _termwise_limit = 1.0; +} + MatchData::UP MatchData::makeTestInstance(uint32_t numTermFields, uint32_t fieldIdLimit) { diff --git a/searchlib/src/vespa/searchlib/fef/matchdata.h b/searchlib/src/vespa/searchlib/fef/matchdata.h index 472b34a823f..5b06f4d37e0 100644 --- a/searchlib/src/vespa/searchlib/fef/matchdata.h +++ b/searchlib/src/vespa/searchlib/fef/matchdata.h @@ -58,6 +58,15 @@ public: **/ explicit MatchData(const Params &cparams); + /** + * Reset this match data in such a way that it can be re-used with + * either the same search iterator tree or with a new search + * iterator tree where the only difference in interaction with the + * match data is which terms are unpacked. Note that this will + * reset some properties, but not all. Use with caution. + **/ + void soft_reset(); + MatchData(const MatchData &rhs) = delete; MatchData & operator=(const MatchData &rhs) = delete; |