Import platform/external/icing
source_repository_url: "user/adorokhine/icing-search-ag"
source_branch: "staging"
source_tip_commit: "67ceaa1d6b6d7da5fa5ed3512ada340c2060250e"
target_repository_name: "platform/external/icing"
Bug: 145010258
Change-Id: I948c0d7979563d688ba08c13614ab6a54ad3a7ff
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/.gitignore
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..654a071
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,28 @@
+# How to Contribute
+
+We'd love to accept your patches and contributions to this project. There are
+just a few small guidelines you need to follow.
+
+## Contributor License Agreement
+
+Contributions to this project must be accompanied by a Contributor License
+Agreement. You (or your employer) retain the copyright to your contribution;
+this simply gives us permission to use and redistribute your contributions as
+part of the project. Head over to <https://cla.developers.google.com/> to see
+your current agreements on file or to sign a new one.
+
+You generally only need to submit a CLA once, so if you've already submitted one
+(even if it was for a different project), you probably don't need to do it
+again.
+
+## Code reviews
+
+All submissions, including submissions by project members, require review. We
+use GitHub pull requests for this purpose. Consult
+[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
+information on using pull requests.
+
+## Community Guidelines
+
+This project follows [Google's Open Source Community
+Guidelines](https://opensource.google/conduct/).
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..fc01d33
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,18 @@
+name: "Icing Search Library"
+description:
+ "Icing is a fast, embedded, mobile-friendly full-text-search library "
+ "written in C++."
+
+third_party {
+ url {
+ type: HOMEPAGE
+ value: "https://github.com/google/icing-search"
+ }
+ url {
+ type: GIT
+ value: "https://github.com/google/icing-search.git"
+ }
+ version: "6ac7095a212a01dd0d25e39843bb593486625370"
+ last_upgrade_date { year: 2019 month: 10 day: 31 }
+ license_type: NOTICE
+}
diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_APACHE2
diff --git a/NOTICE b/NOTICE
new file mode 120000
index 0000000..7a694c9
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1 @@
+LICENSE
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..8f6df57
--- /dev/null
+++ b/README.md
@@ -0,0 +1,5 @@
+# Icing Search Library
+
+Icing is a fast, embedded, mobile-friendly full-text-search library written in C++.
+
+This is not an officially supported Google product.
diff --git a/icing/proto/document.proto b/icing/proto/document.proto
new file mode 100644
index 0000000..64c2e2b
--- /dev/null
+++ b/icing/proto/document.proto
@@ -0,0 +1,59 @@
+// Copyright 2019 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+syntax = "proto2";
+
+package icing;
+
+// Defines a unit of data understood by the IcingSearchEngine.
+// Next tag: 6
+message DocumentProto {
+ // REQUIRED: Namespace that this Document resides in.
+ // Namespaces can affect read/write permissions.
+ optional string namespace = 1;
+
+ // REQUIRED: Identifier of the Document; must be unique within the
+ // Document's `namespace`. Otherwise, the new Document will override any
+ // other Documents with the same `namespace`+`uri` that Icing knows about.
+ optional string uri = 2;
+
+ // REQUIRED: Type of the Document. This should match the 'schema_type' of
+ // one of the types given to Icing as part of the overall schema.
+ // See icing.SchemaTypeConfigProto.schema_type for details.
+ optional string schema = 3;
+
+ // Milliseconds since epoch at which the Document was created. If not
+ // specified, it will default to when the Icing receives the Document.
+ optional uint64 creation_timestamp_ms = 4;
+
+ repeated PropertyProto properties = 5;
+}
+
+// Holds a property field of the Document.
+// Next tag: 8
+message PropertyProto {
+ // Name of the property. This should be the same as one of the properties
+ // already defined in the schema for this Document's schema_type.
+ // See icing.PropertyConfigProto.property_name for details.
+ optional string name = 1;
+
+ // Only the field corresponding to the DataType specified in
+ // icing.PropertyConfigProto.data_type should be set.
+ repeated string string_values = 2;
+ repeated int64 int64_values = 3;
+ repeated double double_values = 4;
+ repeated bool boolean_values = 5;
+ repeated bytes bytes_values = 6;
+ repeated DocumentProto document_values = 7;
+}
diff --git a/icing/proto/document_wrapper.proto b/icing/proto/document_wrapper.proto
new file mode 100644
index 0000000..d17faf9
--- /dev/null
+++ b/icing/proto/document_wrapper.proto
@@ -0,0 +1,30 @@
+// Copyright 2019 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+syntax = "proto2";
+
+package icing;
+
+import "icing/proto/document.proto";
+
+// DocumentWrapper as a wrapper of the user-facing DocumentProto is meant to
+// be used by icing team internally. It stores the original document provided
+// by library users and metadata of the document which shouldn't be exposed to
+// library users.
+message DocumentWrapper {
+ optional DocumentProto document = 1;
+
+ // Indicates if the document is marked as deleted
+ optional bool deleted = 2;
+}
diff --git a/icing/proto/icing-search-engine-options.proto b/icing/proto/icing-search-engine-options.proto
new file mode 100644
index 0000000..f3b98dc
--- /dev/null
+++ b/icing/proto/icing-search-engine-options.proto
@@ -0,0 +1,70 @@
+// Copyright 2019 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+syntax = "proto2";
+
+package icing;
+
+// Next tag: 6
+message IcingSearchEngineOptions {
+ // Directory to persist files for Icing. Required.
+ // If Icing was previously initialized with this directory, it will reload
+ // the index saved by the last instance.
+ optional string base_dir = 1;
+
+ // File path to the LangId language segmentation model for the library to use.
+ // Required.
+ optional string lang_model_path = 2;
+
+ // The maximum number of tokens to be allowed per document. If a document
+ // exceeds this number of tokens, then only the first max_tokens_per_doc
+ // will be indexed.
+ //
+ // Clients may use this value to prevent the possibility of a select few
+ // documents from exhausting limits in the index that are shared between all
+ // documents (ie max allowed index size).
+ //
+ // Valid values: [1, INT_MAX], Current default is 1/5 of the default of
+ // max_document_size.
+ // Optional.
+ optional int32 max_tokens_per_doc = 3 [default = 13107];
+
+ // The maximum allowable token length. All tokens in excess of this size
+ // will be truncated to max_token_length before being indexed.
+ //
+ // Clients may use this option to prevent unnecessary indexing of long tokens.
+ // Depending on the use case, indexing all of
+ // 'Supercalifragilisticexpialidocious' may be unnecessary - a user is
+ // unlikely to type that entire query. So only indexing the first n bytes may
+ // still provide the desired behavior without wasting resources.
+ //
+ // Valid values: [1, INT_MAX]
+ // Optional.
+ optional int32 max_token_length = 4 [default = 30];
+
+ // The size (measured in bytes) at which Icing's internal indices should be
+ // merged. Icing buffers changes together before merging them into a more
+ // compact format. When the buffer exceeds index_merge_size during a Put
+ // operation, the buffer is merged into the larger, more compact index.
+ //
+ // This more compact index is more efficient to search over as the index
+ // grows larger and has smaller system health impact.
+ //
+ // Setting a low index_merge_size increases the frequency of merges -
+ // increasing indexing-time latency and flash wear. Setting a high
+ // index_merge_size leads to larger resource usage and higher query latency.
+ // Valid values: [1, INT_MAX]
+ // Optional.
+ optional int32 index_merge_size = 5 [default = 1048576]; // 1 MiB
+}
diff --git a/icing/proto/schema.proto b/icing/proto/schema.proto
new file mode 100644
index 0000000..b0a6788
--- /dev/null
+++ b/icing/proto/schema.proto
@@ -0,0 +1,176 @@
+// Copyright 2019 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+syntax = "proto2";
+
+package icing;
+
+import "icing/proto/term.proto";
+
+// Defines the schema that every Document of a specific "type" should adhere
+// to. These can be considered as definitions of rich structured types for
+// Documents accepted by IcingSearchEngine.
+//
+// NOTE: Instances of SchemaTypeConfigProto are strongly recommended to be
+// based on types defined in schema.org. This makes the data/config/code more
+// shareable and easier to extend in the future.
+//
+// TODO(cassiewang) Define a sample proto file that can be used by tests and for
+// documentation.
+//
+// Next tag: 5
+message SchemaTypeConfigProto {
+ // REQUIRED: Named type that uniquely identifies the structured, logical
+ // schema being defined.
+ //
+ // Recommended format: Human readable string that's one of the types defined
+ // in http://schema.org. Eg: DigitalDocument, Message, Person, etc.
+ optional string schema_type = 1;
+
+ // The time-to-live that should be enforced on every Document of this type.
+ // Documents get garbage-collected based on their creation-timestamp and the
+ // TTL of the schema they belong to.
+ //
+ // Default value of 0 keeps the Documents till they're explicitly deleted.
+ optional int64 ttl_secs = 3;
+
+ // List of all properties that are supported by Documents of this type.
+ // An Document should never have properties that are not listed here.
+ //
+ // TODO(cassiewang) Figure out if we should disallow, ignore or accept
+ // unknown properties. Accepting them could make switching between versions
+ // easier.
+ repeated PropertyConfigProto properties = 4;
+
+ reserved 2;
+}
+
+// Describes how a single property should be indexed.
+// Next tag: 3
+message IndexingConfig {
+ // Indicates how the content of this property should be matched in the index.
+ //
+ // TermMatchType.Code=UNKNOWN
+ // Content in this section will not be tokenized or indexed. Useful if the
+ // data type is not made up of terms (e.g. DOCUMENT or BYTES type). All the
+ // properties inside the nested property won't be indexed regardless of the
+ // value of the term_match_type field for the nested properties.
+ //
+ // TermMatchType.Code=EXACT_ONLY
+ // Content in this section should only be returned for queries matching the
+ // exact tokens appearing in this section.
+ // Ex. A section with "fool" should NOT match a query for "foo".
+ //
+ // TermMatchType.Code=PREFIX
+ // Content in this section should be returned for queries that are either
+ // exact matches or query matches of the tokens appearing in this section.
+ // Ex. A section with "fool" *should* match a query for "foo".
+ optional TermMatchType.Code term_match_type = 1;
+
+ message TokenizerType {
+ enum Code {
+ // It is only valid for tokenizer_type to be 'NONE' if either indexed is
+ // also 'NONE' or the data type is DOCUMENT.
+ NONE = 0;
+
+ // Tokenization for plain text.
+ PLAIN = 1;
+ }
+ }
+ optional TokenizerType.Code tokenizer_type = 2;
+}
+
+// Describes the schema of a single property of Documents that belong to a
+// specific SchemaTypeConfigProto. These can be considered as a rich, structured
+// type for each property of Documents accepted by IcingSearchEngine.
+// Next tag: 6
+message PropertyConfigProto {
+ // REQUIRED: Name that uniquely identifies a property within an Document of
+ // a specific SchemaTypeConfigProto.
+ //
+ // Recommended format: Human readable string that's one of the properties
+ // defined in schema.org for the parent SchemaTypeConfigProto.
+ // Eg: 'author' for http://schema.org/DigitalDocument.
+ // Eg: 'address' for http://schema.org/Place.
+ optional string property_name = 1;
+
+ // REQUIRED: Physical data-types of the contents of the property.
+ message DataType {
+ enum Code {
+ // This should never purposely be set. This is used for backwards
+ // compatibility reasons.
+ UNKNOWN = 0;
+ STRING = 1;
+ INT64 = 2;
+ DOUBLE = 3;
+ BOOLEAN = 4;
+
+ // Unstructured BLOB.
+ BYTES = 5;
+
+ // Indicates that the property itself is an Document, making it part
+ // a hierarchical Document schema. Any property using this data_type
+ // MUST have a valid 'schema_type'.
+ DOCUMENT = 6;
+ }
+ }
+ optional DataType.Code data_type = 2;
+
+ // REQUIRED if (data_type == DOCUMENT). OPTIONAL otherwise.
+ // Indicates the logical schema-type of the contents of this property.
+ //
+ // TODO(cassiewang): This could be useful for non-document properties, e.g.
+ // to set this field as a schema.org/address for some string property.
+ // Re-evaluate what recommendation we should give clients if we want to start
+ // using this for non-document properties as well.
+ //
+ // Recommended format: Human readable string that is one of the types defined
+ // in schema.org, matching the SchemaTypeConfigProto.schema_type of another
+ // type.
+ optional string schema_type = 3;
+
+ // REQUIRED: The cardinality of the property.
+ message Cardinality {
+ // NOTE: The order of the cardinality is purposefully set to be from least
+ // restrictive (REPEATED) to most restrictive (REQUIRED). This makes it
+ // easier to check if a field is backwards compatible by doing a simple
+ // greater-than/less-than check on the enum ints. Changing/adding new
+ // cardinalities should be done cautiously.
+ enum Code {
+ // This should never purposely be set. This is used for backwards
+ // compatibility reasons.
+ UNKNOWN = 0;
+
+ // Any number of items (including zero) [0...*].
+ REPEATED = 1;
+
+ // Zero or one value [0,1].
+ OPTIONAL = 2;
+
+ // Exactly one value [1].
+ REQUIRED = 3;
+ }
+ }
+ optional Cardinality.Code cardinality = 4;
+
+ // OPTIONAL: Properties that do not set the indexing config will not be
+ // indexed.
+ optional IndexingConfig indexing_config = 5;
+}
+
+// List of all supported types constitutes the schema used by Icing.
+// Next tag: 2
+message SchemaProto {
+ repeated SchemaTypeConfigProto types = 1;
+}
diff --git a/icing/proto/search.proto b/icing/proto/search.proto
new file mode 100644
index 0000000..b153de8
--- /dev/null
+++ b/icing/proto/search.proto
@@ -0,0 +1,103 @@
+// Copyright 2019 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+syntax = "proto2";
+
+package icing;
+
+import "icing/proto/document.proto";
+import "icing/proto/term.proto";
+
+// Client-supplied specifications on what documents to retrieve.
+// Next tag: 3
+message SearchSpecProto {
+ // REQUIRED: The "raw" query string that users may type. For example, "cat"
+ // will search for documents with the term cat in it.
+ optional string query = 1;
+
+ // Indicates how the query terms should match terms in the index.
+ //
+ // TermMatchType.Code=UNKNOWN
+ // Should never purposely be set and may lead to undefined behavior. This is
+ // used for backwards compatibility reasons.
+ //
+ // TermMatchType.Code=EXACT_ONLY
+ // Query terms will only match exact tokens in the index.
+ // Ex. A query term "foo" will only match indexed token "foo", and not "foot"
+ // or "football"
+ //
+ // TermMatchType.Code=PREFIX
+ // Query terms will match indexed tokens when the query term is a prefix of
+ // the token.
+ // Ex. A query term "foo" will match indexed tokens like "foo", "foot", and
+ // "football".
+ optional TermMatchType.Code term_match_type = 2;
+
+ // TODO(cassiewang): add namespace restricts
+ // TODO(cassiewang): add schema type restricts
+}
+
+// Client-supplied specifications on what to include/how to format the search
+// results.
+// Next tag: 3
+message ResultSpecProto {
+ // The maximum number of documents to return in SearchResultProto. Even if
+ // more documents have matched the SearchSpecProto, this may be used to limit
+ // the number to actually return to the client.
+ optional int32 limit = 1 [default = 10];
+
+ // Whether to collect and return debug_info in the SearchResultProto.
+ optional bool debug_info = 2;
+}
+
+// Icing lib-supplied results from a search results.
+// Next tag: 4
+message SearchResultProto {
+ // Documents that match the SearchSpecProto. Empty if there was an error.
+ repeated DocumentProto documents = 1;
+
+ // Details on what errors were encountered. Not populated if there were no
+ // errors.
+ message ErrorProto {
+ // Generic category of errors.
+ enum Status {
+ UNKNOWN = 0;
+ // TODO(cassiewang): Add more as use-cases come up
+ }
+ optional Status status = 1;
+
+ // A more descriptive message on the error. Useful during debugging
+ optional string error_message = 2;
+ }
+ optional ErrorProto error = 2;
+
+ // Various debug fields. Not populated if ResultSpecProto.debug_info = false.
+ message DebugInfoProto {
+ // The number of results that actually matched the SearchSpecProto. This is
+ // different from the number of `documents` returned since the user can
+ // set a ResultSpecProto.limit on how many results are returned to them.
+ optional uint64 num_results = 1;
+
+ // Latency to parse and execute the query, in milliseconds.
+ optional uint64 latency_ms = 2;
+
+ // The internal representation of the actual query string that was executed.
+ // This may be different from the SearchSpecProto.query if the original
+ // query was malformed.
+ optional string executed_query = 3;
+ }
+ optional DebugInfoProto debug_info = 3;
+}
+
+// TODO(cassiewang): Add a ScoringSpec.
diff --git a/icing/proto/term.proto b/icing/proto/term.proto
new file mode 100644
index 0000000..b2cffdf
--- /dev/null
+++ b/icing/proto/term.proto
@@ -0,0 +1,35 @@
+// Copyright 2019 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+syntax = "proto2";
+
+package icing;
+
+// Encapsulates the configurations on how Icing should query/index these terms.
+// Next tag: 0
+message TermMatchType {
+ // Next tag: 3
+ enum Code {
+ // A default for all other use-cases.
+ UNKNOWN = 0;
+
+ // A term is an exact term.
+ // Ex. "foot" means "foot", and is not related to "foo" or "football"
+ EXACT_ONLY = 1;
+
+ // A term is a prefix of other terms.
+ // Ex. "foo" is a prefix of "foot"
+ PREFIX = 2;
+ }
+}