summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-09-10 16:47:04 +0200
committerGitHub <noreply@github.com>2022-09-10 16:47:04 +0200
commit9aa1fd9329c9bf0fd47c893483c761381bbe383f (patch)
treee659a31fd70e52ec8006325db49afba933a87384
parent17ed5acbf5c03be795dd1700f5afbf3cbcac0aa0 (diff)
parent6606938ef28082ca9211b680d49af8eff0af95e5 (diff)
Merge pull request #24003 from vespa-engine/toregge/avoid-multiple-definitions-of-juniper-queryitem
Avoid multiple definitions of juniper::QueryItem.
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/Item.java2
-rw-r--r--searchlib/src/vespa/searchlib/parsequery/item_creator.h20
-rw-r--r--searchlib/src/vespa/searchlib/parsequery/parse.h12
-rw-r--r--searchsummary/src/tests/juniper/queryvisitor_test.cpp25
-rw-r--r--searchsummary/src/vespa/juniper/query.h25
-rw-r--r--searchsummary/src/vespa/juniper/query_item.h24
-rw-r--r--searchsummary/src/vespa/juniper/querymodifier.cpp10
-rw-r--r--searchsummary/src/vespa/juniper/querymodifier.h4
-rw-r--r--searchsummary/src/vespa/juniper/queryparser.cpp123
-rw-r--r--searchsummary/src/vespa/juniper/queryparser.h20
-rw-r--r--searchsummary/src/vespa/juniper/queryvisitor.cpp27
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/dynamicteaserdfw.cpp111
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/keywordextractor.cpp2
13 files changed, 205 insertions, 200 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/Item.java b/container-search/src/main/java/com/yahoo/prelude/query/Item.java
index 02b208b6ce1..c1397ca9d4b 100644
--- a/container-search/src/main/java/com/yahoo/prelude/query/Item.java
+++ b/container-search/src/main/java/com/yahoo/prelude/query/Item.java
@@ -67,7 +67,7 @@ public abstract class Item implements Cloneable {
}
- // These must match the definitions in searchlib/src/searchlib/parsequery/parse.h
+ // These must match the definitions in searchlib/src/vespa/searchlib/parsequery/item_creator.h
public enum ItemCreator {
ORIG(0),
diff --git a/searchlib/src/vespa/searchlib/parsequery/item_creator.h b/searchlib/src/vespa/searchlib/parsequery/item_creator.h
new file mode 100644
index 00000000000..99d8722ea95
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/parsequery/item_creator.h
@@ -0,0 +1,20 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+namespace search::parseitem {
+
+/** A tag identifying the origin of a query node.
+ * Note that descendants may originate from elsewhere.
+ * Used in search::ParseItem and in Juniper.
+ * If changes necessary:
+ * NB! Append at end of list - corresponding type used in search
+ * container and updates of these two types must be synchronized.
+ * (container-search/src/main/java/com/yahoo/prelude/query/Item.java)
+ */
+enum class ItemCreator {
+ CREA_ORIG = 0, // Original user query
+ CREA_FILTER // Automatically applied filter (no specific type)
+};
+
+}
diff --git a/searchlib/src/vespa/searchlib/parsequery/parse.h b/searchlib/src/vespa/searchlib/parsequery/parse.h
index 1285125d34b..d7a04280738 100644
--- a/searchlib/src/vespa/searchlib/parsequery/parse.h
+++ b/searchlib/src/vespa/searchlib/parsequery/parse.h
@@ -2,6 +2,7 @@
#pragma once
+#include "item_creator.h"
#include <vespa/searchlib/query/weight.h>
#include <vespa/vespalib/stllike/string.h>
@@ -23,7 +24,7 @@ class ParseItem
{
public:
/** The type of the item is from this set of values.
- It is important that these defines match those in prelude/source/com/yahoo/prelude/query/Item.java */
+ It is important that these defines match those in container-search/src/main/java/com/yahoo/prelude/query/Item.java */
enum ItemType {
ITEM_OR = 0,
ITEM_AND = 1,
@@ -62,15 +63,8 @@ public:
};
/** A tag identifying the origin of this query node.
- * Note that descendants may originate from elsewhere.
- * If changes necessary:
- * NB! Append at end of list - corresponding type
- * used in Juniper and updates of these two types must be synchronized.
- * (juniper/src/query.h)
*/
- enum ItemCreator {
- CREA_ORIG = 0 // Original user query
- };
+ using ItemCreator = parseitem::ItemCreator;
enum ItemFeatures {
IF_WEIGHT = 0x20, // item has rank weight
diff --git a/searchsummary/src/tests/juniper/queryvisitor_test.cpp b/searchsummary/src/tests/juniper/queryvisitor_test.cpp
index 0b99bf6583c..abb14dc1b16 100644
--- a/searchsummary/src/tests/juniper/queryvisitor_test.cpp
+++ b/searchsummary/src/tests/juniper/queryvisitor_test.cpp
@@ -4,10 +4,23 @@
#include <vespa/juniper/queryhandle.h>
#include <vespa/juniper/queryvisitor.h>
+#include <vespa/juniper/query_item.h>
#include <vespa/vespalib/stllike/string.h>
using namespace juniper;
+struct MyQueryItem : public QueryItem
+{
+ MyQueryItem()
+ : QueryItem()
+ { }
+ ~MyQueryItem() override = default;
+
+ vespalib::stringref get_index() const override { return {}; }
+ int get_weight() const override { return 0; }
+ ItemCreator get_creator() const override { return ItemCreator::CREA_ORIG; }
+};
+
class MyQuery : public juniper::IQuery
{
private:
@@ -17,18 +30,10 @@ public:
MyQuery(const vespalib::string &term) : _term(term) {}
virtual bool Traverse(IQueryVisitor* v) const override {
- v->VisitKeyword(nullptr, _term.c_str(), _term.size());
+ MyQueryItem item;
+ v->VisitKeyword(&item, _term.c_str(), _term.size());
return true;
}
- virtual int Weight(const QueryItem*) const override {
- return 0;
- }
- virtual ItemCreator Creator(const QueryItem*) const override {
- return ItemCreator::CREA_ORIG;
- }
- virtual const char* Index(const QueryItem*, size_t*) const override {
- return "my_index";
- }
virtual bool UsefulIndex(const QueryItem*) const override {
return true;
}
diff --git a/searchsummary/src/vespa/juniper/query.h b/searchsummary/src/vespa/juniper/query.h
index 8208b234d6b..2b45909e0ac 100644
--- a/searchsummary/src/vespa/juniper/query.h
+++ b/searchsummary/src/vespa/juniper/query.h
@@ -2,6 +2,7 @@
#pragma once
+#include <vespa/searchlib/parsequery/item_creator.h>
#include <cstddef>
#include <cstdint>
@@ -27,12 +28,7 @@
namespace juniper {
-enum ItemCreator
-{
- CREA_ORIG = 0, // Original user query
- CREA_FILTER // Automatically applied filter (no specific type)
-};
-
+using ItemCreator = search::parseitem::ItemCreator;
// For debugging purposes: return a text string with the creator enum name
const char* creator_text(ItemCreator);
@@ -56,23 +52,6 @@ public:
*/
virtual bool Traverse(IQueryVisitor* v) const = 0;
- /** @param item A query item to check
- * @return A weight assigned to this term (default 100 (%) )
- */
- virtual int Weight(const QueryItem* item) const = 0;
-
- /** @param item A query item to check
- * @return The creator module associated with this term
- */
- virtual ItemCreator Creator(const QueryItem* item) const = 0;
-
- /** Return a text string representing any index specification used for this term
- * @param item A query item to check
- * @param length the length of the returned string
- * @return A text containing the name of the index associated with this term
- */
- virtual const char* Index(const QueryItem* item, size_t* length) const = 0;
-
/** Check if the index specification associated with the query item is useful from
* a Juniper perspective (see fsearchrc, highlightindexes parameter)
* @param item A query item to check
diff --git a/searchsummary/src/vespa/juniper/query_item.h b/searchsummary/src/vespa/juniper/query_item.h
new file mode 100644
index 00000000000..d69ede53c92
--- /dev/null
+++ b/searchsummary/src/vespa/juniper/query_item.h
@@ -0,0 +1,24 @@
+// Copyright Yahoo. 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::parseitem { enum class ItemCreator; }
+
+namespace juniper {
+
+using ItemCreator = search::parseitem::ItemCreator;
+
+/*
+ * Interface class for juniper query items.
+ */
+class QueryItem {
+public:
+ virtual ~QueryItem() = default;
+ virtual vespalib::stringref get_index() const = 0;
+ virtual int get_weight() const = 0;
+ virtual ItemCreator get_creator() const = 0;
+};
+
+};
diff --git a/searchsummary/src/vespa/juniper/querymodifier.cpp b/searchsummary/src/vespa/juniper/querymodifier.cpp
index da751c52a92..8531455d742 100644
--- a/searchsummary/src/vespa/juniper/querymodifier.cpp
+++ b/searchsummary/src/vespa/juniper/querymodifier.cpp
@@ -47,17 +47,9 @@ void QueryModifier::AddRewriter(const char* index_name, IRewriter* rewriter,
/* Return any configured reducer/expander for the index, if any */
-Rewriter* QueryModifier::FindRewriter(const char* index_name)
+Rewriter* QueryModifier::FindRewriter(vespalib::stringref index_name)
{
return _rewriters.find(index_name);
}
-
-Rewriter* QueryModifier::FindRewriter(const char* index_name, const size_t length)
-{
- std::string idx_name(index_name, length);
- return _rewriters.find(index_name);
-}
-
-
} // end namespace juniper
diff --git a/searchsummary/src/vespa/juniper/querymodifier.h b/searchsummary/src/vespa/juniper/querymodifier.h
index ec0d20778fb..5816740033f 100644
--- a/searchsummary/src/vespa/juniper/querymodifier.h
+++ b/searchsummary/src/vespa/juniper/querymodifier.h
@@ -4,6 +4,7 @@
#include "simplemap.h"
#include "query.h"
#include "rewriter.h"
+#include <vespa/vespalib/stllike/string.h>
#include <string>
#include <vector>
@@ -63,8 +64,7 @@ public:
inline bool HasRewriters() { return _has_expanders || _has_reducers; }
/* Return any configured reducer/expander for the index, if any */
- Rewriter* FindRewriter(const char* index_name);
- Rewriter* FindRewriter(const char* index_name, const size_t length);
+ Rewriter* FindRewriter(vespalib::stringref index_name);
/* Delete/dereference all rewriters (needed for testing/debugging) */
void FlushRewriters();
diff --git a/searchsummary/src/vespa/juniper/queryparser.cpp b/searchsummary/src/vespa/juniper/queryparser.cpp
index 9b8169bee44..482c4820289 100644
--- a/searchsummary/src/vespa/juniper/queryparser.cpp
+++ b/searchsummary/src/vespa/juniper/queryparser.cpp
@@ -4,6 +4,7 @@
#include "queryparser.h"
#include "juniperdebug.h"
+#include "query_item.h"
#include <vector>
#include <cassert>
@@ -17,33 +18,57 @@ namespace juniper {
// simple syntax tree
-struct QueryItem
+class QueryParserQueryItem : public QueryItem
{
- QueryItem(const char* name, int p1 = -1) :
- _name(name), _index(""), _child(), _prefix(false), _p1(p1)
+public:
+ QueryParserQueryItem(const char* name, int p1 = -1)
+ : QueryItem(),
+ _name(name), _index(""), _child(), _prefix(false), _p1(p1)
{ }
- ~QueryItem()
- {
- for (std::vector<QueryItem*>::iterator it = _child.begin(); it != _child.end(); ++it)
- delete *it;
- }
+ ~QueryParserQueryItem() override;
inline int arity() { return _child.size(); }
- void add(QueryItem* e)
+ void add(std::unique_ptr<QueryItem> e)
{
- _child.push_back(e);
- LOG(debug, "Adding %s", e->_name.c_str());
+ _child.push_back(std::move(e));
+ if (LOG_WOULD_LOG(debug)) {
+ auto qpe = dynamic_cast<const QueryParserQueryItem*>(_child.back().get());
+ LOG(debug, "Adding %s", qpe != nullptr ? qpe->_name.c_str() : "");
+ }
}
- std::string _name;
- std::string _index;
- std::vector<QueryItem*> _child;
+ vespalib::stringref get_index() const override;
+ int get_weight() const override;
+ ItemCreator get_creator() const override;
+
+ vespalib::string _name;
+ vespalib::string _index;
+ std::vector<std::unique_ptr<QueryItem>> _child;
bool _prefix;
int _p1;
};
+QueryParserQueryItem::~QueryParserQueryItem() = default;
+
+vespalib::stringref
+QueryParserQueryItem::get_index() const
+{
+ return _index;
+}
+
+int
+QueryParserQueryItem::get_weight() const
+{
+ return 100;
+}
+
+ItemCreator
+QueryParserQueryItem::get_creator() const
+{
+ return ItemCreator::CREA_ORIG;
+}
QueryParser::QueryParser(const char* query_string) :
_tokenizer(),
@@ -51,7 +76,7 @@ QueryParser::QueryParser(const char* query_string) :
_query_string(query_string),
_curtok(),
_v(NULL),
- _exp(NULL), _parse_errno(0), _reached_end(false)
+ _exp(), _parse_errno(0), _reached_end(false)
{
_op_to_type["AND"] = TOK_NORM_OP;
_op_to_type["OR"] = TOK_NORM_OP;
@@ -110,41 +135,23 @@ bool QueryParser::match(const char* s, bool required)
bool QueryParser::Traverse(IQueryVisitor* v) const
{
const_cast<QueryParser*>(this)->_v = v;
- if (_exp) trav(_exp);
+ if (_exp) trav(_exp.get());
return true;
}
-int QueryParser::Weight(const QueryItem*) const
-{
- return 100;
-}
-
-ItemCreator QueryParser::Creator(const QueryItem*) const
-{
- return CREA_ORIG;
-}
-
-const char* QueryParser::Index(const QueryItem* e, size_t* len) const
-{
- if (len) *len = e->_index.size();
- return e->_index.c_str();
-}
-
bool QueryParser::UsefulIndex(const QueryItem*) const
{
return true;
}
-QueryParser::~QueryParser()
-{
- delete _exp;
-}
-
+QueryParser::~QueryParser() = default;
-void QueryParser::trav(QueryItem* e) const
+void QueryParser::trav(QueryItem* e_abstract) const
{
+ auto e = dynamic_cast<QueryParserQueryItem*>(e_abstract);
+ assert(e != nullptr);
if (e->arity() == 0)
_v->VisitKeyword(e, e->_name.c_str(), e->_name.size(), e->_prefix);
if (e->_name.compare("AND") == 0) _v->VisitAND(e, e->arity());
@@ -157,11 +164,13 @@ void QueryParser::trav(QueryItem* e) const
else if (e->_name.compare("WITHIN") == 0) _v->VisitWITHIN(e, e->arity(), e->_p1);
else if (e->_name.compare("ONEAR") == 0) _v->VisitWITHIN(e, e->arity(), e->_p1);
- for (std::vector<QueryItem*>::iterator it = e->_child.begin(); it != e->_child.end(); ++it)
- trav(*it);
+ for (auto& child : e->_child) {
+ trav(child.get());
+ }
}
-QueryItem* QueryParser::ParseExpr()
+std::unique_ptr<QueryItem>
+QueryParser::ParseExpr()
{
int p1 = -1;
std::map<std::string, int>::iterator it = _op_to_type.find(_curtok);
@@ -184,30 +193,28 @@ QueryItem* QueryParser::ParseExpr()
}
next();
if (!match("(", true)) return NULL;
- QueryItem* e = new QueryItem(op.c_str(), p1);
+ auto e = std::make_unique<QueryParserQueryItem>(op.c_str(), p1);
do
{
if (ParseError()) return NULL;
next();
- QueryItem* ep = ParseExpr();
+ auto ep = ParseExpr();
if (!ep)
{
- delete e;
- return NULL;
+ return {};
}
- e->add(ep);
+ e->add(std::move(ep));
} while (match(","));
if (!match(")", true))
{
- delete e;
- return NULL;
+ return {};
}
next();
return e;
}
-
-QueryItem* QueryParser::ParseIndexTerm()
+std::unique_ptr<QueryItem>
+QueryParser::ParseIndexTerm()
{
std::string t = _curtok;
next();
@@ -215,30 +222,34 @@ QueryItem* QueryParser::ParseIndexTerm()
{
next();
LOG(debug, "ParseIndexTerm: %s:%s", t.c_str(), _curtok.c_str());
- QueryItem* e = ParseKeyword();
- if (e) e->_index = t;
+ auto e = ParseKeyword();
+ if (e) {
+ e->_index = t;
+ }
return e;
}
else
return CheckPrefix(t);
}
-QueryItem* QueryParser::CheckPrefix(std::string& kw)
+std::unique_ptr<QueryParserQueryItem>
+QueryParser::CheckPrefix(std::string& kw)
{
std::string::size_type pos = kw.find_first_of("*?");
bool prefix = pos == kw.size() - 1 && kw[pos] == '*';
if (prefix)
kw.erase(pos);
- QueryItem* e = new QueryItem(kw.c_str());
+ auto e = std::make_unique<QueryParserQueryItem>(kw.c_str());
e->_prefix = pos != std::string::npos;
return e;
}
-QueryItem* QueryParser::ParseKeyword()
+std::unique_ptr<QueryParserQueryItem>
+QueryParser::ParseKeyword()
{
LOG(debug, "ParseKeyword: %s", _curtok.c_str());
- QueryItem* e = CheckPrefix(_curtok);
+ auto e = CheckPrefix(_curtok);
next();
return e;
}
diff --git a/searchsummary/src/vespa/juniper/queryparser.h b/searchsummary/src/vespa/juniper/queryparser.h
index 9c596892e31..99d31f4e5ff 100644
--- a/searchsummary/src/vespa/juniper/queryparser.h
+++ b/searchsummary/src/vespa/juniper/queryparser.h
@@ -6,6 +6,7 @@
#include "query.h"
#include "latintokenizer.h"
#include <map>
+#include <memory>
#include <string>
namespace juniper
@@ -22,6 +23,8 @@ struct IsPunctuation {
typedef Fast_LatinTokenizer<Fast_IsSpace, IsPunctuation> WildcardTokenizer;
+class QueryParserQueryItem;
+
class QueryParser : public IQuery
{
private:
@@ -32,29 +35,26 @@ public:
virtual ~QueryParser();
bool Traverse(IQueryVisitor* v) const override;
- int Weight(const QueryItem* item) const override;
- ItemCreator Creator(const QueryItem* item) const override;
- const char* Index(const QueryItem* item, size_t* length) const override;
bool UsefulIndex(const QueryItem* item) const override;
int ParseError() { return _parse_errno; }
-protected:
- QueryItem* ParseExpr();
- QueryItem* ParseKeyword();
- QueryItem* ParseIndexTerm();
- QueryItem* CheckPrefix(std::string& kw);
+private:
+ std::unique_ptr<QueryItem> ParseExpr();
+ std::unique_ptr<QueryParserQueryItem> ParseKeyword();
+ std::unique_ptr<QueryItem> ParseIndexTerm();
+ std::unique_ptr<QueryParserQueryItem> CheckPrefix(std::string& kw);
void next();
void trav(QueryItem*) const;
inline void setvisitor(IQueryVisitor* v) { _v = v; }
bool match(const char* s, bool required = false);
-private:
+
typedef WildcardTokenizer Tokenizer;
Tokenizer _tokenizer;
std::map<std::string, int> _op_to_type;
const char* _query_string;
std::string _curtok;
IQueryVisitor* _v;
- QueryItem* _exp;
+ std::unique_ptr<QueryItem> _exp;
int _parse_errno;
bool _reached_end;
};
diff --git a/searchsummary/src/vespa/juniper/queryvisitor.cpp b/searchsummary/src/vespa/juniper/queryvisitor.cpp
index dcd716c0c0f..ad06e8ee872 100644
--- a/searchsummary/src/vespa/juniper/queryvisitor.cpp
+++ b/searchsummary/src/vespa/juniper/queryvisitor.cpp
@@ -3,6 +3,7 @@
#include "query.h"
#include "juniperdebug.h"
#include "queryvisitor.h"
+#include "query_item.h"
#include "Matcher.h"
#include "queryhandle.h"
#include "querymodifier.h"
@@ -200,10 +201,7 @@ bool QueryVisitor::VisitOther(const QueryItem*, int arity)
std::string QueryVisitor::get_index(const QueryItem* item)
{
- size_t len;
- const char* ind = _fquery->Index(item, &len);
- std::string s(ind, len);
- return s;
+ return item->get_index();
}
@@ -214,11 +212,11 @@ void QueryVisitor::VisitKeyword(const QueryItem* item, const char* keyword,
// Do not consider empty terms.
return;
}
- juniper::ItemCreator creator = _fquery->Creator(item);
+ juniper::ItemCreator creator = item->get_creator();
switch (creator)
{
- case juniper::CREA_ORIG:
- LOG(debug, "(juniper::VisitKeyword) Found valid creator '%s'", creator_text(creator));
+ case juniper::ItemCreator::CREA_ORIG:
+ LOG(debug, "(juniper::VisitKeyword) Found valid creator '%s'", juniper::creator_text(creator));
break;
default:
/** Keep track of eliminated children to have correct arity in rep. */
@@ -227,7 +225,7 @@ void QueryVisitor::VisitKeyword(const QueryItem* item, const char* keyword,
std::string s(keyword, length);
std::string ind = get_index(item);
LOG(debug, "juniper: VisitKeyword(%s:%s) - skip - unwanted creator %s",
- ind.c_str(), s.c_str(), creator_text(creator));
+ ind.c_str(), s.c_str(), juniper::creator_text(creator));
}
return;
}
@@ -249,7 +247,7 @@ void QueryVisitor::VisitKeyword(const QueryItem* item, const char* keyword,
ind.c_str(), (ind.size() > 0 ? ":" : ""), s.c_str());
}
- QueryTerm* term = new QueryTerm(keyword, length, _term_index++, _fquery->Weight(item));
+ QueryTerm* term = new QueryTerm(keyword, length, _term_index++, item->get_weight());
if (prefix)
{
size_t tmplen = length;
@@ -265,12 +263,11 @@ void QueryVisitor::VisitKeyword(const QueryItem* item, const char* keyword,
}
if (_queryModifier.HasRewriters())
{
- size_t len;
- const char* idx = _fquery->Index(item, &len);
- if (idx)
+ auto ind = item->get_index();
+ if (!ind.empty())
{
// record any rewriter for easier lookup later on..
- juniper::Rewriter* rh = _queryModifier.FindRewriter(idx, len);
+ juniper::Rewriter* rh = _queryModifier.FindRewriter(ind);
if (rh)
{
term->rewriter = rh;
@@ -299,8 +296,8 @@ const char* creator_text(ItemCreator creator)
{
switch (creator)
{
- case CREA_ORIG: return "CREA_ORIG";
- case CREA_FILTER: return "CREA_FILTER";
+ case ItemCreator::CREA_ORIG: return "CREA_ORIG";
+ case ItemCreator::CREA_FILTER: return "CREA_FILTER";
default: return "(unknown creator)";
}
}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/dynamicteaserdfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/dynamicteaserdfw.cpp
index df5ce032acd..74845853fce 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/dynamicteaserdfw.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/dynamicteaserdfw.cpp
@@ -10,6 +10,7 @@
#include <vespa/vespalib/objects/hexdump.h>
#include <vespa/juniper/config.h>
#include <vespa/juniper/queryhandle.h>
+#include <vespa/juniper/query_item.h>
#include <vespa/juniper/result.h>
#include <vespa/vespalib/data/slime/inserter.h>
#include <sstream>
@@ -17,17 +18,16 @@
#include <vespa/log/log.h>
LOG_SETUP(".searchlib.docsummary.dynamicteaserdfw");
-namespace juniper {
+namespace search::docsummary {
struct ExplicitItemData
{
- const char *_index;
- uint32_t _indexlen;
- uint32_t _weight;
+ vespalib::stringref _index;
+ int32_t _weight;
ExplicitItemData()
- : _index(nullptr), _indexlen(0), _weight(0)
- {}
+ : _index(), _weight(0)
+ {}
};
@@ -37,47 +37,68 @@ struct ExplicitItemData
* the stack of the IQuery Traverse method. This is needed because
* the Traverse method is const.
**/
-struct QueryItem
+class JuniperDFWQueryItem : public juniper::QueryItem
{
search::SimpleQueryStackDumpIterator *_si;
const ExplicitItemData *_data;
- QueryItem() : _si(nullptr), _data(nullptr) {}
- explicit QueryItem(search::SimpleQueryStackDumpIterator *si) : _si(si), _data(nullptr) {}
- explicit QueryItem(ExplicitItemData *data) : _si(nullptr), _data(data) {}
- QueryItem(const QueryItem&) = delete;
- QueryItem& operator= (const QueryItem&) = delete;
+public:
+ JuniperDFWQueryItem() : _si(nullptr), _data(nullptr) {}
+ ~JuniperDFWQueryItem() override = default;
+ explicit JuniperDFWQueryItem(search::SimpleQueryStackDumpIterator *si) : _si(si), _data(nullptr) {}
+ explicit JuniperDFWQueryItem(const ExplicitItemData *data) : _si(nullptr), _data(data) {}
+ JuniperDFWQueryItem(const QueryItem&) = delete;
+ JuniperDFWQueryItem& operator= (const QueryItem&) = delete;
+
+ vespalib::stringref get_index() const override;
+ int get_weight() const override;
+ juniper::ItemCreator get_creator() const override;
};
+
+vespalib::stringref
+JuniperDFWQueryItem::get_index() const
+{
+ return _si != nullptr ? _si->getIndexName() : _data->_index;
+}
+
+int
+JuniperDFWQueryItem::get_weight() const
+{
+ return _si != nullptr ? _si->GetWeight().percent() : _data->_weight;
}
-namespace search::fef {
-class TermVisitor : public IPropertiesVisitor
+juniper::ItemCreator
+JuniperDFWQueryItem::get_creator() const
+{
+ return _si != nullptr ? _si->getCreator() : juniper::ItemCreator::CREA_ORIG;
+}
+
+class TermVisitor : public search::fef::IPropertiesVisitor
{
public:
juniper::IQueryVisitor *_visitor;
- juniper::QueryItem _item;
+ JuniperDFWQueryItem _item;
explicit TermVisitor(juniper::IQueryVisitor *visitor)
: _visitor(visitor),
_item()
{}
- void visitProperty(const Property::Value &key, const Property &values) override;
+ void visitProperty(const search::fef::Property::Value &key, const search::fef::Property &values) override;
};
void
-TermVisitor::visitProperty(const Property::Value &key, const Property &values)
+TermVisitor::visitProperty(const search::fef::Property::Value &key, const search::fef::Property &values)
{
- juniper::ExplicitItemData data;
- juniper::QueryItem item(&data);
+ ExplicitItemData data;
+ JuniperDFWQueryItem item(&data);
int index = 0;
int numBlocks = atoi(values.getAt(index++).c_str());
- data._index = key.c_str();
- data._indexlen = key.length();
+ data._index = key;
_visitor->VisitAND(&item, numBlocks);
for (int i = 0; i < numBlocks; i++) {
- const Property::Value * s = & values.getAt(index++);
+ const search::fef::Property::Value * s = & values.getAt(index++);
if ((*s)[0] == '"') {
s = & values.getAt(index++);
int phraseLen = atoi(s->c_str());
@@ -93,10 +114,6 @@ TermVisitor::visitProperty(const Property::Value &key, const Property &values)
}
}
-}
-
-namespace search::docsummary {
-
class JuniperQueryAdapter : public juniper::IQuery
{
private:
@@ -126,46 +143,12 @@ public:
bool Traverse(juniper::IQueryVisitor *v) const override;
- int Weight(const juniper::QueryItem* item) const override
- {
- if (item->_si != nullptr) {
- return item->_si->GetWeight().percent();
- } else {
- return item->_data->_weight;
- }
- }
- juniper::ItemCreator Creator(const juniper::QueryItem* item) const override
- {
- // cast master: Knut Omang
- if (item->_si != nullptr) {
- return (juniper::ItemCreator) item->_si->getCreator();
- } else {
- return juniper::CREA_ORIG;
- }
- }
- const char *Index(const juniper::QueryItem* item, size_t *len) const override
- {
- if (item->_si != nullptr) {
- *len = item->_si->getIndexName().size();
- return item->_si->getIndexName().data();
- } else {
- *len = item->_data->_indexlen;
- return item->_data->_index;
- }
-
- }
bool UsefulIndex(const juniper::QueryItem* item) const override
{
- vespalib::stringref index;
-
- if (_kwExtractor == nullptr)
+ if (_kwExtractor == nullptr) {
return true;
-
- if (item->_si != nullptr) {
- index = item->_si->getIndexName();
- } else {
- index = vespalib::stringref(item->_data->_index, item->_data->_indexlen);
}
+ auto index = item->get_index();
return _kwExtractor->IsLegalIndex(index);
}
};
@@ -175,7 +158,7 @@ JuniperQueryAdapter::Traverse(juniper::IQueryVisitor *v) const
{
bool rc = true;
search::SimpleQueryStackDumpIterator iterator(_buf);
- juniper::QueryItem item(&iterator);
+ JuniperDFWQueryItem item(&iterator);
if (_highlightTerms->numKeys() > 0) {
v->VisitAND(&item, 2);
@@ -280,7 +263,7 @@ JuniperQueryAdapter::Traverse(juniper::IQueryVisitor *v) const
if (_highlightTerms->numKeys() > 1) {
v->VisitAND(&item, _highlightTerms->numKeys());
}
- fef::TermVisitor tv(v);
+ TermVisitor tv(v);
_highlightTerms->visitProperties(tv);
return rc;
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/keywordextractor.cpp b/searchsummary/src/vespa/searchsummary/docsummary/keywordextractor.cpp
index e5e0d20832b..0256965e7f4 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/keywordextractor.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/keywordextractor.cpp
@@ -13,7 +13,7 @@ namespace search::docsummary {
bool useful(search::ParseItem::ItemCreator creator)
{
- return creator == search::ParseItem::CREA_ORIG;
+ return creator == search::ParseItem::ItemCreator::CREA_ORIG;
}