summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-05-28 12:03:39 +0000
committerArne Juul <arnej@verizonmedia.com>2020-05-28 14:06:08 +0000
commit17d88084e6b898bacc44b2805206d552c14cd167 (patch)
tree5c7fe0a65029f4ad9bb6ce83011ad19f42f46c61 /searchlib
parentf48cd2de9227c811475797429588e590583dc0fb (diff)
make more intermediate operators implement createFilterSearch
* Rank just returns filter from first child * Near degrades to AND in the UPPER_BOUND case * ONear degrades to AND in the UPPER_BOUND case * SourceBlender degrades to OR in the UPPER_BOUND case * Phrase degrades to AND in the UPPER_BOUND case
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp47
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h17
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp16
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.h4
4 files changed, 80 insertions, 4 deletions
diff --git a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp
index 624b9a1a368..31ee19d238c 100644
--- a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp
@@ -432,6 +432,28 @@ WeakAndBlueprint::createIntermediateSearch(const MultiSearch::Children &sub_sear
//-----------------------------------------------------------------------------
+SearchIterator::UP
+FilterUpperAndBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) const
+{
+ if (constraint == FilterConstraint::UPPER_BOUND) {
+ MultiSearch::Children sub_searches;
+ sub_searches.reserve(childCnt());
+ for (size_t i = 0; i < childCnt(); ++i) {
+ bool child_strict = strict && inheritStrict(i);
+ auto search = getChild(i).createFilterSearch(child_strict, constraint);
+ sub_searches.push_back(search.release());
+ }
+ UnpackInfo unpack_info;
+ AndSearch * search = AndSearch::create(sub_searches, strict, unpack_info);
+ search->estimate(getState().estimate().estHits);
+ return SearchIterator::UP(search);
+ } else {
+ return std::make_unique<EmptySearch>();
+ }
+}
+
+//-----------------------------------------------------------------------------
+
Blueprint::HitEstimate
NearBlueprint::combine(const std::vector<HitEstimate> &data) const
{
@@ -602,6 +624,13 @@ RankBlueprint::createIntermediateSearch(const MultiSearch::Children &sub_searche
}
}
+SearchIterator::UP
+RankBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) const
+{
+ assert(childCnt() > 0);
+ return getChild(0).createFilterSearch(strict, constraint);
+}
+
//-----------------------------------------------------------------------------
SourceBlenderBlueprint::SourceBlenderBlueprint(const ISourceSelector &selector)
@@ -668,6 +697,24 @@ SourceBlenderBlueprint::createIntermediateSearch(const MultiSearch::Children &su
children, strict));
}
+SearchIterator::UP
+SourceBlenderBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) const
+{
+ if (constraint == FilterConstraint::UPPER_BOUND) {
+ MultiSearch::Children sub_searches;
+ sub_searches.reserve(childCnt());
+ for (size_t i = 0; i < childCnt(); ++i) {
+ bool child_strict = strict && inheritStrict(i);
+ auto search = getChild(i).createFilterSearch(child_strict, constraint);
+ sub_searches.push_back(search.release());
+ }
+ UnpackInfo unpack_info;
+ return SearchIterator::UP(OrSearch::create(sub_searches, strict, unpack_info));
+ } else {
+ return std::make_unique<EmptySearch>();
+ }
+}
+
bool
SourceBlenderBlueprint::isCompatibleWith(const SourceBlenderBlueprint &other) const
{
diff --git a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h
index ecad9431a81..b404ca9c6c1 100644
--- a/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h
+++ b/searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.h
@@ -32,6 +32,7 @@ private:
//-----------------------------------------------------------------------------
+/** normal AND operator */
class AndBlueprint : public IntermediateBlueprint
{
public:
@@ -56,6 +57,7 @@ public:
//-----------------------------------------------------------------------------
+/** normal OR operator */
class OrBlueprint : public IntermediateBlueprint
{
public:
@@ -103,7 +105,14 @@ public:
//-----------------------------------------------------------------------------
-class NearBlueprint : public IntermediateBlueprint
+/** shared implementation for operators that degrade to AND when creating filter for upper-bound case */
+class FilterUpperAndBlueprint : public IntermediateBlueprint
+{
+public:
+ SearchIterator::UP createFilterSearch(bool strict, FilterConstraint constraint) const override;
+};
+
+class NearBlueprint : public FilterUpperAndBlueprint
{
private:
uint32_t _window;
@@ -124,7 +133,7 @@ public:
//-----------------------------------------------------------------------------
-class ONearBlueprint : public IntermediateBlueprint
+class ONearBlueprint : public FilterUpperAndBlueprint
{
private:
uint32_t _window;
@@ -157,6 +166,8 @@ public:
SearchIterator::UP
createIntermediateSearch(const MultiSearch::Children &subSearches,
bool strict, fef::MatchData &md) const override;
+ SearchIterator::UP
+ createFilterSearch(bool strict, FilterConstraint constraint) const override;
};
//-----------------------------------------------------------------------------
@@ -181,6 +192,8 @@ public:
SearchIterator::UP
createIntermediateSearch(const MultiSearch::Children &subSearches,
bool strict, fef::MatchData &md) const override;
+ SearchIterator::UP
+ createFilterSearch(bool strict, FilterConstraint constraint) const override;
/** check if this blueprint has the same source selector as the other */
bool isCompatibleWith(const SourceBlenderBlueprint &other) const;
diff --git a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp
index c52cf6ddae1..fc29c7ef45d 100644
--- a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp
@@ -2,6 +2,7 @@
#include "simple_phrase_blueprint.h"
#include "simple_phrase_search.h"
+#include "emptysearch.h"
#include "field_spec.hpp"
#include <vespa/searchlib/fef/termfieldmatchdata.h>
#include <vespa/vespalib/objects/visit.hpp>
@@ -83,6 +84,21 @@ SimplePhraseBlueprint::createLeafSearch(const fef::TermFieldMatchDataArray &tfmd
return phrase;
}
+SearchIterator::UP
+SimplePhraseBlueprint::createFilterSearch(bool strict, FilterConstraint constraint) const
+{
+ if (constraint == FilterConstraint::UPPER_BOUND) {
+ MultiSearch::Children children(_terms.size());
+ for (size_t i = 0; i < _terms.size(); ++i) {
+ bool child_strict = strict && (i == 0);
+ children[i] = _terms[i]->createFilterSearch(child_strict, constraint).release();
+ }
+ UnpackInfo unpack_info;
+ return SearchIterator::UP(AndSearch::create(children, strict, unpack_info));
+ } else {
+ return std::make_unique<EmptySearch>();
+ }
+}
void
SimplePhraseBlueprint::fetchPostings(const ExecuteInfo &execInfo)
diff --git a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.h b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.h
index 0fb1599d68f..b20866fdd1f 100644
--- a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.h
+++ b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.h
@@ -33,8 +33,8 @@ public:
// used by create visitor
void addTerm(Blueprint::UP term);
- SearchIteratorUP
- createLeafSearch(const fef::TermFieldMatchDataArray &tfmda, bool strict) const override;
+ SearchIteratorUP createLeafSearch(const fef::TermFieldMatchDataArray &tfmda, bool strict) const override;
+ SearchIteratorUP createFilterSearch(bool strict, FilterConstraint constraint) const override;
void visitMembers(vespalib::ObjectVisitor &visitor) const override;
void fetchPostings(const ExecuteInfo &execInfo) override;
};