summaryrefslogtreecommitdiffstats
path: root/streamingvisitors
diff options
context:
space:
mode:
authorArne H Juul <arnej@yahooinc.com>2022-01-28 13:47:27 +0000
committerArne H Juul <arnej@yahooinc.com>2022-01-28 13:47:48 +0000
commit36e390ed82d54aaee95133e5dccd460e915e544e (patch)
tree2e4078b43a1ff2422f985da327e5be73b67bf500 /streamingvisitors
parent5d45925095457bd71b3b4416ff4942fcddd77780 (diff)
extract geo positions from query terms
* put them into query environment (for ranking)
Diffstat (limited to 'streamingvisitors')
-rw-r--r--streamingvisitors/src/vespa/searchvisitor/queryenvironment.cpp13
-rw-r--r--streamingvisitors/src/vespa/searchvisitor/queryenvironment.h2
-rw-r--r--streamingvisitors/src/vespa/searchvisitor/querywrapper.h1
-rw-r--r--streamingvisitors/src/vespa/searchvisitor/rankprocessor.cpp5
4 files changed, 21 insertions, 0 deletions
diff --git a/streamingvisitors/src/vespa/searchvisitor/queryenvironment.cpp b/streamingvisitors/src/vespa/searchvisitor/queryenvironment.cpp
index 076b847b32e..0765074e315 100644
--- a/streamingvisitors/src/vespa/searchvisitor/queryenvironment.cpp
+++ b/streamingvisitors/src/vespa/searchvisitor/queryenvironment.cpp
@@ -54,6 +54,19 @@ QueryEnvironment::QueryEnvironment(const string & location_str,
QueryEnvironment::~QueryEnvironment() {}
+void QueryEnvironment::addGeoLocation(const vespalib::string &field, const vespalib::string &location_str) {
+ GeoLocationParser locationParser;
+ if (! locationParser.parseNoField(location_str)) {
+ LOG(warning, "Location parse error (location: '%s'): %s. Location ignored.",
+ location_str.c_str(), locationParser.getParseError());
+ return;
+ }
+ auto loc = locationParser.getGeoLocation();
+ if (loc.has_point) {
+ _locations.push_back(GeoLocationSpec{field, loc});
+ }
+}
+
QueryEnvironment::GeoLocationSpecPtrs
QueryEnvironment::getAllLocations() const
{
diff --git a/streamingvisitors/src/vespa/searchvisitor/queryenvironment.h b/streamingvisitors/src/vespa/searchvisitor/queryenvironment.h
index a61cdc5ae58..1bc625f4ea3 100644
--- a/streamingvisitors/src/vespa/searchvisitor/queryenvironment.h
+++ b/streamingvisitors/src/vespa/searchvisitor/queryenvironment.h
@@ -33,6 +33,8 @@ public:
const search::IAttributeManager * attrMgr = nullptr);
~QueryEnvironment();
+ void addGeoLocation(const vespalib::string &field, const vespalib::string &location);
+
// inherit documentation
virtual const search::fef::Properties & getProperties() const override { return _properties; }
diff --git a/streamingvisitors/src/vespa/searchvisitor/querywrapper.h b/streamingvisitors/src/vespa/searchvisitor/querywrapper.h
index 5a277a12318..90343085298 100644
--- a/streamingvisitors/src/vespa/searchvisitor/querywrapper.h
+++ b/streamingvisitors/src/vespa/searchvisitor/querywrapper.h
@@ -47,6 +47,7 @@ public:
bool isPhraseTerm() const { return _parent != nullptr; }
bool isFirstPhraseTerm() const { return isPhraseTerm() && getIndex() == 0; }
size_t getPosAdjust() const { return _parent != nullptr ? _parent->width() - 1 : 0; }
+ bool isGeoPosTerm() const { return (_term != nullptr) && _term->isGeoLoc(); }
};
typedef std::vector<Term> TermList;
diff --git a/streamingvisitors/src/vespa/searchvisitor/rankprocessor.cpp b/streamingvisitors/src/vespa/searchvisitor/rankprocessor.cpp
index ac74f7791db..73baa1de45f 100644
--- a/streamingvisitors/src/vespa/searchvisitor/rankprocessor.cpp
+++ b/streamingvisitors/src/vespa/searchvisitor/rankprocessor.cpp
@@ -56,6 +56,11 @@ RankProcessor::initQueryEnvironment()
QueryWrapper::TermList & terms = _query.getTermList();
for (uint32_t i = 0; i < terms.size(); ++i) {
+ if (terms[i].isGeoPosTerm()) {
+ const vespalib::string & fieldName = terms[i].getTerm()->index();
+ const vespalib::string & locStr = terms[i].getTerm()->getTermString();
+ _queryEnv.addGeoLocation(fieldName, locStr);
+ }
if (!terms[i].isPhraseTerm() || terms[i].isFirstPhraseTerm()) { // register 1 term data per phrase
QueryTermData & qtd = dynamic_cast<QueryTermData &>(terms[i].getTerm()->getQueryItem());