summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-03-04 14:05:24 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-03-04 14:14:55 +0000
commitd2d26962756cf63046b208c0a920b7bbbeba435b (patch)
tree19dab4e3c21f40917fe444d50d6d561a2490a777
parentcd29e2859009ca728dd6d268715d1703c8d4a321 (diff)
Make the SearchTerm enum a small scoped enum and rename to Type.
-rw-r--r--searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp2
-rw-r--r--searchlib/src/tests/attribute/reference_attribute/reference_attribute_test.cpp2
-rw-r--r--searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp61
-rw-r--r--searchlib/src/tests/attribute/searchcontextelementiterator/searchcontextelementiterator_test.cpp2
-rw-r--r--searchlib/src/tests/query/streaming_query_test.cpp86
-rw-r--r--searchlib/src/tests/queryeval/queryeval.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/query/query_term_simple.cpp48
-rw-r--r--searchlib/src/vespa/searchlib/query/query_term_simple.h30
-rw-r--r--searchlib/src/vespa/searchlib/query/query_term_ucs4.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/query/query_term_ucs4.h2
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/querynode.cpp23
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/query/streaming/queryterm.h2
-rw-r--r--searchlib/src/vespa/searchlib/test/imported_attribute_fixture.cpp2
-rw-r--r--vsm/src/tests/searcher/searcher_test.cpp25
16 files changed, 153 insertions, 144 deletions
diff --git a/searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp b/searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp
index 8f2c82fb21b..4e04677f972 100644
--- a/searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp
+++ b/searchcore/src/tests/proton/documentmetastore/documentmetastore_test.cpp
@@ -193,7 +193,7 @@ assertWhiteList(const SimpleResult &exp, Blueprint::UP whiteListBlueprint, bool
void
assertSearchResult(const SimpleResult &exp, const DocumentMetaStore &dms,
- const vespalib::string &term, const QueryTermSimple::SearchTerm &termType,
+ const vespalib::string &term, const QueryTermSimple::Type &termType,
bool strict, uint32_t docIdLimit = 100)
{
AttributeVector::SearchContext::UP sc =
diff --git a/searchlib/src/tests/attribute/reference_attribute/reference_attribute_test.cpp b/searchlib/src/tests/attribute/reference_attribute/reference_attribute_test.cpp
index b6b8e0a60e8..a8a34b0ba8a 100644
--- a/searchlib/src/tests/attribute/reference_attribute/reference_attribute_test.cpp
+++ b/searchlib/src/tests/attribute/reference_attribute/reference_attribute_test.cpp
@@ -476,7 +476,7 @@ struct ReferenceAttributeSearchTest : public ReferenceAttributeTest {
}
void expect_search_result(const std::string& term, const FakeResult& expected) {
- auto ctx = _attr->getSearch(std::make_unique<QueryTermSimple>(term, QueryTermSimple::WORD),
+ auto ctx = _attr->getSearch(std::make_unique<QueryTermSimple>(term, QueryTermSimple::Type::WORD),
SearchContextParams());
TermFieldMatchData tfmd;
auto itr = ctx->createIterator(&tfmd, false);
diff --git a/searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp b/searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp
index 11da9701b92..1af70946fa2 100644
--- a/searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp
+++ b/searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp
@@ -61,6 +61,7 @@ using fef::TermFieldMatchDataPosition;
using queryeval::HitCollector;
using queryeval::SearchIterator;
using queryeval::SimpleResult;
+using TermType = search::QueryTermSimple::Type;
class DocSet : public std::set<uint32_t>
{
@@ -117,7 +118,7 @@ public:
static void addReservedDoc(AttributeVector &ptr);
static void addDocs(AttributeVector & ptr, uint32_t numDocs);
template <typename V, typename T>
- static SearchContextPtr getSearch(const V & vec, const T & term, QueryTermSimple::SearchTerm termType=QueryTermSimple::WORD);
+ static SearchContextPtr getSearch(const V & vec, const T & term, TermType termType=TermType::WORD);
private:
typedef std::map<vespalib::string, Config> ConfigMap;
// Map of all config objects
@@ -137,14 +138,14 @@ private:
template <typename V, typename T>
void fillPostingList(PostingList<V, T> & pl);
static void buildTermQuery(std::vector<char> & buffer, const vespalib::string & index, const vespalib::string & term,
- QueryTermSimple::SearchTerm termType=QueryTermSimple::WORD);
+ TermType termType=TermType::WORD);
ResultSetPtr performSearch(SearchIterator & sb, uint32_t numDocs);
template <typename V, typename T>
- ResultSetPtr performSearch(const V & vec, const T & term, QueryTermSimple::SearchTerm termType=QueryTermSimple::WORD);
+ ResultSetPtr performSearch(const V & vec, const T & term, TermType termType=TermType::WORD);
template <typename V>
void performSearch(const V & vec, const vespalib::string & term,
- const DocSet & expected, QueryTermSimple::SearchTerm termType);
+ const DocSet & expected, TermType termType);
void checkResultSet(const ResultSet & rs, const DocSet & exp, bool bitVector);
template<typename T, typename A>
@@ -236,7 +237,7 @@ private:
// test prefix search
void performPrefixSearch(const StringAttribute & vec, const vespalib::string & term,
- const DocSet & expected, QueryTermSimple::SearchTerm termType);
+ const DocSet & expected, TermType termType);
void testPrefixSearch(const AttributePtr & ptr);
void testPrefixSearch();
@@ -390,7 +391,7 @@ SearchContextTest::fillPostingList(PostingList<V, T> & pl)
}
void
-SearchContextTest::buildTermQuery(std::vector<char> & buffer, const vespalib::string & index, const vespalib::string & term, QueryTermSimple::SearchTerm termType)
+SearchContextTest::buildTermQuery(std::vector<char> & buffer, const vespalib::string & index, const vespalib::string & term, TermType termType)
{
uint32_t indexLen = index.size();
uint32_t termLen = term.size();
@@ -398,8 +399,8 @@ SearchContextTest::buildTermQuery(std::vector<char> & buffer, const vespalib::st
uint32_t p = 0;
buffer.resize(queryPacketSize);
switch (termType) {
- case QueryTermSimple::PREFIXTERM: buffer[p++] = ParseItem::ITEM_PREFIXTERM; break;
- case QueryTermSimple::REGEXP: buffer[p++] = ParseItem::ITEM_REGEXP; break;
+ case TermType::PREFIXTERM: buffer[p++] = ParseItem::ITEM_PREFIXTERM; break;
+ case TermType::REGEXP: buffer[p++] = ParseItem::ITEM_REGEXP; break;
default:
buffer[p++] = ParseItem::ITEM_TERM;
break;
@@ -415,7 +416,7 @@ SearchContextTest::buildTermQuery(std::vector<char> & buffer, const vespalib::st
template <typename V, typename T>
SearchContextPtr
-SearchContextTest::getSearch(const V & vec, const T & term, QueryTermSimple::SearchTerm termType)
+SearchContextTest::getSearch(const V & vec, const T & term, TermType termType)
{
std::vector<char> query;
vespalib::asciistream ss;
@@ -441,7 +442,7 @@ SearchContextTest::performSearch(SearchIterator & sb, uint32_t numDocs)
template <typename V, typename T>
ResultSetPtr
-SearchContextTest::performSearch(const V & vec, const T & term, QueryTermSimple::SearchTerm termType)
+SearchContextTest::performSearch(const V & vec, const T & term, TermType termType)
{
TermFieldMatchData dummy;
SearchContextPtr sc = getSearch(vec, term, termType);
@@ -454,7 +455,7 @@ SearchContextTest::performSearch(const V & vec, const T & term, QueryTermSimple:
template <typename V>
void
SearchContextTest::performSearch(const V & vec, const vespalib::string & term,
- const DocSet & expected, QueryTermSimple::SearchTerm termType)
+ const DocSet & expected, TermType termType)
{
#if 0
std::cout << "performSearch[" << term << "]: {";
@@ -1100,7 +1101,7 @@ void
SearchContextTest::performRangeSearch(const VectorType & vec, const vespalib::string & term,
const DocSet & expected)
{
- performSearch(vec, term, expected, QueryTermSimple::WORD);
+ performSearch(vec, term, expected, TermType::WORD);
}
template <typename VectorType, typename ValueType>
@@ -1307,7 +1308,7 @@ void
SearchContextTest::performCaseInsensitiveSearch(const StringAttribute & vec, const vespalib::string & term,
const DocSet & expected)
{
- performSearch(vec, term, expected, QueryTermSimple::WORD);
+ performSearch(vec, term, expected, TermType::WORD);
}
void
@@ -1403,8 +1404,8 @@ SearchContextTest::testRegexSearch(const AttributePtr & ptr)
}
for (uint32_t i = 0; i < terms.size(); ++i) {
- performSearch(vec, terms[i], expected[i], QueryTermSimple::REGEXP);
- performSearch(vec, terms[i], empty, QueryTermSimple::WORD);
+ performSearch(vec, terms[i], expected[i], TermType::REGEXP);
+ performSearch(vec, terms[i], empty, TermType::WORD);
}
}
@@ -1432,7 +1433,7 @@ SearchContextTest::testRegexSearch()
void
SearchContextTest::performPrefixSearch(const StringAttribute & vec, const vespalib::string & term,
- const DocSet & expected, QueryTermSimple::SearchTerm termType)
+ const DocSet & expected, TermType termType)
{
performSearch(vec, term, expected, termType);
}
@@ -1477,11 +1478,11 @@ SearchContextTest::testPrefixSearch(const AttributePtr & ptr)
for (uint32_t i = 0; i < 4; ++i) {
for (uint32_t j = 0; j < 3; ++j) {
if (j == 0 || ptr->getConfig().fastSearch()) {
- performPrefixSearch(vec, terms[i][j], expected[i], QueryTermSimple::PREFIXTERM);
- performPrefixSearch(vec, terms[i][j], empty, QueryTermSimple::WORD);
+ performPrefixSearch(vec, terms[i][j], expected[i], TermType::PREFIXTERM);
+ performPrefixSearch(vec, terms[i][j], empty, TermType::WORD);
} else {
- performPrefixSearch(vec, terms[i][j], empty, QueryTermSimple::PREFIXTERM);
- performPrefixSearch(vec, terms[i][j], empty, QueryTermSimple::WORD);
+ performPrefixSearch(vec, terms[i][j], empty, TermType::PREFIXTERM);
+ performPrefixSearch(vec, terms[i][j], empty, TermType::WORD);
}
}
}
@@ -1779,15 +1780,15 @@ SearchContextTest::requireThatFlagAttributeHandlesTheByteRange()
fa.append(5, 127, 1);
fa.commit(true);
- performSearch(fa, "-128", DocSet().put(1), QueryTermSimple::WORD);
- performSearch(fa, "127", DocSet().put(5), QueryTermSimple::WORD);
- performSearch(fa, ">-128", DocSet().put(2).put(3).put(4).put(5), QueryTermSimple::WORD);
- performSearch(fa, "<127", DocSet().put(1).put(2).put(3).put(4), QueryTermSimple::WORD);
- performSearch(fa, "[-128;-8]", DocSet().put(1).put(2), QueryTermSimple::WORD);
- performSearch(fa, "[-8;8]", DocSet().put(2).put(3), QueryTermSimple::WORD);
- performSearch(fa, "[8;127]", DocSet().put(3).put(4).put(5), QueryTermSimple::WORD);
- performSearch(fa, "[-129;-8]", DocSet().put(1).put(2), QueryTermSimple::WORD);
- performSearch(fa, "[8;128]", DocSet().put(3).put(4).put(5), QueryTermSimple::WORD);
+ performSearch(fa, "-128", DocSet().put(1), TermType::WORD);
+ performSearch(fa, "127", DocSet().put(5), TermType::WORD);
+ performSearch(fa, ">-128", DocSet().put(2).put(3).put(4).put(5), TermType::WORD);
+ performSearch(fa, "<127", DocSet().put(1).put(2).put(3).put(4), TermType::WORD);
+ performSearch(fa, "[-128;-8]", DocSet().put(1).put(2), TermType::WORD);
+ performSearch(fa, "[-8;8]", DocSet().put(2).put(3), TermType::WORD);
+ performSearch(fa, "[8;127]", DocSet().put(3).put(4).put(5), TermType::WORD);
+ performSearch(fa, "[-129;-8]", DocSet().put(1).put(2), TermType::WORD);
+ performSearch(fa, "[8;128]", DocSet().put(3).put(4).put(5), TermType::WORD);
}
void
@@ -1838,7 +1839,7 @@ public:
_attr.commit();
}
search::AttributeVector::SearchContext::UP create_search_context(const std::string& term) const {
- return _attr.getSearch(std::make_unique<search::QueryTermSimple>(term, search::QueryTermSimple::WORD),
+ return _attr.getSearch(std::make_unique<search::QueryTermSimple>(term, search::TermType::WORD),
SearchContextParams().useBitVector(true));
}
SimpleResult search_context(const std::string& term) const {
diff --git a/searchlib/src/tests/attribute/searchcontextelementiterator/searchcontextelementiterator_test.cpp b/searchlib/src/tests/attribute/searchcontextelementiterator/searchcontextelementiterator_test.cpp
index 22fd409320c..7f9577eb13f 100644
--- a/searchlib/src/tests/attribute/searchcontextelementiterator/searchcontextelementiterator_test.cpp
+++ b/searchlib/src/tests/attribute/searchcontextelementiterator/searchcontextelementiterator_test.cpp
@@ -109,7 +109,7 @@ TEST(ElementIteratorTest, require_that_searchcontext)
fef::TermFieldMatchData tfmd;
SearchContextParams params;
- ISearchContext::UP sc = attribute->createSearchContext(std::make_unique<QueryTermSimple>("1", QueryTermSimple::SearchTerm::WORD), params);
+ ISearchContext::UP sc = attribute->createSearchContext(std::make_unique<QueryTermSimple>("1", QueryTermSimple::Type::WORD), params);
SearchContextElementIterator elemIt(sc->createIterator(&tfmd, false), *sc);
verifyElementIterator(elemIt);
}
diff --git a/searchlib/src/tests/query/streaming_query_test.cpp b/searchlib/src/tests/query/streaming_query_test.cpp
index dbd186fdcb5..9aa07570c0d 100644
--- a/searchlib/src/tests/query/streaming_query_test.cpp
+++ b/searchlib/src/tests/query/streaming_query_test.cpp
@@ -11,6 +11,7 @@
using namespace search;
using namespace search::query;
using namespace search::streaming;
+using TermType = QueryTerm::Type;
void assertHit(const Hit & h, size_t expWordpos, size_t expContext, int32_t weight) {
EXPECT_EQUAL(h.wordpos(), expWordpos);
@@ -23,7 +24,7 @@ TEST("testQueryLanguage") {
int64_t ia(0), ib(0);
double da(0), db(0);
- QueryTerm q(factory.create(), "7", "index", QueryTerm::WORD);
+ QueryTerm q(factory.create(), "7", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, 7);
EXPECT_EQUAL(ib, 7);
@@ -31,7 +32,7 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(da, 7);
EXPECT_EQUAL(db, 7);
- q = QueryTerm(factory.create(), "-7", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "-7", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, -7);
EXPECT_EQUAL(ib, -7);
@@ -39,19 +40,19 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(da, -7);
EXPECT_EQUAL(db, -7);
- q = QueryTerm(factory.create(), "7.5", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "7.5", "index", TermType::WORD);
EXPECT_TRUE(!q.getAsIntegerTerm(ia, ib));
EXPECT_TRUE(q.getAsDoubleTerm(da, db));
EXPECT_EQUAL(da, 7.5);
EXPECT_EQUAL(db, 7.5);
- q = QueryTerm(factory.create(), "-7.5", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "-7.5", "index", TermType::WORD);
EXPECT_TRUE(!q.getAsIntegerTerm(ia, ib));
EXPECT_TRUE(q.getAsDoubleTerm(da, db));
EXPECT_EQUAL(da, -7.5);
EXPECT_EQUAL(db, -7.5);
- q = QueryTerm(factory.create(), "<7", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "<7", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, std::numeric_limits<int64_t>::min());
EXPECT_EQUAL(ib, 6);
@@ -60,7 +61,7 @@ TEST("testQueryLanguage") {
EXPECT_LESS(db, 7);
EXPECT_GREATER(db, 6.99);
- q = QueryTerm(factory.create(), "[;7]", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "[;7]", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, std::numeric_limits<int64_t>::min());
EXPECT_EQUAL(ib, 7);
@@ -68,7 +69,7 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(da, -std::numeric_limits<double>::max());
EXPECT_EQUAL(db, 7);
- q = QueryTerm(factory.create(), ">7", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), ">7", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, 8);
EXPECT_EQUAL(ib, std::numeric_limits<int64_t>::max());
@@ -77,7 +78,7 @@ TEST("testQueryLanguage") {
EXPECT_LESS(da, 7.01);
EXPECT_EQUAL(db, std::numeric_limits<double>::max());
- q = QueryTerm(factory.create(), "[7;]", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "[7;]", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, 7);
EXPECT_EQUAL(ib, std::numeric_limits<int64_t>::max());
@@ -85,7 +86,7 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(da, 7);
EXPECT_EQUAL(db, std::numeric_limits<double>::max());
- q = QueryTerm(factory.create(), "[-7;7]", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "[-7;7]", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, -7);
EXPECT_EQUAL(ib, 7);
@@ -93,7 +94,7 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(da, -7);
EXPECT_EQUAL(db, 7);
- q = QueryTerm(factory.create(), "[-7.1;7.1]", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "[-7.1;7.1]", "index", TermType::WORD);
EXPECT_FALSE(q.getAsIntegerTerm(ia, ib)); // This is dubious and perhaps a regression.
EXPECT_EQUAL(ia, std::numeric_limits<int64_t>::min());
EXPECT_EQUAL(ib, std::numeric_limits<int64_t>::max());
@@ -101,7 +102,7 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(da, -7.1);
EXPECT_EQUAL(db, 7.1);
- q = QueryTerm(factory.create(), "[500.0;1.7976931348623157E308]", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "[500.0;1.7976931348623157E308]", "index", TermType::WORD);
EXPECT_FALSE(q.getAsIntegerTerm(ia, ib)); // This is dubious and perhaps a regression.
EXPECT_EQUAL(ia, std::numeric_limits<int64_t>::min());
EXPECT_EQUAL(ib, std::numeric_limits<int64_t>::max());
@@ -110,7 +111,7 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(db, std::numeric_limits<double>::max());
const double minusSeven(-7), seven(7);
- q = QueryTerm(factory.create(), "<-7;7]", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "<-7;7]", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, -6);
EXPECT_EQUAL(ib, 7);
@@ -118,7 +119,7 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(da, std::nextafterf(minusSeven, seven));
EXPECT_EQUAL(db, seven);
- q = QueryTerm(factory.create(), "<-7;7>", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "<-7;7>", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, -6);
EXPECT_EQUAL(ib, 6);
@@ -126,12 +127,12 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(da, std::nextafterf(minusSeven, seven));
EXPECT_EQUAL(db, std::nextafterf(seven, minusSeven));
- q = QueryTerm(factory.create(), "<1;2>", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "<1;2>", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, 2);
EXPECT_EQUAL(ib, 1);
- q = QueryTerm(factory.create(), "[-7;7>", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "[-7;7>", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, -7);
EXPECT_EQUAL(ib, 6);
@@ -139,7 +140,7 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(da, minusSeven);
EXPECT_EQUAL(db, std::nextafterf(seven, minusSeven));
- q = QueryTerm(factory.create(), "<-7", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "<-7", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, std::numeric_limits<int64_t>::min());
EXPECT_EQUAL(ib, -8);
@@ -148,7 +149,7 @@ TEST("testQueryLanguage") {
EXPECT_LESS(db, -7);
EXPECT_GREATER(db, -7.01);
- q = QueryTerm(factory.create(), "[;-7]", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "[;-7]", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, std::numeric_limits<int64_t>::min());
EXPECT_EQUAL(ib, -7);
@@ -156,7 +157,7 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(da, -std::numeric_limits<double>::max());
EXPECT_EQUAL(db, -7);
- q = QueryTerm(factory.create(), "<;-7]", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "<;-7]", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, std::numeric_limits<int64_t>::min());
EXPECT_EQUAL(ib, -7);
@@ -164,7 +165,7 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(da, -std::numeric_limits<double>::max());
EXPECT_EQUAL(db, -7);
- q = QueryTerm(factory.create(), ">-7", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), ">-7", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, -6);
EXPECT_EQUAL(ib, std::numeric_limits<int64_t>::max());
@@ -173,7 +174,7 @@ TEST("testQueryLanguage") {
EXPECT_LESS(da, -6.99);
EXPECT_EQUAL(db, std::numeric_limits<double>::max());
- q = QueryTerm(factory.create(), "[-7;]", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "[-7;]", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, -7);
EXPECT_EQUAL(ib, std::numeric_limits<int64_t>::max());
@@ -181,7 +182,7 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(da, -7);
EXPECT_EQUAL(db, std::numeric_limits<double>::max());
- q = QueryTerm(factory.create(), "[-7;>", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "[-7;>", "index", TermType::WORD);
EXPECT_TRUE(q.getAsIntegerTerm(ia, ib));
EXPECT_EQUAL(ia, -7);
EXPECT_EQUAL(ib, std::numeric_limits<int64_t>::max());
@@ -189,31 +190,31 @@ TEST("testQueryLanguage") {
EXPECT_EQUAL(da, -7);
EXPECT_EQUAL(db, std::numeric_limits<double>::max());
- q = QueryTerm(factory.create(), "a", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "a", "index", TermType::WORD);
EXPECT_TRUE(!q.getAsIntegerTerm(ia, ib));
EXPECT_TRUE(!q.getAsDoubleTerm(da, db));
- q = QueryTerm(factory.create(), "word", "index", QueryTerm::WORD);
+ q = QueryTerm(factory.create(), "word", "index", TermType::WORD);
EXPECT_TRUE(!q.isPrefix());
EXPECT_TRUE(!q.isSubstring());
EXPECT_TRUE(!q.isSuffix());
- q = QueryTerm(factory.create(), "prefix", "index", QueryTerm::PREFIXTERM);
+ q = QueryTerm(factory.create(), "prefix", "index", TermType::PREFIXTERM);
EXPECT_TRUE(q.isPrefix());
EXPECT_TRUE(!q.isSubstring());
EXPECT_TRUE(!q.isSuffix());
- q = QueryTerm(factory.create(), "substring", "index", QueryTerm::SUBSTRINGTERM);
+ q = QueryTerm(factory.create(), "substring", "index", TermType::SUBSTRINGTERM);
EXPECT_TRUE(!q.isPrefix());
EXPECT_TRUE(q.isSubstring());
EXPECT_TRUE(!q.isSuffix());
- q = QueryTerm(factory.create(), "suffix", "index", QueryTerm::SUFFIXTERM);
+ q = QueryTerm(factory.create(), "suffix", "index", TermType::SUFFIXTERM);
EXPECT_TRUE(!q.isPrefix());
EXPECT_TRUE(!q.isSubstring());
EXPECT_TRUE(q.isSuffix());
- q = QueryTerm(factory.create(), "regexp", "index", QueryTerm::REGEXP);
+ q = QueryTerm(factory.create(), "regexp", "index", TermType::REGEXP);
EXPECT_TRUE(!q.isPrefix());
EXPECT_TRUE(!q.isSubstring());
EXPECT_TRUE(!q.isSuffix());
@@ -426,7 +427,7 @@ TEST("testHit") {
}
void assertInt8Range(const std::string &term, bool expAdjusted, int64_t expLow, int64_t expHigh) {
- QueryTermSimple q(term, QueryTermSimple::WORD);
+ QueryTermSimple q(term, TermType::WORD);
QueryTermSimple::RangeResult<int8_t> res = q.getRange<int8_t>();
EXPECT_EQUAL(true, res.valid);
EXPECT_EQUAL(expAdjusted, res.adjusted);
@@ -435,7 +436,7 @@ void assertInt8Range(const std::string &term, bool expAdjusted, int64_t expLow,
}
void assertInt32Range(const std::string &term, bool expAdjusted, int64_t expLow, int64_t expHigh) {
- QueryTermSimple q(term, QueryTermSimple::WORD);
+ QueryTermSimple q(term, TermType::WORD);
QueryTermSimple::RangeResult<int32_t> res = q.getRange<int32_t>();
EXPECT_EQUAL(true, res.valid);
EXPECT_EQUAL(expAdjusted, res.adjusted);
@@ -444,7 +445,7 @@ void assertInt32Range(const std::string &term, bool expAdjusted, int64_t expLow,
}
void assertInt64Range(const std::string &term, bool expAdjusted, int64_t expLow, int64_t expHigh) {
- QueryTermSimple q(term, QueryTermSimple::WORD);
+ QueryTermSimple q(term, TermType::WORD);
QueryTermSimple::RangeResult<int64_t> res = q.getRange<int64_t>();
EXPECT_EQUAL(true, res.valid);
EXPECT_EQUAL(expAdjusted, res.adjusted);
@@ -547,7 +548,7 @@ TEST("require that ascending range can be specified with limit only") {
double high_double = 0.0;
QueryNodeResultFactory eqnr;
- QueryTerm ascending_query(eqnr.create(), "[;;500]", "index", QueryTerm::WORD);
+ QueryTerm ascending_query(eqnr.create(), "[;;500]", "index", TermType::WORD);
EXPECT_TRUE(ascending_query.getAsIntegerTerm(low_integer, high_integer));
EXPECT_TRUE(ascending_query.getAsDoubleTerm(low_double, high_double));
@@ -565,7 +566,7 @@ TEST("require that descending range can be specified with limit only") {
double high_double = 0.0;
QueryNodeResultFactory eqnr;
- QueryTerm descending_query(eqnr.create(), "[;;-500]", "index", QueryTerm::WORD);
+ QueryTerm descending_query(eqnr.create(), "[;;-500]", "index", TermType::WORD);
EXPECT_TRUE(descending_query.getAsIntegerTerm(low_integer, high_integer));
EXPECT_TRUE(descending_query.getAsDoubleTerm(low_double, high_double));
@@ -578,7 +579,7 @@ TEST("require that descending range can be specified with limit only") {
TEST("require that correctly specified diversity can be parsed") {
QueryNodeResultFactory eqnr;
- QueryTerm descending_query(eqnr.create(), "[;;-500;ab56;78]", "index", QueryTerm::WORD);
+ QueryTerm descending_query(eqnr.create(), "[;;-500;ab56;78]", "index", TermType::WORD);
EXPECT_TRUE(descending_query.isValid());
EXPECT_EQUAL(-500, descending_query.getRangeLimit());
EXPECT_EQUAL("ab56", descending_query.getDiversityAttribute());
@@ -589,7 +590,7 @@ TEST("require that correctly specified diversity can be parsed") {
TEST("require that correctly specified diversity with cutoff groups can be parsed") {
QueryNodeResultFactory eqnr;
- QueryTerm descending_query(eqnr.create(), "[;;-500;ab56;78;93]", "index", QueryTerm::WORD);
+ QueryTerm descending_query(eqnr.create(), "[;;-500;ab56;78;93]", "index", TermType::WORD);
EXPECT_TRUE(descending_query.isValid());
EXPECT_EQUAL(-500, descending_query.getRangeLimit());
EXPECT_EQUAL("ab56", descending_query.getDiversityAttribute());
@@ -600,7 +601,7 @@ TEST("require that correctly specified diversity with cutoff groups can be parse
TEST("require that correctly specified diversity with cutoff groups can be parsed") {
QueryNodeResultFactory eqnr;
- QueryTerm descending_query(eqnr.create(), "[;;-500;ab56;78;13]", "index", QueryTerm::WORD);
+ QueryTerm descending_query(eqnr.create(), "[;;-500;ab56;78;13]", "index", TermType::WORD);
EXPECT_TRUE(descending_query.isValid());
EXPECT_EQUAL(-500, descending_query.getRangeLimit());
EXPECT_EQUAL("ab56", descending_query.getDiversityAttribute());
@@ -611,7 +612,7 @@ TEST("require that correctly specified diversity with cutoff groups can be parse
TEST("require that correctly specified diversity with incorrect cutoff groups can be parsed") {
QueryNodeResultFactory eqnr;
- QueryTerm descending_query(eqnr.create(), "[;;-500;ab56;78;a13.9]", "index", QueryTerm::WORD);
+ QueryTerm descending_query(eqnr.create(), "[;;-500;ab56;78;a13.9]", "index", TermType::WORD);
EXPECT_TRUE(descending_query.isValid());
EXPECT_EQUAL(-500, descending_query.getRangeLimit());
EXPECT_EQUAL("ab56", descending_query.getDiversityAttribute());
@@ -622,7 +623,7 @@ TEST("require that correctly specified diversity with incorrect cutoff groups ca
TEST("require that correctly specified diversity with cutoff strategy can be parsed") {
QueryNodeResultFactory eqnr;
- QueryTerm descending_query(eqnr.create(), "[;;-500;ab56;78;93;anything but strict]", "index", QueryTerm::WORD);
+ QueryTerm descending_query(eqnr.create(), "[;;-500;ab56;78;93;anything but strict]", "index", TermType::WORD);
EXPECT_TRUE(descending_query.isValid());
EXPECT_EQUAL(-500, descending_query.getRangeLimit());
EXPECT_EQUAL("ab56", descending_query.getDiversityAttribute());
@@ -633,7 +634,7 @@ TEST("require that correctly specified diversity with cutoff strategy can be par
TEST("require that correctly specified diversity with strict cutoff strategy can be parsed") {
QueryNodeResultFactory eqnr;
- QueryTerm descending_query(eqnr.create(), "[;;-500;ab56;78;93;strict]", "index", QueryTerm::WORD);
+ QueryTerm descending_query(eqnr.create(), "[;;-500;ab56;78;93;strict]", "index", TermType::WORD);
EXPECT_TRUE(descending_query.isValid());
EXPECT_EQUAL(-500, descending_query.getRangeLimit());
EXPECT_EQUAL("ab56", descending_query.getDiversityAttribute());
@@ -644,12 +645,12 @@ TEST("require that correctly specified diversity with strict cutoff strategy can
TEST("require that incorrectly specified diversity can be parsed") {
QueryNodeResultFactory eqnr;
- QueryTerm descending_query(eqnr.create(), "[;;-500;ab56]", "index", QueryTerm::WORD);
+ QueryTerm descending_query(eqnr.create(), "[;;-500;ab56]", "index", TermType::WORD);
EXPECT_FALSE(descending_query.isValid());
}
TEST("require that we do not break the stack on bad query") {
- QueryTermSimple term("<form><iframe+&#09;&#10;&#11;+src=\\\"javascript&#58;alert(1)\\\"&#11;&#10;&#09;;>", QueryTerm::WORD);
+ QueryTermSimple term("<form><iframe+&#09;&#10;&#11;+src=\\\"javascript&#58;alert(1)\\\"&#11;&#10;&#09;;>", TermType::WORD);
EXPECT_FALSE(term.isValid());
}
@@ -731,5 +732,10 @@ TEST("testSameElementEvaluate") {
EXPECT_TRUE(sameElem->evaluate());
}
+TEST("Control the size of query terms") {
+ EXPECT_EQUAL(104u, sizeof(QueryTermSimple));
+ EXPECT_EQUAL(136u, sizeof(QueryTermUCS4));
+ EXPECT_EQUAL(280u, sizeof(QueryTerm));
+}
TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/searchlib/src/tests/queryeval/queryeval.cpp b/searchlib/src/tests/queryeval/queryeval.cpp
index 23647b208a3..f82bfabb7c3 100644
--- a/searchlib/src/tests/queryeval/queryeval.cpp
+++ b/searchlib/src/tests/queryeval/queryeval.cpp
@@ -350,7 +350,7 @@ public:
_a.update(docId, 1);
}
_a.commit();
- _sc = _a.getSearch(std::make_unique<search::QueryTermSimple>("1", search::QueryTermSimple::WORD),
+ _sc = _a.getSearch(std::make_unique<search::QueryTermSimple>("1", search::QueryTermSimple::Type::WORD),
SearchContextParams().useBitVector(true));
}
SearchIterator::UP
diff --git a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp
index 70a59f1575a..5ba38d803c8 100644
--- a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp
@@ -591,7 +591,7 @@ public:
void visit(RangeTerm &n) override {
const string stack = StackDumpCreator::create(n);
const string term = queryeval::termAsString(n);
- QueryTermSimple parsed_term(term, QueryTermSimple::WORD);
+ QueryTermSimple parsed_term(term, QueryTermSimple::Type::WORD);
if (parsed_term.getMaxPerGroup() > 0) {
const IAttributeVector *diversity(getRequestContext().getAttribute(parsed_term.getDiversityAttribute()));
if (check_valid_diversity_attr(diversity)) {
@@ -636,9 +636,9 @@ public:
extractTerm(const query::Node &node, bool isInteger) {
vespalib::string term = queryeval::termAsString(node);
if (isInteger) {
- return std::make_unique<QueryTermSimple>(term, QueryTermSimple::WORD);
+ return std::make_unique<QueryTermSimple>(term, QueryTermSimple::Type::WORD);
}
- return std::make_unique<QueryTermUCS4>(term, QueryTermSimple::WORD);
+ return std::make_unique<QueryTermUCS4>(term, QueryTermSimple::Type::WORD);
}
template <typename WS, typename NODE>
diff --git a/searchlib/src/vespa/searchlib/query/query_term_simple.cpp b/searchlib/src/vespa/searchlib/query/query_term_simple.cpp
index 46f2c6198e5..d1f616622ff 100644
--- a/searchlib/src/vespa/searchlib/query/query_term_simple.cpp
+++ b/searchlib/src/vespa/searchlib/query/query_term_simple.cpp
@@ -25,7 +25,7 @@ void
QueryTermSimple::visitMembers(vespalib::ObjectVisitor & visitor) const
{
visit(visitor, "term", _term);
- visit(visitor, "type", _type);
+ visit(visitor, "type", static_cast<uint32_t>(_type));
}
template <typename N>
@@ -189,15 +189,15 @@ bool QueryTermSimple::getAsDoubleTerm(double & lower, double & upper) const
return getAsNumericTerm(lower, upper, DoubleDecoder());
}
-QueryTermSimple::QueryTermSimple() :
- _type(WORD),
- _rangeLimit(0),
- _maxPerGroup(0),
- _diversityCutoffGroups(std::numeric_limits<uint32_t>::max()),
- _diversityCutoffStrict(false),
- _valid(true),
- _term(),
- _diversityAttribute()
+QueryTermSimple::QueryTermSimple()
+ : _rangeLimit(0),
+ _maxPerGroup(0),
+ _diversityCutoffGroups(std::numeric_limits<uint32_t>::max()),
+ _type(Type::WORD),
+ _diversityCutoffStrict(false),
+ _valid(true),
+ _term(),
+ _diversityAttribute()
{ }
QueryTermSimple::~QueryTermSimple() = default;
@@ -213,15 +213,15 @@ bool isFullRange(vespalib::stringref s) {
}
-QueryTermSimple::QueryTermSimple(const string & term_, SearchTerm type) :
- _type(type),
- _rangeLimit(0),
- _maxPerGroup(0),
- _diversityCutoffGroups(std::numeric_limits<uint32_t>::max()),
- _diversityCutoffStrict(false),
- _valid(true),
- _term(term_),
- _diversityAttribute()
+QueryTermSimple::QueryTermSimple(const string & term_, Type type)
+ : _rangeLimit(0),
+ _maxPerGroup(0),
+ _diversityCutoffGroups(std::numeric_limits<uint32_t>::max()),
+ _type(type),
+ _diversityCutoffStrict(false),
+ _valid(true),
+ _term(term_),
+ _diversityAttribute()
{
if (isFullRange(_term)) {
stringref rest(_term.c_str() + 1, _term.size() - 2);
@@ -272,7 +272,7 @@ QueryTermSimple::getAsNumericTerm(T & lower, T & upper, D d) const
bool valid(empty());
size_t sz(_term.size());
if (sz) {
- char *err(NULL);
+ char *err(nullptr);
T low(lower);
T high(upper);
const char * q = _term.c_str();
@@ -320,8 +320,8 @@ QueryTermSimple::getClassName() const
}
-void visit(vespalib::ObjectVisitor &self, const vespalib::string &name,
- const search::QueryTermSimple *obj)
+void
+visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const search::QueryTermSimple *obj)
{
if (obj != 0) {
self.openStruct(name, obj->getClassName());
@@ -332,8 +332,8 @@ void visit(vespalib::ObjectVisitor &self, const vespalib::string &name,
}
}
-void visit(vespalib::ObjectVisitor &self, const vespalib::string &name,
- const search::QueryTermSimple &obj)
+void
+visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const search::QueryTermSimple &obj)
{
visit(self, name, &obj);
}
diff --git a/searchlib/src/vespa/searchlib/query/query_term_simple.h b/searchlib/src/vespa/searchlib/query/query_term_simple.h
index 11dbdefdaab..0ee97f9d43c 100644
--- a/searchlib/src/vespa/searchlib/query/query_term_simple.h
+++ b/searchlib/src/vespa/searchlib/query/query_term_simple.h
@@ -15,13 +15,13 @@ public:
typedef std::unique_ptr<QueryTermSimple> UP;
typedef vespalib::string string;
typedef vespalib::stringref stringref;
- enum SearchTerm {
- WORD,
- PREFIXTERM,
- SUBSTRINGTERM,
- EXACTSTRINGTERM,
- SUFFIXTERM,
- REGEXP
+ enum class Type : uint8_t {
+ WORD = 0,
+ PREFIXTERM = 1,
+ SUBSTRINGTERM = 2,
+ EXACTSTRINGTERM = 3,
+ SUFFIXTERM = 4,
+ REGEXP = 5
};
template <typename N>
@@ -39,7 +39,7 @@ public:
QueryTermSimple(QueryTermSimple &&) = default;
QueryTermSimple & operator = (QueryTermSimple &&) = default;
QueryTermSimple();
- QueryTermSimple(const string & term_, SearchTerm type);
+ QueryTermSimple(const string & term_, Type type);
virtual ~QueryTermSimple();
/**
* Extracts the content of this query term as a range with low and high values.
@@ -54,12 +54,12 @@ public:
bool getAsIntegerTerm(int64_t & lower, int64_t & upper) const;
bool getAsDoubleTerm(double & lower, double & upper) const;
const char * getTerm() const { return _term.c_str(); }
- bool isPrefix() const { return (_type == PREFIXTERM); }
- bool isSubstring() const { return (_type == SUBSTRINGTERM); }
- bool isExactstring() const { return (_type == EXACTSTRINGTERM); }
- bool isSuffix() const { return (_type == SUFFIXTERM); }
- bool isWord() const { return (_type == WORD); }
- bool isRegex() const { return (_type == REGEXP); }
+ bool isPrefix() const { return (_type == Type::PREFIXTERM); }
+ bool isSubstring() const { return (_type == Type::SUBSTRINGTERM); }
+ bool isExactstring() const { return (_type == Type::EXACTSTRINGTERM); }
+ bool isSuffix() const { return (_type == Type::SUFFIXTERM); }
+ bool isWord() const { return (_type == Type::WORD); }
+ bool isRegex() const { return (_type == Type::REGEXP); }
bool empty() const { return _term.empty(); }
virtual void visitMembers(vespalib::ObjectVisitor &visitor) const;
vespalib::string getClassName() const;
@@ -72,10 +72,10 @@ private:
RangeResult<N> getIntegerRange() const;
template <typename N>
RangeResult<N> getFloatRange() const;
- SearchTerm _type;
int _rangeLimit;
uint32_t _maxPerGroup;
uint32_t _diversityCutoffGroups;
+ Type _type;
bool _diversityCutoffStrict;
bool _valid;
string _term;
diff --git a/searchlib/src/vespa/searchlib/query/query_term_ucs4.cpp b/searchlib/src/vespa/searchlib/query/query_term_ucs4.cpp
index 86cda7e6786..b267ad9253e 100644
--- a/searchlib/src/vespa/searchlib/query/query_term_ucs4.cpp
+++ b/searchlib/src/vespa/searchlib/query/query_term_ucs4.cpp
@@ -30,7 +30,7 @@ QueryTermUCS4::QueryTermUCS4() :
QueryTermUCS4::~QueryTermUCS4() = default;
-QueryTermUCS4::QueryTermUCS4(const string & termS, SearchTerm type) :
+QueryTermUCS4::QueryTermUCS4(const string & termS, Type type) :
QueryTermSimple(termS, type),
_cachedTermLen(0),
_termUCS4()
diff --git a/searchlib/src/vespa/searchlib/query/query_term_ucs4.h b/searchlib/src/vespa/searchlib/query/query_term_ucs4.h
index 8a270d47777..90f5c07b7ca 100644
--- a/searchlib/src/vespa/searchlib/query/query_term_ucs4.h
+++ b/searchlib/src/vespa/searchlib/query/query_term_ucs4.h
@@ -21,7 +21,7 @@ public:
QueryTermUCS4(QueryTermUCS4 &&) = default;
QueryTermUCS4 & operator = (QueryTermUCS4 &&) = default;
QueryTermUCS4();
- QueryTermUCS4(const string & term_, SearchTerm type);
+ QueryTermUCS4(const string & term_, Type type);
~QueryTermUCS4();
size_t getTermLen() const { return _cachedTermLen; }
size_t term(const char * & t) const { t = getTerm(); return _cachedTermLen; }
diff --git a/searchlib/src/vespa/searchlib/query/streaming/querynode.cpp b/searchlib/src/vespa/searchlib/query/streaming/querynode.cpp
index 66466b030d0..ec1b26ec143 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/querynode.cpp
+++ b/searchlib/src/vespa/searchlib/query/streaming/querynode.cpp
@@ -91,22 +91,23 @@ QueryNode::Build(const QueryNode * parent, const QueryNodeResultFactory & factor
index = parent->getIndex() + "." + index;
}
vespalib::stringref term = queryRep.getTerm();
- QueryTerm::SearchTerm sTerm(QueryTerm::WORD);
+ using TermType = QueryTerm::Type;
+ TermType sTerm(TermType::WORD);
switch (type) {
case ParseItem::ITEM_REGEXP:
- sTerm = QueryTerm::REGEXP;
+ sTerm = TermType::REGEXP;
break;
case ParseItem::ITEM_PREFIXTERM:
- sTerm = QueryTerm::PREFIXTERM;
+ sTerm = TermType::PREFIXTERM;
break;
case ParseItem::ITEM_SUBSTRINGTERM:
- sTerm = QueryTerm::SUBSTRINGTERM;
+ sTerm = TermType::SUBSTRINGTERM;
break;
case ParseItem::ITEM_EXACTSTRINGTERM:
- sTerm = QueryTerm::EXACTSTRINGTERM;
+ sTerm = TermType::EXACTSTRINGTERM;
break;
case ParseItem::ITEM_SUFFIXTERM:
- sTerm = QueryTerm::SUFFIXTERM;
+ sTerm = TermType::SUFFIXTERM;
break;
default:
break;
@@ -118,16 +119,16 @@ QueryNode::Build(const QueryNode * parent, const QueryNodeResultFactory & factor
// But it will do for now as only correct sddocname queries are sent down.
qn.reset(new TrueNode());
} else {
- std::unique_ptr<QueryTerm> qt(new QueryTerm(factory.create(), ssTerm, ssIndex, sTerm));
+ auto qt = std::make_unique<QueryTerm>(factory.create(), ssTerm, ssIndex, sTerm);
qt->setWeight(queryRep.GetWeight());
qt->setUniqueId(queryRep.getUniqueId());
if ( qt->encoding().isBase10Integer() || ! qt->encoding().isFloat() || ! factory.getRewriteFloatTerms() || !allowRewrite || (ssTerm.find('.') == vespalib::string::npos)) {
qn = std::move(qt);
} else {
- std::unique_ptr<PhraseQueryNode> phrase(new PhraseQueryNode());
- phrase->push_back(UP(new QueryTerm(factory.create(), ssTerm.substr(0, ssTerm.find('.')), ssIndex, QueryTerm::WORD)));
- phrase->push_back(UP(new QueryTerm(factory.create(), ssTerm.substr(ssTerm.find('.') + 1), ssIndex, QueryTerm::WORD)));
- std::unique_ptr<EquivQueryNode> orqn(new EquivQueryNode());
+ auto phrase = std::make_unique<PhraseQueryNode>();
+ phrase->push_back(std::make_unique<QueryTerm>(factory.create(), ssTerm.substr(0, ssTerm.find('.')), ssIndex, TermType::WORD));
+ phrase->push_back(std::make_unique<QueryTerm>(factory.create(), ssTerm.substr(ssTerm.find('.') + 1), ssIndex, TermType::WORD));
+ auto orqn = std::make_unique<EquivQueryNode>();
orqn->push_back(std::move(qt));
orqn->push_back(std::move(phrase));
qn.reset(orqn.release());
diff --git a/searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp b/searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp
index 943920c9dc6..3caa47bf55d 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp
+++ b/searchlib/src/vespa/searchlib/query/streaming/queryterm.cpp
@@ -70,7 +70,7 @@ QueryTerm::visitMembers(vespalib::ObjectVisitor & visitor) const
visit(visitor, "uniqueid", _uniqueId);
}
-QueryTerm::QueryTerm(std::unique_ptr<QueryNodeResultBase> org, const string & termS, const string & indexS, SearchTerm type) :
+QueryTerm::QueryTerm(std::unique_ptr<QueryNodeResultBase> org, const string & termS, const string & indexS, Type type) :
QueryTermUCS4(termS, type),
_index(indexS),
_encoding(0x01),
diff --git a/searchlib/src/vespa/searchlib/query/streaming/queryterm.h b/searchlib/src/vespa/searchlib/query/streaming/queryterm.h
index 65e966ca0f2..6daa60a317a 100644
--- a/searchlib/src/vespa/searchlib/query/streaming/queryterm.h
+++ b/searchlib/src/vespa/searchlib/query/streaming/queryterm.h
@@ -54,7 +54,7 @@ public:
uint32_t _fieldLength;
};
QueryTerm();
- QueryTerm(std::unique_ptr<QueryNodeResultBase> resultBase, const string & term, const string & index, SearchTerm type);
+ QueryTerm(std::unique_ptr<QueryNodeResultBase> resultBase, const string & term, const string & index, Type type);
QueryTerm(const QueryTerm &);
QueryTerm & operator = (const QueryTerm &);
QueryTerm(QueryTerm &&) noexcept;
diff --git a/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.cpp b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.cpp
index 68d2dc5472b..02b1063cc37 100644
--- a/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.cpp
+++ b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.cpp
@@ -55,7 +55,7 @@ GlobalId dummy_gid(uint32_t doc_index) {
}
std::unique_ptr<QueryTermSimple> word_term(vespalib::stringref term) {
- return std::make_unique<QueryTermSimple>(term, QueryTermSimple::WORD);
+ return std::make_unique<QueryTermSimple>(term, QueryTermSimple::Type::WORD);
}
diff --git a/vsm/src/tests/searcher/searcher_test.cpp b/vsm/src/tests/searcher/searcher_test.cpp
index 87bbefa6c06..e8753a43397 100644
--- a/vsm/src/tests/searcher/searcher_test.cpp
+++ b/vsm/src/tests/searcher/searcher_test.cpp
@@ -21,6 +21,7 @@ using search::streaming::HitList;
using search::streaming::QueryNodeResultFactory;
using search::streaming::QueryTerm;
using search::streaming::QueryTermList;
+using TermType = QueryTerm::Type;
using namespace vsm;
template <typename T>
@@ -66,7 +67,7 @@ private:
}
public:
typedef std::pair<std::string, std::string> ParsedQueryTerm;
- typedef std::pair<std::string, QueryTerm::SearchTerm> ParsedTerm;
+ typedef std::pair<std::string, TermType> ParsedTerm;
QueryNodeResultFactory eqnr;
std::vector<QueryTerm> qtv;
QueryTermList qtl;
@@ -81,13 +82,13 @@ public:
}
static ParsedTerm parseTerm(const std::string & term) {
if (term[0] == '*' && term[term.size() - 1] == '*') {
- return std::make_pair(term.substr(1, term.size() - 2), QueryTerm::SUBSTRINGTERM);
+ return std::make_pair(term.substr(1, term.size() - 2), TermType::SUBSTRINGTERM);
} else if (term[0] == '*') {
- return std::make_pair(term.substr(1, term.size() - 1), QueryTerm::SUFFIXTERM);
+ return std::make_pair(term.substr(1, term.size() - 1), TermType::SUFFIXTERM);
} else if (term[term.size() - 1] == '*') {
- return std::make_pair(term.substr(0, term.size() - 1), QueryTerm::PREFIXTERM);
+ return std::make_pair(term.substr(0, term.size() - 1), TermType::PREFIXTERM);
} else {
- return std::make_pair(term, QueryTerm::WORD);
+ return std::make_pair(term, TermType::WORD);
}
}
};
@@ -95,7 +96,7 @@ public:
Query::Query(const StringList & terms) : eqnr(), qtv(), qtl() {
setupQuery(terms);
}
-Query::~Query() {}
+Query::~Query() = default;
struct SnippetModifierSetup
{
@@ -284,8 +285,8 @@ bool
assertMatchTermSuffix(const std::string & term, const std::string & word)
{
QueryNodeResultFactory eqnr;
- QueryTerm qa(eqnr.create(), term, "index", QueryTerm::WORD);
- QueryTerm qb(eqnr.create(), word, "index", QueryTerm::WORD);
+ QueryTerm qa(eqnr.create(), term, "index", TermType::WORD);
+ QueryTerm qb(eqnr.create(), word, "index", TermType::WORD);
const ucs4_t * a;
size_t alen = qa.term(a);
const ucs4_t * b;
@@ -467,13 +468,13 @@ testStrChrFieldSearcher(StrChrFieldSearcher & fs)
ASSERT_TRUE(Query::parseQueryTerm("term").first == "");
ASSERT_TRUE(Query::parseQueryTerm("term").second == "term");
ASSERT_TRUE(Query::parseTerm("*substr*").first == "substr");
- ASSERT_TRUE(Query::parseTerm("*substr*").second == QueryTerm::SUBSTRINGTERM);
+ ASSERT_TRUE(Query::parseTerm("*substr*").second == TermType::SUBSTRINGTERM);
ASSERT_TRUE(Query::parseTerm("*suffix").first == "suffix");
- ASSERT_TRUE(Query::parseTerm("*suffix").second == QueryTerm::SUFFIXTERM);
+ ASSERT_TRUE(Query::parseTerm("*suffix").second == TermType::SUFFIXTERM);
ASSERT_TRUE(Query::parseTerm("prefix*").first == "prefix");
- ASSERT_TRUE(Query::parseTerm("prefix*").second == QueryTerm::PREFIXTERM);
+ ASSERT_TRUE(Query::parseTerm("prefix*").second == TermType::PREFIXTERM);
ASSERT_TRUE(Query::parseTerm("term").first == "term");
- ASSERT_TRUE(Query::parseTerm("term").second == QueryTerm::WORD);
+ ASSERT_TRUE(Query::parseTerm("term").second == TermType::WORD);
}
TEST("suffix matching") {