diff options
author | Arne H Juul <arnej27959@users.noreply.github.com> | 2020-07-16 17:45:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-16 17:45:01 +0200 |
commit | bc2c2241cfb7980ec122050f693de68052ad8b2d (patch) | |
tree | 9cdda0c638b84239d778363467dc4557f31a9b00 | |
parent | 81656283891fb3a661e866bd6f534e5efeb76cfd (diff) | |
parent | 244bec357ad0bd00fcb998eb0c3a951babb1331a (diff) |
Merge pull request #13908 from vespa-engine/arnej/remove-fef-location
Arnej/remove fef location
18 files changed, 87 insertions, 214 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/matching/query.cpp b/searchcore/src/vespa/searchcore/proton/matching/query.cpp index 8edf85657dc..65959e6e6de 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/query.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/query.cpp @@ -102,7 +102,7 @@ GeoLocationSpec process_location_term(ProtonLocationTerm &pterm) { void exchange_location_nodes(const string &location_str, Node::UP &query_tree, - std::vector<search::fef::Location> &fef_locations) + std::vector<GeoLocationSpec> &fef_locations) { std::vector<GeoLocationSpec> locationSpecs; @@ -118,13 +118,7 @@ void exchange_location_nodes(const string &location_str, } for (const GeoLocationSpec &spec : locationSpecs) { if (spec.location.has_point) { - search::fef::Location fef_loc; - fef_loc.setAttribute(spec.field_name); - fef_loc.setXPosition(spec.location.point.x); - fef_loc.setYPosition(spec.location.point.y); - fef_loc.setXAspect(spec.location.x_aspect.multiplier); - fef_loc.setValid(true); - fef_locations.push_back(fef_loc); + fef_locations.push_back(spec); } } if (parsed.location.can_limit()) { @@ -189,7 +183,7 @@ Query::extractTerms(vector<const ITermData *> &terms) } void -Query::extractLocations(vector<const search::fef::Location *> &locations) +Query::extractLocations(vector<const GeoLocationSpec *> &locations) { locations.clear(); for (const auto & loc : _locations) { diff --git a/searchcore/src/vespa/searchcore/proton/matching/query.h b/searchcore/src/vespa/searchcore/proton/matching/query.h index 5a484d2ce1f..952b6260da1 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/query.h +++ b/searchcore/src/vespa/searchcore/proton/matching/query.h @@ -2,7 +2,7 @@ #pragma once -#include <vespa/searchlib/fef/location.h> +#include <vespa/searchlib/common/geo_location_spec.h> #include <vespa/searchlib/fef/itermdata.h> #include <vespa/searchlib/fef/matchdatalayout.h> #include <vespa/searchlib/fef/iindexenvironment.h> @@ -22,9 +22,12 @@ private: search::query::Node::UP _query_tree; Blueprint::UP _blueprint; Blueprint::UP _whiteListBlueprint; - std::vector<search::fef::Location> _locations; + std::vector<search::common::GeoLocationSpec> _locations; public: + /** Convenience typedef. */ + using GeoLocationSpecPtrs = std::vector<const search::common::GeoLocationSpec *>; + Query(); ~Query(); /** @@ -65,7 +68,7 @@ public: * * @param locs where to collect locations **/ - void extractLocations(std::vector<const search::fef::Location *> &locs); + void extractLocations(GeoLocationSpecPtrs &locs); /** * Reserve room for terms in the query in the given match data diff --git a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp index 667b48d2acd..448ce14dd51 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp @@ -5,7 +5,6 @@ using search::attribute::IAttributeContext; using search::fef::IIndexEnvironment; -using search::fef::Location; using search::fef::Properties; namespace proton::matching { diff --git a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h index 426123599bd..6daf488297d 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h +++ b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h @@ -4,7 +4,6 @@ #include <vespa/searchlib/fef/iqueryenvironment.h> #include <vespa/searchlib/fef/properties.h> -#include <vespa/searchlib/fef/location.h> namespace search::index { class IFieldLengthInspector; } @@ -19,7 +18,7 @@ private: const search::fef::IIndexEnvironment &_indexEnv; const search::attribute::IAttributeContext &_attrContext; search::fef::Properties _properties; - std::vector<const search::fef::Location *> _locations; + GeoLocationSpecPtrs _locations; std::vector<const search::fef::ITermData *> _terms; const search::index::IFieldLengthInspector &_field_length_inspector; @@ -56,7 +55,7 @@ public: * * @return modifiable list of location data pointers **/ - std::vector<const search::fef::Location *> &locations() { + GeoLocationSpecPtrs &locations() { return _locations; } @@ -70,7 +69,7 @@ public: const search::fef::ITermData *getTerm(uint32_t idx) const override; // inherited from search::fef::IQueryEnvironment - std::vector<const search::fef::Location *> getAllLocations() const override { + GeoLocationSpecPtrs getAllLocations() const override { return _locations; } diff --git a/searchlib/src/tests/features/prod_features.cpp b/searchlib/src/tests/features/prod_features.cpp index f886ba59c1c..25b5ba20d26 100644 --- a/searchlib/src/tests/features/prod_features.cpp +++ b/searchlib/src/tests/features/prod_features.cpp @@ -62,6 +62,8 @@ using search::StringAttribute; using search::SingleBoolAttribute; using search::WeightedSetStringExtAttribute; using search::attribute::WeightedEnumContent; +using search::common::GeoLocation; +using search::common::GeoLocationSpec; using AttributePtr = AttributeVector::SP; using AVC = search::attribute::Config; @@ -507,8 +509,8 @@ Test::assertCloseness(feature_t exp, const vespalib::string & attr, double dista int32_t x = 0; positions.emplace_back(x, x); setupForDistanceTest(ft, "pos", positions, false); - ft.getQueryEnv().getLocation().setXPosition((int)distance); - ft.getQueryEnv().getLocation().setValid(true); + GeoLocation::Point p{int32_t(distance), 0}; + ft.getQueryEnv().addLocation(GeoLocationSpec{attr, p}); if (maxDistance > 0) { ft.getIndexEnv().getProperties().add(feature + ".maxDistance", vespalib::make_string("%u", (unsigned int)maxDistance)); @@ -857,13 +859,16 @@ Test::testDistance() { // non-existing attribute FtFeatureTest ft(_factory, "distance(pos)"); ft.getIndexEnv().getBuilder().addField(FieldType::ATTRIBUTE, CollectionType::SINGLE, DataType::INT64, "pos"); - ft.getQueryEnv().getLocation().setValid(true); + GeoLocation::Point p{0, 0}; + ft.getQueryEnv().addLocation(GeoLocationSpec{"pos", p}); + ASSERT_TRUE(ft.setup()); ASSERT_TRUE(ft.execute(RankResult().addScore("distance(pos)", 6400000000.0))); } { // label FtFeatureTest ft(_factory, "distance(label,foo)"); - ft.getQueryEnv().getLocation().setValid(true); + GeoLocation::Point p{0, 0}; + ft.getQueryEnv().addLocation(GeoLocationSpec{"pos", p}); ASSERT_TRUE(ft.setup()); ASSERT_TRUE(ft.execute(RankResult().addScore("distance(label,foo)", std::numeric_limits<feature_t>::max()))); } @@ -873,7 +878,8 @@ Test::testDistance() pos->commit(); ft.getIndexEnv().getAttributeMap().add(pos); ft.getIndexEnv().getBuilder().addField(FieldType::ATTRIBUTE, CollectionType::SINGLE, DataType::INT64, "pos"); - ft.getQueryEnv().getLocation().setValid(true); + GeoLocation::Point p{0, 0}; + ft.getQueryEnv().addLocation(GeoLocationSpec{"pos", p}); ASSERT_TRUE(ft.setup()); ASSERT_TRUE(ft.execute(RankResult().addScore("distance(pos)", 6400000000.0))); } @@ -883,7 +889,8 @@ Test::testDistance() pos->commit(); ft.getIndexEnv().getAttributeMap().add(pos); ft.getIndexEnv().getBuilder().addField(FieldType::ATTRIBUTE, CollectionType::SINGLE, DataType::INT64, "pos"); - ft.getQueryEnv().getLocation().setValid(true); + GeoLocation::Point p{0, 0}; + ft.getQueryEnv().addLocation(GeoLocationSpec{"pos", p}); ASSERT_TRUE(ft.setup()); ASSERT_TRUE(ft.execute(RankResult().addScore("distance(pos)", 6400000000.0))); } @@ -893,7 +900,8 @@ Test::testDistance() pos->commit(); ft.getIndexEnv().getAttributeMap().add(pos); ft.getIndexEnv().getBuilder().addField(FieldType::ATTRIBUTE, CollectionType::WEIGHTEDSET, DataType::INT64, "pos"); - ft.getQueryEnv().getLocation().setValid(true); + GeoLocation::Point p{0, 0}; + ft.getQueryEnv().addLocation(GeoLocationSpec{"pos", p}); ASSERT_TRUE(ft.setup()); ASSERT_TRUE(ft.execute(RankResult().addScore("distance(pos)", 6400000000.0))); } @@ -939,10 +947,9 @@ Test::assert2DZDistance(feature_t exp, const vespalib::string & positions, pos.emplace_back(x, y); } setupForDistanceTest(ft, "pos", pos, true); - ft.getQueryEnv().getLocation().setXPosition(xquery); - ft.getQueryEnv().getLocation().setYPosition(yquery); - ft.getQueryEnv().getLocation().setXAspect(xAspect); - ft.getQueryEnv().getLocation().setValid(true); + GeoLocation::Point p{xquery, yquery}; + GeoLocation::Aspect aspect{xAspect}; + ft.getQueryEnv().addLocation(GeoLocationSpec{"pos", {p, aspect}}); ASSERT_TRUE(ft.setup()); ASSERT_TRUE(ft.execute(RankResult().setEpsilon(1e-4). addScore("distance(pos)", exp))); diff --git a/searchlib/src/vespa/searchlib/features/distancefeature.cpp b/searchlib/src/vespa/searchlib/features/distancefeature.cpp index bd2c7becc81..6582bcae92a 100644 --- a/searchlib/src/vespa/searchlib/features/distancefeature.cpp +++ b/searchlib/src/vespa/searchlib/features/distancefeature.cpp @@ -2,7 +2,7 @@ #include "distancefeature.h" #include <vespa/searchcommon/common/schema.h> -#include <vespa/searchlib/fef/location.h> +#include <vespa/searchlib/common/geo_location_spec.h> #include <vespa/searchlib/fef/matchdata.h> #include <vespa/document/datatype/positiondatatype.h> #include <vespa/vespalib/geo/zcurve.h> @@ -100,19 +100,10 @@ DistanceExecutor::calculate2DZDistance(uint32_t docId) int32_t docy = 0; for (auto loc : _locations) { assert(loc); - assert(loc->isValid()); - int32_t loc_x = loc->getXPosition(); - int32_t loc_y = loc->getYPosition(); - uint64_t loc_a = loc->getXAspect(); - LOG(debug, "location: x=%u, y=%u, aspect=%zu", loc_x, loc_y, loc_a); + assert(loc->location.valid()); for (uint32_t i = 0; i < numValues; ++i) { vespalib::geo::ZCurve::decode(_intBuf[i], &docx, &docy); - uint32_t dx = (loc_x > docx) ? (loc_x - docx) : (docx - loc_x); - if (loc_a != 0) { - dx = (uint64_t(dx) * loc_a) >> 32; - } - uint32_t dy = (loc_y > docy) ? (loc_y - docy) : (docy - loc_y); - uint64_t sqdist = (uint64_t) dx * dx + (uint64_t) dy * dy; + uint64_t sqdist = loc->location.sq_distance_to({docx, docy}); if (sqdist < sqabsdist) { sqabsdist = sqdist; } @@ -121,7 +112,7 @@ DistanceExecutor::calculate2DZDistance(uint32_t docId) return static_cast<feature_t>(std::sqrt(static_cast<feature_t>(sqabsdist))); } -DistanceExecutor::DistanceExecutor(std::vector<const Location *> locations, +DistanceExecutor::DistanceExecutor(GeoLocationSpecPtrs locations, const search::attribute::IAttributeVector * pos) : FeatureExecutor(), _locations(locations), @@ -253,17 +244,17 @@ DistanceBlueprint::createExecutor(const IQueryEnvironment &env, vespalib::Stash } // expect geo pos: const search::attribute::IAttributeVector * pos = nullptr; - std::vector<const search::fef::Location *> matching_locs; - std::vector<const search::fef::Location *> other_locs; + GeoLocationSpecPtrs matching_locs; + GeoLocationSpecPtrs other_locs; for (auto loc_ptr : env.getAllLocations()) { - if (_use_geo_pos && loc_ptr && loc_ptr->isValid()) { - if (loc_ptr->getAttribute() == _arg_string) { + if (_use_geo_pos && loc_ptr && loc_ptr->location.valid()) { + if (loc_ptr->field_name == _arg_string) { LOG(debug, "found loc from query env matching '%s'", _arg_string.c_str()); matching_locs.push_back(loc_ptr); } else { LOG(debug, "found loc(%s) from query env not matching arg(%s)", - loc_ptr->getAttribute().c_str(), _arg_string.c_str()); + loc_ptr->field_name.c_str(), _arg_string.c_str()); other_locs.push_back(loc_ptr); } } diff --git a/searchlib/src/vespa/searchlib/features/distancefeature.h b/searchlib/src/vespa/searchlib/features/distancefeature.h index 024b9f37f31..ece139c6546 100644 --- a/searchlib/src/vespa/searchlib/features/distancefeature.h +++ b/searchlib/src/vespa/searchlib/features/distancefeature.h @@ -7,12 +7,15 @@ namespace search::features { +/** Convenience typedef. */ +using GeoLocationSpecPtrs = std::vector<const search::common::GeoLocationSpec *>; + /** * Implements the executor for the distance feature. */ class DistanceExecutor : public fef::FeatureExecutor { private: - std::vector<const fef::Location *> _locations; + GeoLocationSpecPtrs _locations; const attribute::IAttributeVector * _pos; attribute::IntegerContent _intBuf; @@ -26,7 +29,7 @@ public: * @param locations location objects associated with the query environment. * @param pos the attribute to use for positions (expects zcurve encoding). */ - DistanceExecutor(std::vector<const fef::Location *> locations, + DistanceExecutor(GeoLocationSpecPtrs locations, const attribute::IAttributeVector * pos); void execute(uint32_t docId) override; diff --git a/searchlib/src/vespa/searchlib/fef/CMakeLists.txt b/searchlib/src/vespa/searchlib/fef/CMakeLists.txt index 396775b20c5..178de1b8b87 100644 --- a/searchlib/src/vespa/searchlib/fef/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/fef/CMakeLists.txt @@ -16,7 +16,6 @@ vespa_add_library(searchlib_fef OBJECT filetablefactory.cpp functiontablefactory.cpp indexproperties.cpp - location.cpp matchdata.cpp matchdatalayout.cpp objectstore.cpp diff --git a/searchlib/src/vespa/searchlib/fef/fef.h b/searchlib/src/vespa/searchlib/fef/fef.h index 7dd24bd17ae..b677ba128c9 100644 --- a/searchlib/src/vespa/searchlib/fef/fef.h +++ b/searchlib/src/vespa/searchlib/fef/fef.h @@ -35,7 +35,6 @@ #include "itablemanager.h" #include "itermdata.h" #include "itermfielddata.h" -#include "location.h" #include "matchdata.h" #include "matchdatalayout.h" #include "parameter.h" diff --git a/searchlib/src/vespa/searchlib/fef/iqueryenvironment.h b/searchlib/src/vespa/searchlib/fef/iqueryenvironment.h index 811e7fd4616..7c6a84916f4 100644 --- a/searchlib/src/vespa/searchlib/fef/iqueryenvironment.h +++ b/searchlib/src/vespa/searchlib/fef/iqueryenvironment.h @@ -6,9 +6,10 @@ #include "objectstore.h" #include <vespa/searchcommon/attribute/iattributecontext.h> +namespace search::common { class GeoLocationSpec; } + namespace search::fef { -class Location; class Properties; class ITermData; @@ -24,6 +25,9 @@ public: **/ typedef std::shared_ptr<IQueryEnvironment> SP; + /** Convenience typedef. */ + using GeoLocationSpecPtrs = std::vector<const search::common::GeoLocationSpec *>; + /** * Obtain the set of properties associated with this query * environment. This set of properties is known through the system @@ -60,7 +64,7 @@ public: * * @return pointers to location objects. **/ - virtual std::vector<const Location *> getAllLocations() const = 0; + virtual GeoLocationSpecPtrs getAllLocations() const = 0; /** * Returns the attribute context for this query. diff --git a/searchlib/src/vespa/searchlib/fef/location.cpp b/searchlib/src/vespa/searchlib/fef/location.cpp deleted file mode 100644 index 978daa0f930..00000000000 --- a/searchlib/src/vespa/searchlib/fef/location.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "location.h" - -namespace search { -namespace fef { - -Location::Location() : - _attr(), - _xPos(0), - _yPos(0), - _xAspect(0), - _valid(false) -{ -} - -} // namespace fef -} // namespace search diff --git a/searchlib/src/vespa/searchlib/fef/location.h b/searchlib/src/vespa/searchlib/fef/location.h deleted file mode 100644 index 3bc693e11b4..00000000000 --- a/searchlib/src/vespa/searchlib/fef/location.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include <vespa/vespalib/stllike/string.h> - -namespace search { -namespace fef { - -/** - * This class contains location data that is associated with a query. - **/ -class Location -{ -private: - vespalib::string _attr; - int32_t _xPos; - int32_t _yPos; - uint32_t _xAspect; - bool _valid; - -public: - /** - * Creates an empty object. - **/ - Location(); - - /** - * Sets the name of the attribute to use for x positions. - * - * @param xAttr the attribute name. - * @return this to allow chaining. - **/ - Location & - setAttribute(const vespalib::string & attr) - { - _attr = attr; - return *this; - } - - /** - * Returns the name of the attribute to use for positions. - * - * @return the attribute name. - **/ - const vespalib::string & getAttribute() const { return _attr; } - - /** - * Sets the x position of this location. - * - * @param xPos the x position. - * @return this to allow chaining. - **/ - Location & setXPosition(int32_t xPos) { _xPos = xPos; return *this; } - - /** - * Returns the x position of this location. - * - * @return the x position. - **/ - int32_t getXPosition() const { return _xPos; } - - /** - * Sets the y position of this location. - * - * @param yPos the y position. - * @return this to allow chaining. - **/ - Location & setYPosition(int32_t yPos) { _yPos = yPos; return *this; } - - /** - * Returns the y position of this location. - * - * @return the y position. - **/ - int32_t getYPosition() const { return _yPos; } - - /** - * Sets the x distance multiplier fraction. - * - * @param xAspect the x aspect. - * @return this to allow chaining. - **/ - Location & setXAspect(uint32_t xAspect) { _xAspect = xAspect; return *this; } - - /** - * Returns the x distance multiplier fraction. - * - * @return the x aspect. - **/ - uint32_t getXAspect() const { return _xAspect; } - - /** - * Sets whether this is a valid location object. - * - * @param valid true if this is valid. - * @return this to allow chaining. - **/ - Location & setValid(bool valid) { _valid = valid; return *this; } - - /** - * Returns whether this is a valid location object. - * - * @param true if this is a valid. - **/ - bool isValid() const { return _valid; } -}; - -} // namespace fef -} // namespace search - diff --git a/searchlib/src/vespa/searchlib/fef/phrase_splitter_query_env.h b/searchlib/src/vespa/searchlib/fef/phrase_splitter_query_env.h index 3a8cde99c06..90bf4e8955f 100644 --- a/searchlib/src/vespa/searchlib/fef/phrase_splitter_query_env.h +++ b/searchlib/src/vespa/searchlib/fef/phrase_splitter_query_env.h @@ -73,7 +73,7 @@ public: } const Properties & getProperties() const override { return _queryEnv.getProperties(); } - std::vector<const Location *> getAllLocations() const override { + GeoLocationSpecPtrs getAllLocations() const override { return _queryEnv.getAllLocations(); } const attribute::IAttributeContext & getAttributeContext() const override { return _queryEnv.getAttributeContext(); } diff --git a/searchlib/src/vespa/searchlib/fef/test/queryenvironment.cpp b/searchlib/src/vespa/searchlib/fef/test/queryenvironment.cpp index 4697675c071..d602e74ddfb 100644 --- a/searchlib/src/vespa/searchlib/fef/test/queryenvironment.cpp +++ b/searchlib/src/vespa/searchlib/fef/test/queryenvironment.cpp @@ -8,7 +8,7 @@ QueryEnvironment::QueryEnvironment(IndexEnvironment *env) : _indexEnv(env), _terms(), _properties(), - _location(), + _locations(), _attrCtx((env == nullptr) ? attribute::IAttributeContext::UP() : env->getAttributeMap().createContext()) { } diff --git a/searchlib/src/vespa/searchlib/fef/test/queryenvironment.h b/searchlib/src/vespa/searchlib/fef/test/queryenvironment.h index 4b9bec1ee68..d8d5c802360 100644 --- a/searchlib/src/vespa/searchlib/fef/test/queryenvironment.h +++ b/searchlib/src/vespa/searchlib/fef/test/queryenvironment.h @@ -4,12 +4,14 @@ #include "indexenvironment.h" #include <vespa/searchcommon/attribute/iattributecontext.h> #include <vespa/searchlib/fef/iqueryenvironment.h> -#include <vespa/searchlib/fef/location.h> #include <vespa/searchlib/fef/simpletermdata.h> +#include <vespa/searchlib/common/geo_location_spec.h> #include <unordered_map> namespace search::fef::test { +using search::common::GeoLocationSpec; + /** * Implementation of the IQueryEnvironment interface used for testing. */ @@ -22,7 +24,7 @@ private: IndexEnvironment *_indexEnv; std::vector<SimpleTermData> _terms; Properties _properties; - Location _location; + std::vector<GeoLocationSpec> _locations; search::attribute::IAttributeContext::UP _attrCtx; std::unordered_map<std::string, double> _avg_field_lengths; @@ -38,10 +40,12 @@ public: const Properties &getProperties() const override { return _properties; } uint32_t getNumTerms() const override { return _terms.size(); } const ITermData *getTerm(uint32_t idx) const override { return idx < _terms.size() ? &_terms[idx] : NULL; } - std::vector<const Location *> getAllLocations() const override { - std::vector<const Location *> retval; - retval.push_back(&_location); - return retval; + GeoLocationSpecPtrs getAllLocations() const override { + GeoLocationSpecPtrs locations; + for (const auto & loc : _locations) { + locations.push_back(&loc); + } + return locations; } const search::attribute::IAttributeContext &getAttributeContext() const override { return *_attrCtx; } double get_average_field_length(const vespalib::string& field_name) const override { @@ -86,7 +90,7 @@ public: Properties & getProperties() { return _properties; } /** Returns a reference to the location of this. */ - Location & getLocation() { return _location; } + void addLocation(const GeoLocationSpec &spec) { _locations.push_back(spec); } std::unordered_map<std::string, double>& get_avg_field_lengths() { return _avg_field_lengths; } }; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp index 42afadb386a..1f9b553b56a 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp @@ -15,6 +15,9 @@ #include <vespa/log/log.h> LOG_SETUP(".searchsummary.docsummary.docsumstate"); +using search::common::GeoLocationParser; +using search::common::GeoLocationSpec; + namespace search::docsummary { GetDocsumsState::GetDocsumsState(GetDocsumsStateCallback &callback) @@ -72,11 +75,11 @@ GetDocsumsState::parse_locations() using document::PositionDataType; assert(_parsedLocations.empty()); // only allowed to call this once if (! _args.getLocation().empty()) { - search::common::GeoLocationParser parser; + GeoLocationParser parser; if (parser.parseOldFormatWithField(_args.getLocation())) { auto view = parser.getFieldName(); auto attr_name = PositionDataType::getZCurveFieldName(view); - search::common::GeoLocationSpec spec{attr_name, parser.getGeoLocation()}; + GeoLocationSpec spec{attr_name, parser.getGeoLocation()}; _parsedLocations.push_back(spec); } else { LOG(warning, "could not parse location string '%s' from request", @@ -90,10 +93,10 @@ GetDocsumsState::parse_locations() if (iterator.getType() == search::ParseItem::ITEM_GEO_LOCATION_TERM) { vespalib::string view = iterator.getIndexName(); vespalib::string term = iterator.getTerm(); - search::common::GeoLocationParser parser; + GeoLocationParser parser; if (parser.parseOldFormat(term)) { auto attr_name = PositionDataType::getZCurveFieldName(view); - search::common::GeoLocationSpec spec{attr_name, parser.getGeoLocation()}; + GeoLocationSpec spec{attr_name, parser.getGeoLocation()}; _parsedLocations.push_back(spec); } else { LOG(warning, "could not parse location string '%s' from stack dump", diff --git a/streamingvisitors/src/vespa/searchvisitor/queryenvironment.cpp b/streamingvisitors/src/vespa/searchvisitor/queryenvironment.cpp index 6096a2faea4..06bdb9f69bb 100644 --- a/streamingvisitors/src/vespa/searchvisitor/queryenvironment.cpp +++ b/streamingvisitors/src/vespa/searchvisitor/queryenvironment.cpp @@ -9,6 +9,8 @@ LOG_SETUP(".searchvisitor.queryenvironment"); using search::IAttributeManager; +using search::common::GeoLocationParser; +using search::common::GeoLocationSpec; using search::fef::Properties; using vespalib::string; @@ -16,28 +18,24 @@ namespace streaming { namespace { -search::fef::Location +std::vector<GeoLocationSpec> parseLocation(const string & location_str) { - search::fef::Location fefLocation; + std::vector<GeoLocationSpec> fefLocations; if (location_str.empty()) { - return fefLocation; + return fefLocations; } - search::common::GeoLocationParser locationParser; + GeoLocationParser locationParser; if (!locationParser.parseOldFormatWithField(location_str)) { LOG(warning, "Location parse error (location: '%s'): %s. Location ignored.", location_str.c_str(), locationParser.getParseError()); - return fefLocation; + return fefLocations; } - auto location = locationParser.getGeoLocation(); - if (location.has_point) { - fefLocation.setAttribute(locationParser.getFieldName()); - fefLocation.setXPosition(location.point.x); - fefLocation.setYPosition(location.point.y); - fefLocation.setXAspect(location.x_aspect.multiplier); - fefLocation.setValid(true); + auto loc = locationParser.getGeoLocation(); + if (loc.has_point) { + fefLocations.push_back(GeoLocationSpec{locationParser.getFieldName(), loc}); } - return fefLocation; + return fefLocations; } } @@ -50,7 +48,7 @@ QueryEnvironment::QueryEnvironment(const string & location_str, _properties(properties), _attrCtx(attrMgr->createContext()), _queryTerms(), - _location(parseLocation(location_str)) + _locations(parseLocation(location_str)) { } diff --git a/streamingvisitors/src/vespa/searchvisitor/queryenvironment.h b/streamingvisitors/src/vespa/searchvisitor/queryenvironment.h index e3da5a44167..df354d578e6 100644 --- a/streamingvisitors/src/vespa/searchvisitor/queryenvironment.h +++ b/streamingvisitors/src/vespa/searchvisitor/queryenvironment.h @@ -6,7 +6,6 @@ #include <vespa/searchlib/attribute/iattributemanager.h> #include <vespa/searchlib/fef/iindexenvironment.h> #include <vespa/searchlib/fef/iqueryenvironment.h> -#include <vespa/searchlib/fef/location.h> #include <vespa/searchlib/fef/properties.h> #include "indexenvironment.h" @@ -23,7 +22,7 @@ private: const search::fef::Properties &_properties; search::attribute::IAttributeContext::UP _attrCtx; std::vector<const search::fef::ITermData *> _queryTerms; - search::fef::Location _location; + std::vector<search::common::GeoLocationSpec> _locations; public: typedef std::unique_ptr<QueryEnvironment> UP; @@ -49,10 +48,10 @@ public: } // inherit documentation - std::vector<const search::fef::Location *> getAllLocations() const override { - std::vector<const search::fef::Location *> retval; - if (_location.isValid()) { - retval.push_back(&_location); + GeoLocationSpecPtrs getAllLocations() const override { + GeoLocationSpecPtrs retval; + for (const auto & loc : _locations) { + retval.push_back(&loc); } return retval; } |