From 9534d9ef4d74017ff4ef0849924f751403979cbb Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Tue, 14 Jul 2020 06:42:52 +0000 Subject: finish rewrite to use GeoLocation --- .../proton/matching/termdataextractor_test.cpp | 2 +- .../src/vespa/searchcore/proton/matching/query.cpp | 62 ++++++++++------------ 2 files changed, 28 insertions(+), 36 deletions(-) (limited to 'searchcore') diff --git a/searchcore/src/tests/proton/matching/termdataextractor_test.cpp b/searchcore/src/tests/proton/matching/termdataextractor_test.cpp index 2570e64dbe2..36c34e38a04 100644 --- a/searchcore/src/tests/proton/matching/termdataextractor_test.cpp +++ b/searchcore/src/tests/proton/matching/termdataextractor_test.cpp @@ -83,7 +83,7 @@ Node::UP getQuery(const ViewResolver &resolver) query_builder.addStringTerm("bar", field, id[3], Weight(0)); } - query_builder.addLocationTerm(Location(Point(10, 10), 3, 0), + query_builder.addLocationTerm(Location(Point{10, 10}, 3, 0), field, id[7], Weight(0)); Node::UP node = query_builder.build(); diff --git a/searchcore/src/vespa/searchcore/proton/matching/query.cpp b/searchcore/src/vespa/searchcore/proton/matching/query.cpp index 6909f098481..42d663c169d 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/query.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/query.cpp @@ -9,6 +9,7 @@ #include "unpacking_iterators_optimizer.h" #include #include +#include #include #include @@ -18,6 +19,7 @@ LOG_SETUP(".proton.matching.query"); using document::PositionDataType; using search::SimpleQueryStackDumpIterator; +using search::common::GeoLocationSpec; using search::fef::IIndexEnvironment; using search::fef::ITermData; using search::fef::MatchData; @@ -75,65 +77,55 @@ fix_location_terms(Node *tree) { return retval; } -struct ParsedLocationString { - bool valid; - string view; - search::common::GeoLocationSpec locationSpec; - ParsedLocationString() : valid(false), view(), locationSpec() {} - ~ParsedLocationString() {} -}; - -ParsedLocationString parseQueryLocationString(string str) { - ParsedLocationString retval; +GeoLocationSpec parseQueryLocationString(string str) { + GeoLocationSpec empty; if (str.empty()) { - return retval; + return empty; } - search::common::GeoLocationParser locationParser; - if (locationParser.parseOldFormatWithField(str)) { - auto spec = locationParser.spec(); - retval.locationSpec = spec; - retval.view = PositionDataType::getZCurveFieldName(spec.getFieldName()); - retval.valid = true; + search::common::GeoLocationParser parser; + if (parser.parseOldFormatWithField(str)) { + auto attr_name = PositionDataType::getZCurveFieldName(parser.getFieldName()); + return GeoLocationSpec{attr_name, parser.getGeoLocation()}; } else { - LOG(warning, "Location parse error (location: '%s'): %s", str.c_str(), locationParser.getParseError()); + LOG(warning, "Location parse error (location: '%s'): %s", str.c_str(), parser.getParseError()); } - return retval; + return empty; } void exchangeLocationNodes(const string &location_str, Node::UP &query_tree, std::vector &fef_locations) { - using Spec = std::pair; - std::vector locationSpecs; + std::vector locationSpecs; auto parsed = parseQueryLocationString(location_str); - if (parsed.valid) { - locationSpecs.emplace_back(parsed.view, parsed.locationSpec); + if (parsed.location.valid()) { + locationSpecs.emplace_back(parsed); } for (const ProtonLocationTerm * pterm : fix_location_terms(query_tree.get())) { - const string view = pterm->getView(); - auto loc = pterm->getTerm(); - if (loc.isValid()) { - locationSpecs.emplace_back(view, loc); + std::string view = pterm->getView(); + search::common::GeoLocation loc = pterm->getTerm(); + if (loc.valid()) { + search::common::GeoLocationSpec spec{view, loc}; + locationSpecs.push_back(spec); } } - for (const Spec &spec : locationSpecs) { - if (spec.second.hasPoint()) { + for (const GeoLocationSpec &spec : locationSpecs) { + if (spec.location.has_point) { search::fef::Location fef_loc; - fef_loc.setAttribute(spec.first); - fef_loc.setXPosition(spec.second.getX()); - fef_loc.setYPosition(spec.second.getY()); - fef_loc.setXAspect(spec.second.getXAspect()); + 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); } } - if (parsed.valid) { + if (parsed.location.can_limit()) { int32_t id = -1; Weight weight(100); query_tree = inject(std::move(query_tree), - std::make_unique(parsed.locationSpec, parsed.view, id, weight)); + std::make_unique(parsed.location, parsed.field_name, id, weight)); } } -- cgit v1.2.3