1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "uri_field.h"
#include <cassert>
namespace search::index {
UriField::UriField()
: _all(Schema::UNKNOWN_FIELD_ID),
_scheme(Schema::UNKNOWN_FIELD_ID),
_host(Schema::UNKNOWN_FIELD_ID),
_port(Schema::UNKNOWN_FIELD_ID),
_path(Schema::UNKNOWN_FIELD_ID),
_query(Schema::UNKNOWN_FIELD_ID),
_fragment(Schema::UNKNOWN_FIELD_ID),
_hostname(Schema::UNKNOWN_FIELD_ID)
{
}
bool
UriField::valid(const Schema &schema, uint32_t fieldId, const Schema::CollectionType &collectionType)
{
if (fieldId == Schema::UNKNOWN_FIELD_ID) {
return false;
}
const Schema::IndexField &field = schema.getIndexField(fieldId);
if (field.getDataType() != schema::DataType::STRING) {
return false;
}
if (field.getCollectionType() != collectionType) {
return false;
}
return true;
}
bool
UriField::broken(const Schema &schema, const Schema::CollectionType & collectionType) const
{
return !valid(schema, _all, collectionType) &&
valid(schema, _scheme, collectionType) &&
valid(schema, _host, collectionType) &&
valid(schema, _port, collectionType) &&
valid(schema, _path, collectionType) &&
valid(schema, _query, collectionType) &&
valid(schema, _fragment, collectionType);
}
bool
UriField::valid(const Schema &schema, const Schema::CollectionType & collectionType) const
{
return valid(schema, _all, collectionType) &&
valid(schema, _scheme, collectionType) &&
valid(schema, _host, collectionType) &&
valid(schema, _port, collectionType) &&
valid(schema, _path, collectionType) &&
valid(schema, _query, collectionType) &&
valid(schema, _fragment, collectionType);
}
void
UriField::setup(const Schema &schema, const vespalib::string &field)
{
_all = schema.getIndexFieldId(field);
_scheme = schema.getIndexFieldId(field + ".scheme");
_host = schema.getIndexFieldId(field + ".host");
_port = schema.getIndexFieldId(field + ".port");
_path = schema.getIndexFieldId(field + ".path");
_query = schema.getIndexFieldId(field + ".query");
_fragment = schema.getIndexFieldId(field + ".fragment");
_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)
{
if (field == Schema::UNKNOWN_FIELD_ID) {
return;
}
assert(usedFields.size() > field);
usedFields[field] = true;
}
void
UriField::markUsed(UsedFieldsMap &usedFields) const
{
markUsed(usedFields, _all);
markUsed(usedFields, _scheme);
markUsed(usedFields, _host);
markUsed(usedFields, _port);
markUsed(usedFields, _path);
markUsed(usedFields, _query);
markUsed(usedFields, _fragment);
markUsed(usedFields, _hostname);
}
}
|