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/logging.proto";
20import "icing/proto/status.proto";
21
22option java_package = "com.google.android.icing.proto";
23option java_multiple_files = true;
24option objc_class_prefix = "ICNG";
25
26// Defines a unit of data understood by the IcingSearchEngine.
27// Next tag: 10
28message DocumentProto {
29  // REQUIRED: Namespace that this Document resides in.
30  // Namespaces can affect read/write permissions.
31  optional string namespace = 1;
32
33  // REQUIRED: Identifier of the Document; must be unique within the
34  // Document's `namespace`. Otherwise, the new Document will override any
35  // other Documents with the same `namespace`+`uri` that Icing knows about.
36  optional string uri = 2;
37
38  // REQUIRED: Type of the Document. This should match the 'schema_type' of
39  // one of the types given to Icing as part of the overall schema.
40  // See icing.lib.SchemaTypeConfigProto.schema_type for details.
41  optional string schema = 3;
42
43  // OPTIONAL: Seconds since epoch at which the Document was created.
44  // Negative values will lead to validation errors. If not specified, it will
45  // default to when the Icing receives the Document.
46  optional int64 creation_timestamp_ms = 4;
47
48  // REQUIRED: Properties that will be validated against the provided schema.
49  // The names of these properties should map to one of the properties
50  // already defined in the schema for this Document's schema_type.
51  repeated PropertyProto properties = 5;
52
53  // OPTIONAL: Score of the document which could be used during search result
54  // ranking. Negative values will lead to validation errors. The default is the
55  // lowest score 0.
56  optional int32 score = 7 [default = 0];
57
58  // The time-to-live that should be enforced on this Document. Documents get
59  // garbage-collected once the current time exceeds the ttl_ms after the
60  // creation_timestamp_ms. Negative values will lead to validation errors.
61  //
62  // Default value of 0 keeps the Documents till they're explicitly deleted.
63  //
64  // TODO(cassiewang): Benchmark if fixed64 or some other proto type is better
65  // in terms of space/time efficiency. Both for ttl_ms and timestamp fields
66  optional int64 ttl_ms = 8 [default = 0];
67
68  // Defines document level data that's generated internally by Icing.
69  message InternalFields {
70    // The length of the document as a count of tokens (or terms) in all indexed
71    // text properties. This field is used in the computation of BM25F relevance
72    // score.
73    optional int32 length_in_tokens = 1;
74  }
75  optional InternalFields internal_fields = 9;
76
77  reserved 6;
78}
79
80// Holds a property field of the Document.
81// Next tag: 8
82message PropertyProto {
83  // Name of the property.
84  // See icing.lib.PropertyConfigProto.property_name for details.
85  optional string name = 1;
86
87  // Only the field corresponding to the DataType specified in
88  // icing.lib.PropertyConfigProto.data_type should be set.
89  repeated string string_values = 2;
90  repeated int64 int64_values = 3;
91  repeated double double_values = 4;
92  repeated bool boolean_values = 5;
93  repeated bytes bytes_values = 6;
94  repeated DocumentProto document_values = 7;
95}
96
97// Result of a call to IcingSearchEngine.Put
98// Next tag: 3
99message PutResultProto {
100  // Status code can be one of:
101  //   OK
102  //   FAILED_PRECONDITION
103  //   NOT_FOUND
104  //   INTERNAL
105  //   OUT_OF_SPACE
106  //
107  // See status.proto for more details.
108  //
109  // TODO(b/147699081): Fix error codes: +ABORTED
110  // go/icing-library-apis.
111  optional StatusProto status = 1;
112
113  // Stats of the function call. Inside PutDocumentStatsProto, the function
114  // call latency 'latency_ms' will always be populated. The other fields will
115  // be accurate only when the status above is OK. See logging.proto for
116  // details.
117  optional PutDocumentStatsProto put_document_stats = 2;
118}
119
120// Result of a call to IcingSearchEngine.Get
121// Next tag: 3
122message GetResultProto {
123  // Status code can be one of:
124  //   OK
125  //   FAILED_PRECONDITION
126  //   NOT_FOUND
127  //   INTERNAL
128  //
129  // See status.proto for more details.
130  //
131  // TODO(b/147699081): Fix error codes: +ABORTED, -INTERNAL.
132  // go/icing-library-apis.
133  optional StatusProto status = 1;
134
135  // Copy of the Document proto with the specified name_space, uri. Modifying
136  // this does not affect the Document in IcingSearchEngine.
137  optional DocumentProto document = 2;
138}
139
140// Result of a call to IcingSearchEngine.GetAllNamespaces
141// Next tag: 3
142message GetAllNamespacesResultProto {
143  // Status code can be one of:
144  //   OK
145  //
146  // See status.proto for more details.
147  optional StatusProto status = 1;
148
149  // List of namespaces which have at least one existing document in it (not
150  // deleted and not expired). Order of namespaces is undefined.
151  repeated string namespaces = 2;
152}
153
154// Result of a call to IcingSearchEngine.Delete
155// Next tag: 3
156message DeleteResultProto {
157  // Status code can be one of:
158  //   OK
159  //   FAILED_PRECONDITION
160  //   NOT_FOUND
161  //   INTERNAL
162  //
163  // See status.proto for more details.
164  //
165  // TODO(b/147699081): Fix error codes: +ABORTED.
166  // go/icing-library-apis.
167  optional StatusProto status = 1;
168
169  // Stats for delete execution performance.
170  optional DeleteStatsProto delete_stats = 2;
171}
172
173// Result of a call to IcingSearchEngine.DeleteByNamespace
174// Next tag: 3
175message DeleteByNamespaceResultProto {
176  // Status code can be one of:
177  //   OK
178  //   FAILED_PRECONDITION
179  //   NOT_FOUND
180  //   INTERNAL
181  //
182  // See status.proto for more details.
183  //
184  // TODO(b/147699081): Fix error codes: +ABORTED.
185  // go/icing-library-apis.
186  optional StatusProto status = 1;
187
188  // Stats for delete execution performance.
189  optional DeleteStatsProto delete_stats = 2;
190}
191
192// Result of a call to IcingSearchEngine.DeleteBySchemaType
193// Next tag: 3
194message DeleteBySchemaTypeResultProto {
195  // Status code can be one of:
196  //   OK
197  //   FAILED_PRECONDITION
198  //   NOT_FOUND
199  //   INTERNAL
200  //
201  // See status.proto for more details.
202  //
203  // TODO(b/147699081): Fix error codes: +ABORTED.
204  // go/icing-library-apis.
205  optional StatusProto status = 1;
206
207  // Stats for delete execution performance.
208  optional DeleteStatsProto delete_stats = 2;
209}
210
211// Result of a call to IcingSearchEngine.DeleteByQuery
212// Next tag: 3
213message DeleteByQueryResultProto {
214  // Status code can be one of:
215  //   OK
216  //   FAILED_PRECONDITION
217  //   NOT_FOUND
218  //   INTERNAL
219  //
220  // See status.proto for more details.
221  //
222  // TODO(b/147699081): Fix error codes: +ABORTED.
223  // go/icing-library-apis.
224  optional StatusProto status = 1;
225
226  // Stats for delete execution performance.
227  optional DeleteStatsProto delete_stats = 2;
228}
229