1 // Copyright (C) 2022 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef ICING_QUERY_QUERY_FEATURES_H_
16 #define ICING_QUERY_QUERY_FEATURES_H_
17
18 #include <string_view>
19 #include <unordered_set>
20
21 namespace icing {
22 namespace lib {
23
24 // A feature used in a query.
25 // All feature values here must be kept in sync with its counterpart in:
26 // androidx-main/frameworks/support/appsearch/appsearch/src/main/java/androidx/appsearch/app/Features.java
27 using Feature = std::string_view;
28
29 // This feature relates to the use of the numeric comparison operators in the
30 // advanced query language. Ex. `price < 10`.
31 constexpr Feature kNumericSearchFeature =
32 "NUMERIC_SEARCH"; // Features#NUMERIC_SEARCH
33
34 // This feature relates to the use of the STRING terminal in the advanced query
35 // language. Ex. `"foo?bar"` is treated as a single term - `foo?bar`.
36 constexpr Feature kVerbatimSearchFeature =
37 "VERBATIM_SEARCH"; // Features#VERBATIM_SEARCH
38
39 // This feature covers all additions (other than numeric search and verbatim
40 // search) to the query language to bring it into better alignment with the list
41 // filters spec.
42 // This includes:
43 // - support for function calls
44 // - expanding support for negation and property restriction expressions
45 // - prefix operator '*'
46 // - 'NOT' operator
47 // - propertyDefined("url")
48 constexpr Feature kListFilterQueryLanguageFeature =
49 "LIST_FILTER_QUERY_LANGUAGE"; // Features#LIST_FILTER_QUERY_LANGUAGE
50
51 // This feature relates to the use of the "hasProperty(property_path)" function.
52 constexpr Feature kHasPropertyFunctionFeature =
53 "HAS_PROPERTY_FUNCTION"; // Features#HAS_PROPERTY_FUNCTION
54
55 // This feature relates to the use of embedding searches in the advanced query
56 // language. Ex. `semanticSearch(getSearchSpecEmbedding(0), 0.5, 1, "COSINE")`.
57 constexpr Feature kEmbeddingSearchFeature =
58 "EMBEDDING_SEARCH"; // Features#EMBEDDING_SEARCH
59
60 // This feature relates to the use of the tokenize function which returns an
61 // iterator that ANDs all of the normalized tokens in its string.
62 // Ex. `tokenize("foo.bar\" baz(")`.
63 constexpr Feature kTokenizeFeature = "TOKENIZE"; // Features#TOKENIZE
64
GetQueryFeaturesSet()65 inline std::unordered_set<Feature> GetQueryFeaturesSet() {
66 return {kNumericSearchFeature, kVerbatimSearchFeature,
67 kListFilterQueryLanguageFeature, kHasPropertyFunctionFeature,
68 kEmbeddingSearchFeature, kTokenizeFeature};
69 }
70
71 } // namespace lib
72 } // namespace icing
73
74 #endif // ICING_QUERY_QUERY_FEATURES_H_
75