summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-08-16 10:51:58 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-08-16 10:51:58 +0000
commit138b5682bf247dfdf52068b42a681ca9d8d5803d (patch)
treeeb0f1e4423597fc2944c2ac8741bcf33f8cf92e2 /searchlib
parent00b69dd91f1073a54f1f307c97693111a9ab63cb (diff)
Add and test uri detection.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/index/docbuilder/docbuilder_test.cpp41
-rw-r--r--searchlib/src/vespa/searchlib/index/uri_field.cpp26
-rw-r--r--searchlib/src/vespa/searchlib/index/uri_field.h1
3 files changed, 34 insertions, 34 deletions
diff --git a/searchlib/src/tests/index/docbuilder/docbuilder_test.cpp b/searchlib/src/tests/index/docbuilder/docbuilder_test.cpp
index 75cccb0d573..9f1027d0522 100644
--- a/searchlib/src/tests/index/docbuilder/docbuilder_test.cpp
+++ b/searchlib/src/tests/index/docbuilder/docbuilder_test.cpp
@@ -13,8 +13,7 @@ LOG_SETUP("docbuilder_test");
using namespace document;
using search::index::schema::CollectionType;
-namespace search {
-namespace index {
+namespace search::index {
namespace
{
@@ -26,15 +25,8 @@ namespace linguistics
const vespalib::string SPANTREE_NAME("linguistics");
}
-class Test : public vespalib::TestApp {
-private:
- void testBuilder();
-public:
- int Main() override;
-};
-void
-Test::testBuilder()
+TEST("test docBuilder")
{
Schema s;
s.addIndexField(Schema::IndexField("ia", schema::DataType::STRING));
@@ -415,7 +407,7 @@ Test::testBuilder()
EXPECT_EQUAL("</af>", *itr++);
EXPECT_EQUAL("</document>", *itr++);
EXPECT_TRUE(itr == lines.end());
-#if 1
+#if 0
std::cout << "onedoc xml start -----" << std::endl <<
xml << std::endl <<
"-------" << std::endl;
@@ -479,7 +471,7 @@ Test::testBuilder()
expSpans.push_back(Span(15, 9));
expSpans.push_back(Span(15, 9));
ASSERT_TRUE(expSpans == spans);
-#if 1
+#if 0
std::cout << "onedoc xml start -----" << std::endl <<
xml << std::endl <<
"-------" << std::endl;
@@ -490,18 +482,21 @@ Test::testBuilder()
}
}
-int
-Test::Main()
-{
- TEST_INIT("docbuilder_test");
-
- testBuilder();
-
- TEST_DONE();
+TEST("test if index names are valid uri parts") {
+ EXPECT_FALSE(UriField::mightBePartofUri("all"));
+ EXPECT_FALSE(UriField::mightBePartofUri("fragment"));
+ EXPECT_FALSE(UriField::mightBePartofUri(".all"));
+ EXPECT_FALSE(UriField::mightBePartofUri("all.b"));
+ EXPECT_TRUE(UriField::mightBePartofUri("b.all"));
+ EXPECT_TRUE(UriField::mightBePartofUri("b.scheme"));
+ EXPECT_TRUE(UriField::mightBePartofUri("b.host"));
+ EXPECT_TRUE(UriField::mightBePartofUri("b.port"));
+ EXPECT_TRUE(UriField::mightBePartofUri("b.hostname"));
+ EXPECT_TRUE(UriField::mightBePartofUri("b.path"));
+ EXPECT_TRUE(UriField::mightBePartofUri("b.query"));
+ EXPECT_TRUE(UriField::mightBePartofUri("b.fragment"));
}
}
-}
-
-TEST_APPHOOK(search::index::Test);
+TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/searchlib/src/vespa/searchlib/index/uri_field.cpp b/searchlib/src/vespa/searchlib/index/uri_field.cpp
index daf0e6e685e..070afc94837 100644
--- a/searchlib/src/vespa/searchlib/index/uri_field.cpp
+++ b/searchlib/src/vespa/searchlib/index/uri_field.cpp
@@ -18,9 +18,7 @@ UriField::UriField()
}
bool
-UriField::valid(const Schema &schema,
- uint32_t fieldId,
- const Schema::CollectionType &collectionType)
+UriField::valid(const Schema &schema, uint32_t fieldId, const Schema::CollectionType &collectionType)
{
if (fieldId == Schema::UNKNOWN_FIELD_ID) {
return false;
@@ -36,9 +34,7 @@ UriField::valid(const Schema &schema,
}
bool
-UriField::broken(const Schema &schema,
- const Schema::CollectionType &
- collectionType) const
+UriField::broken(const Schema &schema, const Schema::CollectionType & collectionType) const
{
return !valid(schema, _all, collectionType) &&
valid(schema, _scheme, collectionType) &&
@@ -50,9 +46,7 @@ UriField::broken(const Schema &schema,
}
bool
-UriField::valid(const Schema &schema,
- const Schema::CollectionType &
- collectionType) const
+UriField::valid(const Schema &schema, const Schema::CollectionType & collectionType) const
{
return valid(schema, _all, collectionType) &&
valid(schema, _scheme, collectionType) &&
@@ -64,8 +58,7 @@ UriField::valid(const Schema &schema,
}
void
-UriField::setup(const Schema &schema,
- const vespalib::string &field)
+UriField::setup(const Schema &schema, const vespalib::string &field)
{
_all = schema.getIndexFieldId(field);
_scheme = schema.getIndexFieldId(field + ".scheme");
@@ -77,6 +70,17 @@ UriField::setup(const Schema &schema,
_hostname = schema.getIndexFieldId(field + ".hostname");
}
+bool
+UriField::mightBePartofUri(vespalib::stringref name) {
+ size_t dotPos = name.find('.');
+ if ((dotPos != 0) && (dotPos != vespalib::string::npos)) {
+ vespalib::stringref suffix = name.substr(dotPos + 1);
+ return ((suffix == "all") || (suffix == "scheme") || (suffix == "host") || (suffix == "port") ||
+ (suffix == "path") || (suffix == "query") || (suffix == "fragment") || (suffix == "hostname"));
+ }
+ return false;
+}
+
void
UriField::markUsed(UsedFieldsMap &usedFields, uint32_t field)
{
diff --git a/searchlib/src/vespa/searchlib/index/uri_field.h b/searchlib/src/vespa/searchlib/index/uri_field.h
index 9b8e4e72b7c..70bf8c01a8c 100644
--- a/searchlib/src/vespa/searchlib/index/uri_field.h
+++ b/searchlib/src/vespa/searchlib/index/uri_field.h
@@ -35,6 +35,7 @@ public:
bool valid(const Schema &schema, const Schema::CollectionType &collectionType) const;
void setup(const Schema &schema, const vespalib::string &field);
void markUsed(UsedFieldsMap &usedFields) const;
+ static bool mightBePartofUri(vespalib::stringref name);
};
}