diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2019-06-11 14:08:32 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@broadpark.no> | 2019-06-11 14:12:46 +0200 |
commit | 95e8dfa3dcb77ec7b643124f9f468063f41616e1 (patch) | |
tree | 5abd69a4cbbffd919af37c0ab12ceb38fef0851b | |
parent | bf0f7ced58968e26eafa632cb68cfb3757d4dd2f (diff) |
Extend query environment with method to get average field length.
13 files changed, 48 insertions, 11 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp b/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp index 268fe63ba4c..672e7f78784 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp @@ -4,6 +4,7 @@ #include "blueprintbuilder.h" #include "termdatafromnode.h" #include "same_element_builder.h" +#include <vespa/searchcorespi/index/indexsearchable.h> #include <vespa/searchlib/query/tree/customtypevisitor.h> #include <vespa/searchlib/queryeval/leaf_blueprints.h> #include <vespa/searchlib/queryeval/intermediate_blueprints.h> diff --git a/searchcore/src/vespa/searchcore/proton/matching/fakesearchcontext.h b/searchcore/src/vespa/searchcore/proton/matching/fakesearchcontext.h index 02aedf15d6e..fe9c20112f4 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/fakesearchcontext.h +++ b/searchcore/src/vespa/searchcore/proton/matching/fakesearchcontext.h @@ -52,7 +52,7 @@ public: search::queryeval::ISourceSelector &selector() { return *_selector; } // Implements ISearchContext - search::queryeval::Searchable &getIndexes() override { + IndexSearchable &getIndexes() override { return *_indexes; } diff --git a/searchcore/src/vespa/searchcore/proton/matching/isearchcontext.h b/searchcore/src/vespa/searchcore/proton/matching/isearchcontext.h index 2965e3796bf..dc840dc79ff 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/isearchcontext.h +++ b/searchcore/src/vespa/searchcore/proton/matching/isearchcontext.h @@ -6,6 +6,8 @@ #include <memory> +namespace searchcorespi { class IndexSearchable; } + namespace proton::matching { /** @@ -31,13 +33,14 @@ public: ISearchContext & operator = (const ISearchContext &) = delete; typedef search::queryeval::Searchable Searchable; + using IndexSearchable = searchcorespi::IndexSearchable; /** * Obtain the index fields searchable. * * @return index fields searchable. **/ - virtual Searchable &getIndexes() = 0; + virtual IndexSearchable &getIndexes() = 0; /** * Obtain the attribute fields searchable. diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp index 4a944dc3214..5d1e2212c83 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/match_tools.cpp @@ -9,6 +9,7 @@ #include <vespa/log/log.h> LOG_SETUP(".proton.matching.match_tools"); #include <vespa/searchlib/query/tree/querytreecreator.h> +#include <vespa/searchcorespi/index/indexsearchable.h> using search::attribute::IAttributeContext; using search::queryeval::IRequestContext; @@ -158,7 +159,7 @@ MatchToolsFactory(QueryLimiter & queryLimiter, _hardDoom(hardDoom), _query(), _match_limiter(), - _queryEnv(indexEnv, attributeContext, rankProperties), + _queryEnv(indexEnv, attributeContext, rankProperties, searchContext.getIndexes()), _mdl(), _rankSetup(rankSetup), _featureOverrides(featureOverrides), diff --git a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp index d4320c87ab2..ec48ee7164b 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "queryenvironment.h" +#include <vespa/searchlib/index/i_field_length_inspector.h> using search::attribute::IAttributeContext; using search::fef::IIndexEnvironment; @@ -11,12 +12,14 @@ namespace proton::matching { QueryEnvironment::QueryEnvironment(const IIndexEnvironment &indexEnv, const IAttributeContext &attrContext, - const Properties &properties) + const Properties &properties, + const search::index::IFieldLengthInspector &field_length_inspector) : _indexEnv(indexEnv), _attrContext(attrContext), _properties(properties), _locations(1), - _terms() + _terms(), + _field_length_inspector(field_length_inspector) { } @@ -53,6 +56,12 @@ QueryEnvironment::getAttributeContext() const return _attrContext; } +double +QueryEnvironment::get_average_field_length(const vespalib::string &field_name) const +{ + return _field_length_inspector.get_field_length_info(field_name).get_average_field_length(); +} + const search::fef::IIndexEnvironment & QueryEnvironment::getIndexEnvironment() const { diff --git a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h index d79ba1796f7..8f958870d52 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h +++ b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h @@ -6,6 +6,8 @@ #include <vespa/searchlib/fef/properties.h> #include <vespa/searchlib/fef/location.h> +namespace search::index { class IFieldLengthInspector; } + namespace proton::matching { /** @@ -19,6 +21,7 @@ private: search::fef::Properties _properties; std::vector<const search::fef::Location *> _locations; std::vector<const search::fef::ITermData *> _terms; + const search::index::IFieldLengthInspector &_field_length_inspector; QueryEnvironment(const QueryEnvironment &); QueryEnvironment &operator=(const QueryEnvironment &); @@ -33,7 +36,8 @@ public: **/ QueryEnvironment(const search::fef::IIndexEnvironment &indexEnv, const search::attribute::IAttributeContext &attrContext, - const search::fef::Properties &properties); + const search::fef::Properties &properties, + const search::index::IFieldLengthInspector &field_length_inspector); /** * Used to edit the list of terms by the one setting up this query @@ -71,6 +75,8 @@ public: // inherited from search::fef::IQueryEnvironment const search::attribute::IAttributeContext & getAttributeContext() const override; + double get_average_field_length(const vespalib::string &field_name) const override; + // inherited from search::fef::IQueryEnvironment const search::fef::IIndexEnvironment & getIndexEnvironment() const override; diff --git a/searchcore/src/vespa/searchcore/proton/matching/same_element_builder.cpp b/searchcore/src/vespa/searchcore/proton/matching/same_element_builder.cpp index d3a0ec4726f..16c86e8a4f5 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/same_element_builder.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/same_element_builder.cpp @@ -4,6 +4,7 @@ #include "querynodes.h" #include <vespa/searchlib/query/tree/customtypevisitor.h> #include <vespa/searchlib/queryeval/leaf_blueprints.h> +#include <vespa/searchcorespi/index/indexsearchable.h> using search::queryeval::Blueprint; using search::queryeval::EmptyBlueprint; diff --git a/searchcore/src/vespa/searchcore/proton/server/searchcontext.cpp b/searchcore/src/vespa/searchcore/proton/server/searchcontext.cpp index ea09c60bd52..d9207ef70e1 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchcontext.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/searchcontext.cpp @@ -3,10 +3,11 @@ #include "searchcontext.h" using search::queryeval::Searchable; +using searchcorespi::IndexSearchable; namespace proton { -Searchable & +IndexSearchable & SearchContext::getIndexes() { return *_indexSearchable; @@ -23,7 +24,7 @@ uint32_t SearchContext::getDocIdLimit() return _docIdLimit; } -SearchContext::SearchContext(const Searchable::SP &indexSearchable, uint32_t docIdLimit) +SearchContext::SearchContext(const std::shared_ptr<IndexSearchable> &indexSearchable, uint32_t docIdLimit) : _indexSearchable(indexSearchable), _attributeBlueprintFactory(), _docIdLimit(docIdLimit) diff --git a/searchcore/src/vespa/searchcore/proton/server/searchcontext.h b/searchcore/src/vespa/searchcore/proton/server/searchcontext.h index 71475c3decd..b9ea6b334b3 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchcontext.h +++ b/searchcore/src/vespa/searchcore/proton/server/searchcontext.h @@ -16,16 +16,16 @@ class SearchContext : public matching::ISearchContext { private: /// Snapshot of the indexes used. - Searchable::SP _indexSearchable; + std::shared_ptr<IndexSearchable> _indexSearchable; search::AttributeBlueprintFactory _attributeBlueprintFactory; uint32_t _docIdLimit; - Searchable &getIndexes() override; + IndexSearchable &getIndexes() override; Searchable &getAttributes() override; uint32_t getDocIdLimit() override; public: - SearchContext(const Searchable::SP &indexSearchable, uint32_t docIdLimit); + SearchContext(const std::shared_ptr<IndexSearchable> &indexSearchable, uint32_t docIdLimit); }; } // namespace proton diff --git a/searchlib/src/vespa/searchlib/fef/iqueryenvironment.h b/searchlib/src/vespa/searchlib/fef/iqueryenvironment.h index a7f268e5c6b..041e9ec67bc 100644 --- a/searchlib/src/vespa/searchlib/fef/iqueryenvironment.h +++ b/searchlib/src/vespa/searchlib/fef/iqueryenvironment.h @@ -70,6 +70,15 @@ public: virtual const search::attribute::IAttributeContext & getAttributeContext() const = 0; /** + * Returns the average field length for the given field. + * + * @param field_name field name + * + * @return average field length + **/ + virtual double get_average_field_length(const vespalib::string &field_name) const = 0; + + /** * Returns a const view of the index environment. * * @return index environment diff --git a/searchlib/src/vespa/searchlib/fef/phrasesplitter.h b/searchlib/src/vespa/searchlib/fef/phrasesplitter.h index 4c7ca4b67d7..4e46c9eaa7c 100644 --- a/searchlib/src/vespa/searchlib/fef/phrasesplitter.h +++ b/searchlib/src/vespa/searchlib/fef/phrasesplitter.h @@ -113,6 +113,7 @@ public: const Properties & getProperties() const override { return _queryEnv.getProperties(); } const Location & getLocation() const override { return _queryEnv.getLocation(); } const attribute::IAttributeContext & getAttributeContext() const override { return _queryEnv.getAttributeContext(); } + double get_average_field_length(const vespalib::string &field_name) const override { return _queryEnv.get_average_field_length(field_name); } const IIndexEnvironment & getIndexEnvironment() const override { return _queryEnv.getIndexEnvironment(); } void bind_match_data(const fef::MatchData &md) { _matchData = &md; } }; diff --git a/searchlib/src/vespa/searchlib/fef/test/queryenvironment.h b/searchlib/src/vespa/searchlib/fef/test/queryenvironment.h index 0179b5020e6..4d7a92586e6 100644 --- a/searchlib/src/vespa/searchlib/fef/test/queryenvironment.h +++ b/searchlib/src/vespa/searchlib/fef/test/queryenvironment.h @@ -40,6 +40,9 @@ public: const ITermData *getTerm(uint32_t idx) const override { return idx < _terms.size() ? &_terms[idx] : NULL; } const Location & getLocation() const override { return _location; } const search::attribute::IAttributeContext &getAttributeContext() const override { return *_attrCtx; } + double get_average_field_length(const vespalib::string &) const override { + return 1.0; + } const IIndexEnvironment &getIndexEnvironment() const override { assert(_indexEnv != NULL); return *_indexEnv; } /** Returns a reference to the index environment of this. */ diff --git a/streamingvisitors/src/vespa/searchvisitor/queryenvironment.h b/streamingvisitors/src/vespa/searchvisitor/queryenvironment.h index b9391ac838c..db0f95cb6bb 100644 --- a/streamingvisitors/src/vespa/searchvisitor/queryenvironment.h +++ b/streamingvisitors/src/vespa/searchvisitor/queryenvironment.h @@ -54,6 +54,8 @@ public: // inherit documentation virtual const search::attribute::IAttributeContext & getAttributeContext() const override { return *_attrCtx; } + double get_average_field_length(const vespalib::string &) const override { return 1.0; } + // inherit documentation virtual const search::fef::IIndexEnvironment & getIndexEnvironment() const override { return _indexEnv; } |