1// Copyright 2019 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 15syntax = "proto2"; 16 17package icing.lib; 18 19import "icing/proto/status.proto"; 20import "icing/proto/term.proto"; 21 22option java_package = "com.google.android.icing.proto"; 23option java_multiple_files = true; 24option objc_class_prefix = "ICNG"; 25 26// Defines the schema that every Document of a specific "type" should adhere 27// to. These can be considered as definitions of rich structured types for 28// Documents accepted by IcingSearchEngine. 29// 30// NOTE: Instances of SchemaTypeConfigProto are strongly recommended to be 31// based on types defined in schema.org. This makes the data/config/code more 32// shareable and easier to extend in the future. 33// 34// TODO(cassiewang) Define a sample proto file that can be used by tests and for 35// documentation. 36// 37// Next tag: 6 38message SchemaTypeConfigProto { 39 // REQUIRED: Named type that uniquely identifies the structured, logical 40 // schema being defined. 41 // 42 // Recommended format: Human readable string that's one of the types defined 43 // in http://schema.org. Eg: DigitalDocument, Message, Person, etc. 44 optional string schema_type = 1; 45 46 // List of all properties that are supported by Documents of this type. 47 // An Document should never have properties that are not listed here. 48 // 49 // TODO(cassiewang) Figure out if we should disallow, ignore or accept 50 // unknown properties. Accepting them could make switching between versions 51 // easier. 52 repeated PropertyConfigProto properties = 4; 53 54 // Version is an arbitrary number that the client may use to keep track of 55 // different incarnations of the schema. Icing library imposes no requirements 56 // on this field and will not validate it in anyway. If a client calls 57 // SetSchema with a schema that contains one or more new version numbers, then 58 // those version numbers will be updated so long as the SetSchema call 59 // succeeds. Clients are free to leave the version number unset, in which case 60 // it will default to value == 0. 61 optional int32 version = 5; 62 63 reserved 2, 3; 64} 65 66// Describes how a string property should be indexed. 67// Next tag: 3 68message StringIndexingConfig { 69 // Indicates how the content of this property should be matched in the index. 70 // 71 // TermMatchType.Code=UNKNOWN 72 // Content in this property will not be tokenized or indexed. Useful if the 73 // data type is not indexable. See schema-util for details. 74 // 75 // TermMatchType.Code=EXACT_ONLY 76 // Content in this property should only be returned for queries matching the 77 // exact tokens appearing in this property. 78 // Ex. A property with "fool" should NOT match a query for "foo". 79 // 80 // TermMatchType.Code=PREFIX 81 // Content in this property should be returned for queries that are either 82 // exact matches or query matches of the tokens appearing in this property. 83 // Ex. A property with "fool" *should* match a query for "foo". 84 optional TermMatchType.Code term_match_type = 1; 85 86 message TokenizerType { 87 enum Code { 88 // It is only valid for tokenizer_type to be 'NONE' if the data type is 89 // not indexed. 90 NONE = 0; 91 92 // Tokenization for plain text. 93 PLAIN = 1; 94 } 95 } 96 optional TokenizerType.Code tokenizer_type = 2; 97} 98 99// Describes how a document property should be indexed. 100// Next tag: 2 101message DocumentIndexingConfig { 102 // OPTIONAL: Whether nested properties within the document property should be 103 // indexed. If true, then the nested properties will be indexed according to 104 // the property's own indexing configurations. If false, nested documents' 105 // properties will not be indexed even if they have an indexing configuration. 106 // 107 // The default value is false. 108 optional bool index_nested_properties = 1; 109} 110 111// Describes the schema of a single property of Documents that belong to a 112// specific SchemaTypeConfigProto. These can be considered as a rich, structured 113// type for each property of Documents accepted by IcingSearchEngine. 114// Next tag: 7 115message PropertyConfigProto { 116 // REQUIRED: Name that uniquely identifies a property within an Document of 117 // a specific SchemaTypeConfigProto. 118 // 119 // Recommended format: Human readable string that's one of the properties 120 // defined in schema.org for the parent SchemaTypeConfigProto. 121 // Eg: 'author' for http://schema.org/DigitalDocument. 122 // Eg: 'address' for http://schema.org/Place. 123 optional string property_name = 1; 124 125 // REQUIRED: Physical data-types of the contents of the property. 126 message DataType { 127 enum Code { 128 // This value should never purposely be used. This is used for backwards 129 // compatibility reasons. 130 UNKNOWN = 0; 131 132 STRING = 1; 133 INT64 = 2; 134 DOUBLE = 3; 135 BOOLEAN = 4; 136 137 // Unstructured BLOB. 138 BYTES = 5; 139 140 // Indicates that the property itself is an Document, making it part 141 // a hierarchical Document schema. Any property using this data_type 142 // MUST have a valid 'schema_type'. 143 DOCUMENT = 6; 144 } 145 } 146 optional DataType.Code data_type = 2; 147 148 // REQUIRED if (data_type == DOCUMENT). OPTIONAL otherwise. 149 // Indicates the logical schema-type of the contents of this property. 150 // 151 // TODO(cassiewang): This could be useful for non-document properties, e.g. 152 // to set this field as a schema.org/address for some string property. 153 // Re-evaluate what recommendation we should give clients if we want to start 154 // using this for non-document properties as well. 155 // 156 // Recommended format: Human readable string that is one of the types defined 157 // in schema.org, matching the SchemaTypeConfigProto.schema_type of another 158 // type. 159 optional string schema_type = 3; 160 161 // REQUIRED: The cardinality of the property. 162 message Cardinality { 163 // NOTE: The order of the cardinality is purposefully set to be from least 164 // restrictive (REPEATED) to most restrictive (REQUIRED). This makes it 165 // easier to check if a field is backwards compatible by doing a simple 166 // greater-than/less-than check on the enum ints. Changing/adding new 167 // cardinalities should be done cautiously. 168 enum Code { 169 // This should never purposely be set. This is used for backwards 170 // compatibility reasons. 171 UNKNOWN = 0; 172 173 // Any number of items (including zero) [0...*]. 174 REPEATED = 1; 175 176 // Zero or one value [0,1]. 177 OPTIONAL = 2; 178 179 // Exactly one value [1]. 180 REQUIRED = 3; 181 } 182 } 183 optional Cardinality.Code cardinality = 4; 184 185 // OPTIONAL: Describes how string properties should be indexed. String 186 // properties that do not set the indexing config will not be indexed. 187 optional StringIndexingConfig string_indexing_config = 5; 188 189 // OPTIONAL: Describes how document properties should be indexed. 190 optional DocumentIndexingConfig document_indexing_config = 6; 191} 192 193// List of all supported types constitutes the schema used by Icing. 194// Next tag: 2 195message SchemaProto { 196 repeated SchemaTypeConfigProto types = 1; 197} 198 199// Result of a call to IcingSearchEngine.SetSchema 200// Next tag: 4 201message SetSchemaResultProto { 202 // Status code can be one of: 203 // OK 204 // INVALID_ARGUMENT 205 // FAILED_PRECONDITION 206 // INTERNAL 207 // 208 // See status.proto for more details. 209 // 210 // TODO(b/147699081): Fix error codes: +ABORTED, +WARNING_DATA_LOSS, 211 // -INTERNAL. go/icing-library-apis. 212 optional StatusProto status = 1; 213 214 // Schema types that existed in the previous schema, but were deleted from the 215 // new schema. If ignore_errors_and_delete_documents=true, then all documents 216 // of these types were also deleted. 217 repeated string deleted_schema_types = 2; 218 219 // Schema types that existed in the previous schema and were incompatible with 220 // the new schema type. If ignore_errors_and_delete_documents=true, then any 221 // documents that fail validation against the new schema types would also be 222 // deleted. 223 repeated string incompatible_schema_types = 3; 224} 225 226// Result of a call to IcingSearchEngine.GetSchema 227// Next tag: 3 228message GetSchemaResultProto { 229 // Status code can be one of: 230 // OK 231 // FAILED_PRECONDITION 232 // NOT_FOUND 233 // INTERNAL 234 // 235 // See status.proto for more details. 236 // 237 // TODO(b/147699081): Fix error codes: +ABORTED, -INTERNAL 238 // go/icing-library-apis. 239 optional StatusProto status = 1; 240 241 // Copy of the Schema proto. Modifying this does not affect the Schema that 242 // IcingSearchEngine holds. 243 optional SchemaProto schema = 2; 244} 245 246// Result of a call to IcingSearchEngine.GetSchemaType 247// Next tag: 3 248message GetSchemaTypeResultProto { 249 // Status code can be one of: 250 // OK 251 // FAILED_PRECONDITION 252 // NOT_FOUND 253 // INTERNAL 254 // 255 // See status.proto for more details. 256 // 257 // TODO(b/147699081): Fix error codes: +ABORTED, -INTERNAL 258 // go/icing-library-apis. 259 optional StatusProto status = 1; 260 261 // Copy of the SchemaTypeConfig proto with the specified schema_type. 262 // Modifying this does not affect the SchemaTypeConfig that IcingSearchEngine 263 // holds. 264 optional SchemaTypeConfigProto schema_type_config = 2; 265} 266