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(getEmbeddingParameter(0), 0.5, 1, "COSINE")`.
57 //
58 // Deprecated: This feature is not necessary. The availability of this feature
59 // is already controlled by the existence of the embedding_query_vectors in the
60 // SearchSpecProto. This API was never publicly released in Jetpack or Android,
61 // so it should be safe to delete once all google3 references are removed.
62 constexpr Feature kEmbeddingSearchFeatureDeprecated =
63 "EMBEDDING_SEARCH"; // Features#EMBEDDING_SEARCH
64
65 // This feature relates to the use of the
66 // "matchScoreExpression(scoring_expression, low, high)" function.
67 //
68 // Features#MATCH_SCORE_EXPRESSION_FUNCTION
69 constexpr Feature kMatchScoreExpressionFunctionFeature =
70 "MATCH_SCORE_EXPRESSION_FUNCTION";
71
GetQueryFeaturesSet()72 inline std::unordered_set<Feature> GetQueryFeaturesSet() {
73 return {kNumericSearchFeature,
74 kVerbatimSearchFeature,
75 kListFilterQueryLanguageFeature,
76 kHasPropertyFunctionFeature,
77 kEmbeddingSearchFeatureDeprecated,
78 kMatchScoreExpressionFunctionFeature};
79 }
80
81 } // namespace lib
82 } // namespace icing
83
84 #endif // ICING_QUERY_QUERY_FEATURES_H_
85