diff options
author | Geir Storli <geirst@yahoo-inc.com> | 2017-03-15 14:51:21 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahoo-inc.com> | 2017-03-15 14:51:21 +0000 |
commit | ac342e998ba02c42a7a22651986f1dfaa8131b54 (patch) | |
tree | 7e6758f36303721670647ae2508de8a4fec99d71 | |
parent | f111ab07d4edc8a1640ed87b74162f6d3b99ad71 (diff) |
Extend IAttributeVector API with function for creating a ISearchContext.
10 files changed, 108 insertions, 37 deletions
diff --git a/searchcommon/src/vespa/searchcommon/attribute/i_search_context.h b/searchcommon/src/vespa/searchcommon/attribute/i_search_context.h index f5751135ef7..eb5ba68d6ee 100644 --- a/searchcommon/src/vespa/searchcommon/attribute/i_search_context.h +++ b/searchcommon/src/vespa/searchcommon/attribute/i_search_context.h @@ -17,8 +17,11 @@ class QueryTermBase; namespace attribute { +class IAttributeVector; + class ISearchContext { public: + using UP = std::unique_ptr<ISearchContext>; virtual ~ISearchContext() {} virtual unsigned int approximateHits() const = 0; @@ -59,7 +62,8 @@ public: virtual bool valid() const = 0; virtual Int64Range getAsIntegerTerm() const = 0; - virtual const QueryTermBase & queryTerm() const = 0; + virtual const QueryTermBase &queryTerm() const = 0; + virtual const IAttributeVector &attribute() const = 0; }; diff --git a/searchcommon/src/vespa/searchcommon/attribute/iattributevector.h b/searchcommon/src/vespa/searchcommon/attribute/iattributevector.h index 8e17e697d0e..edc71591175 100644 --- a/searchcommon/src/vespa/searchcommon/attribute/iattributevector.h +++ b/searchcommon/src/vespa/searchcommon/attribute/iattributevector.h @@ -10,8 +10,14 @@ #include <vespa/searchcommon/attribute/basictype.h> namespace search { + +class QueryTermSimple; + namespace attribute { +class ISearchContext; +class SearchContextParams; + /** * This class is used to store a value and a weight. * It is used when getting content from a weighted set attribute vector. @@ -236,6 +242,18 @@ public: **/ virtual bool findEnum(const char * value, EnumHandle & e) const = 0; + + /** + * Creates a context for searching this attribute with the given term. + * The search context is used to create the actual search iterator. + * + * @param term the term to search for. + * @param params optional bitvector and diversity settings for the search. + * @return the search context. + **/ + virtual std::unique_ptr<ISearchContext> createSearchContext(std::unique_ptr<QueryTermSimple> term, + const SearchContextParams ¶ms) const = 0; + /** * Returns the basic type of this attribute vector. * diff --git a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp index 8023270446a..47f3520c006 100644 --- a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp +++ b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp @@ -10,6 +10,8 @@ #include <vespa/searchlib/attribute/iattributemanager.h> #include <vespa/searchlib/common/location.h> #include <vespa/searchlib/common/locationiterators.h> +#include <vespa/searchlib/query/queryterm.h> +#include <vespa/searchlib/query/query_term_decoder.h> #include <vespa/searchlib/query/tree/stackdumpcreator.h> #include <vespa/searchlib/queryeval/andsearchstrict.h> #include <vespa/searchlib/queryeval/create_blueprint_visitor_helper.h> @@ -22,14 +24,14 @@ #include <vespa/searchlib/queryeval/predicate_blueprint.h> #include <vespa/searchlib/queryeval/wand/parallel_weak_and_search.h> #include <vespa/searchlib/queryeval/weighted_set_term_search.h> -#include <vespa/searchlib/query/queryterm.h> -#include <sstream> #include <vespa/vespalib/util/regexp.h> +#include <sstream> #include <vespa/log/log.h> LOG_SETUP(".searchlib.attribute.attribute_blueprint_factory"); using search::AttributeVector; +using search::attribute::ISearchContext; using search::fef::TermFieldMatchData; using search::fef::TermFieldMatchDataArray; using search::fef::TermFieldMatchDataPosition; @@ -40,11 +42,11 @@ using search::query::NumberTerm; using search::query::PredicateQuery; using search::query::PrefixTerm; using search::query::RangeTerm; +using search::query::RegExpTerm; using search::query::StackDumpCreator; using search::query::StringTerm; using search::query::SubstringTerm; using search::query::SuffixTerm; -using search::query::RegExpTerm; using search::queryeval::AndBlueprint; using search::queryeval::AndSearchStrict; using search::queryeval::Blueprint; @@ -52,15 +54,15 @@ using search::queryeval::CreateBlueprintVisitorHelper; using search::queryeval::DotProductBlueprint; using search::queryeval::FieldSpec; using search::queryeval::FieldSpecBaseList; +using search::queryeval::IRequestContext; using search::queryeval::MultiSearch; +using search::queryeval::NoUnpack; using search::queryeval::OrLikeSearch; using search::queryeval::OrSearch; using search::queryeval::ParallelWeakAndBlueprint; using search::queryeval::PredicateBlueprint; using search::queryeval::SearchIterator; using search::queryeval::Searchable; -using search::queryeval::NoUnpack; -using search::queryeval::IRequestContext; using search::queryeval::WeightedSetTermBlueprint; using vespalib::geo::ZCurve; using vespalib::string; @@ -77,14 +79,14 @@ class AttributeFieldBlueprint : public search::queryeval::SimpleLeafBlueprint { private: - AttributeVector::SearchContext::UP _search_context; + ISearchContext::UP _search_context; AttributeFieldBlueprint(const FieldSpec &field, const AttributeVector &attribute, const string &query_stack, const attribute::SearchContextParams ¶ms) : SimpleLeafBlueprint(field), - _search_context(attribute.getSearch(query_stack, params).release()) + _search_context(attribute.createSearchContext(QueryTermDecoder::decodeTerm(query_stack), params).release()) { uint32_t estHits = _search_context->approximateHits(); HitEstimate estimate(estHits, estHits == 0); @@ -157,7 +159,7 @@ class LocationPreFilterBlueprint : { private: const AttributeVector & _attribute; - std::vector<AttributeVector::SearchContext::UP> _rangeSearches; + std::vector<ISearchContext::UP> _rangeSearches; bool _should_use; public: @@ -174,7 +176,8 @@ public: search::query::Range qr(r.min(), r.max()); search::query::SimpleRangeTerm rt(qr, "", 0, search::query::Weight(0)); string stack(StackDumpCreator::create(rt)); - _rangeSearches.push_back(attr.getSearch(stack, attribute::SearchContextParams())); + _rangeSearches.push_back(attr.createSearchContext(QueryTermDecoder::decodeTerm(stack), + attribute::SearchContextParams())); estHits += _rangeSearches.back()->approximateHits(); LOG(debug, "Range '%s' estHits %ld", qr.getRangeString().c_str(), estHits); } @@ -570,7 +573,7 @@ public: } else { qt.reset(new search::QueryTermBase(term, search::QueryTermSimple::WORD)); } - ws->addToken(_attr.getSearch(std::move(qt), attribute::SearchContextParams()), weight); + ws->addToken(_attr.createSearchContext(std::move(qt), attribute::SearchContextParams()), weight); } setResult(std::move(result)); } else { diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp index 7a8c44a7a19..f0a0b72a3e6 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp +++ b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp @@ -1,22 +1,23 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "attributefilesavetarget.h" +#include "attributeiterators.hpp" +#include "attributesaver.h" #include "attributevector.h" #include "attributevector.hpp" -#include "attributeiterators.hpp" -#include "attributefilesavetarget.h" -#include "stringbase.h" #include "floatbase.h" #include "interlock.h" -#include "attributesaver.h" -#include <vespa/searchlib/common/tunefileinfo.h> -#include <vespa/searchlib/parsequery/stackdumpiterator.h> -#include <vespa/searchlib/index/dummyfileheadercontext.h> -#include "ipostinglistsearchcontext.h" #include "ipostinglistattributebase.h" -#include <vespa/searchlib/queryeval/emptysearch.h> +#include "ipostinglistsearchcontext.h" +#include "stringbase.h" #include <vespa/document/update/mapvalueupdate.h> #include <vespa/fastlib/io/bufferedfile.h> +#include <vespa/searchlib/common/tunefileinfo.h> +#include <vespa/searchlib/index/dummyfileheadercontext.h> +#include <vespa/searchlib/parsequery/stackdumpiterator.h> #include <vespa/searchlib/query/query.h> +#include <vespa/searchlib/query/query_term_decoder.h> +#include <vespa/searchlib/queryeval/emptysearch.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/log/log.h> @@ -552,7 +553,14 @@ AttributeVector::SearchContext::SearchContext(const AttributeVector &attr) : AttributeVector::SearchContext::UP AttributeVector::getSearch(QueryPacketT searchSpec, const SearchContextParams ¶ms) const { - return getSearch(SearchContext::decodeQuery(searchSpec), params); + return getSearch(QueryTermDecoder::decodeTerm(searchSpec), params); +} + +attribute::ISearchContext::UP +AttributeVector::createSearchContext(QueryTermSimpleUP term, + const attribute::SearchContextParams ¶ms) const +{ + return getSearch(std::move(term), params); } AttributeVector::SearchContext::~SearchContext() { } @@ -567,21 +575,6 @@ AttributeVector::SearchContext::approximateHits() const _attr.getStatus().getNumValues()); } -QueryTermSimple::UP -AttributeVector::SearchContext::decodeQuery(QueryPacketT searchSpec) -{ - QueryTermSimple::UP qt; - QueryNodeResultFactory factory; - Query q(factory, searchSpec); - if (q.valid() && (dynamic_cast<QueryTerm *>(q.getRoot().get()))) { - qt.reset(static_cast<QueryTerm *>(q.getRoot().release())); - } else { - throw IllegalStateException("Failed decoding query"); - } - return qt; -} - - SearchIterator::UP AttributeVector::SearchContext:: createIterator(fef::TermFieldMatchData *matchData, bool strict) diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.h b/searchlib/src/vespa/searchlib/attribute/attributevector.h index f82a66942c1..80f2fed9f8d 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributevector.h +++ b/searchlib/src/vespa/searchlib/attribute/attributevector.h @@ -525,7 +525,6 @@ public: typedef std::unique_ptr<SearchContext> UP; ~SearchContext(); unsigned int approximateHits() const override; - static QueryTermSimpleUP decodeQuery(QueryPacketT searchSpec); /** * Creates an attribute search iterator associated with this @@ -586,6 +585,8 @@ public: }; SearchContext::UP getSearch(QueryPacketT searchSpec, const attribute::SearchContextParams ¶ms) const; + virtual attribute::ISearchContext::UP createSearchContext(QueryTermSimpleUP term, + const attribute::SearchContextParams ¶ms) const override; virtual SearchContext::UP getSearch(QueryTermSimpleUP term, const attribute::SearchContextParams ¶ms) const = 0; virtual const EnumStoreBase *getEnumStoreBase() const; virtual const attribute::MultiValueMappingBase *getMultiValueBase() const; diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp index 93fe7125f57..f02bf78c59e 100644 --- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp +++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp @@ -92,6 +92,13 @@ bool ImportedAttributeVector::findEnum(const char *value, EnumHandle &e) const { return _target_attribute->findEnum(value, e); } +std::unique_ptr<ISearchContext> ImportedAttributeVector::createSearchContext(std::unique_ptr<QueryTermSimple> term, + const SearchContextParams ¶ms) const { + (void) term; + (void) params; + return std::unique_ptr<ISearchContext>(); +} + BasicType::Type ImportedAttributeVector::getBasicType() const { return _target_attribute->getBasicType(); } diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h index 0c8de22986a..645f61d5aaa 100644 --- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h +++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h @@ -50,6 +50,8 @@ public: uint32_t get(DocId docId, WeightedConstChar * buffer, uint32_t sz) const override; uint32_t get(DocId docId, WeightedEnum * buffer, uint32_t sz) const override; bool findEnum(const char * value, EnumHandle & e) const override; + std::unique_ptr<ISearchContext> createSearchContext(std::unique_ptr<QueryTermSimple> term, + const SearchContextParams ¶ms) const override; BasicType::Type getBasicType() const override; size_t getFixedWidth() const override; CollectionType::Type getCollectionType() const override; diff --git a/searchlib/src/vespa/searchlib/query/CMakeLists.txt b/searchlib/src/vespa/searchlib/query/CMakeLists.txt index d255732835e..9cac9f4f8b0 100644 --- a/searchlib/src/vespa/searchlib/query/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/query/CMakeLists.txt @@ -5,6 +5,7 @@ vespa_add_library(searchlib_query OBJECT querynode.cpp base.cpp query.cpp + query_term_decoder.cpp querynoderesultbase.cpp DEPENDS ) diff --git a/searchlib/src/vespa/searchlib/query/query_term_decoder.cpp b/searchlib/src/vespa/searchlib/query/query_term_decoder.cpp new file mode 100644 index 00000000000..c05e51468bf --- /dev/null +++ b/searchlib/src/vespa/searchlib/query/query_term_decoder.cpp @@ -0,0 +1,23 @@ +// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "query_term_decoder.h" +#include "query.h" +#include <vespa/vespalib/util/exceptions.h> + +namespace search { + +QueryTermSimple::UP +QueryTermDecoder::decodeTerm(QueryPacketT term) +{ + QueryTermSimple::UP result; + QueryNodeResultFactory factory; + Query query(factory, term); + if (query.valid() && (dynamic_cast<QueryTerm *>(query.getRoot().get()))) { + result.reset(static_cast<QueryTerm *>(query.getRoot().release())); + } else { + throw vespalib::IllegalStateException("Failed decoding query term"); + } + return result; +} + +} diff --git a/searchlib/src/vespa/searchlib/query/query_term_decoder.h b/searchlib/src/vespa/searchlib/query/query_term_decoder.h new file mode 100644 index 00000000000..ed7cec5f1cf --- /dev/null +++ b/searchlib/src/vespa/searchlib/query/query_term_decoder.h @@ -0,0 +1,19 @@ +// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "queryterm.h" +#include <vespa/vespalib/stllike/string.h> + +namespace search { + +/** + * Class used to decode a single term. + */ +struct QueryTermDecoder { + using QueryPacketT = vespalib::stringref; + + static QueryTermSimple::UP decodeTerm(QueryPacketT term); +}; + +} |