-
Notifications
You must be signed in to change notification settings - Fork 582
/
search_service.search.js
242 lines (232 loc) · 10.2 KB
/
search_service.search.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// Copyright 2024 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
//
// https://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.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **
'use strict';
function main(servingConfig) {
// [START discoveryengine_v1_generated_SearchService_Search_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
* Required. The resource name of the Search serving config, such as
* `projects/* /locations/global/collections/default_collection/engines/* /servingConfigs/default_serving_config`,
* or
* `projects/* /locations/global/collections/default_collection/dataStores/default_data_store/servingConfigs/default_serving_config`.
* This field is used to identify the serving configuration name, set
* of models used to make the search.
*/
// const servingConfig = 'abc123'
/**
* The branch resource name, such as
* `projects/* /locations/global/collections/default_collection/dataStores/default_data_store/branches/0`.
* Use `default_branch` as the branch ID or leave this field empty, to search
* documents under the default branch.
*/
// const branch = 'abc123'
/**
* Raw search query.
*/
// const query = 'abc123'
/**
* Raw image query.
*/
// const imageQuery = {}
/**
* Maximum number of Document google.cloud.discoveryengine.v1.Document s to
* return. The maximum allowed value depends on the data type. Values above
* the maximum value are coerced to the maximum value.
* * Websites with basic indexing: Default `10`, Maximum `25`.
* * Websites with advanced indexing: Default `25`, Maximum `50`.
* * Other: Default `50`, Maximum `100`.
* If this field is negative, an `INVALID_ARGUMENT` is returned.
*/
// const pageSize = 1234
/**
* A page token received from a previous
* SearchService.Search google.cloud.discoveryengine.v1.SearchService.Search
* call. Provide this to retrieve the subsequent page.
* When paginating, all other parameters provided to
* SearchService.Search google.cloud.discoveryengine.v1.SearchService.Search
* must match the call that provided the page token. Otherwise, an
* `INVALID_ARGUMENT` error is returned.
*/
// const pageToken = 'abc123'
/**
* A 0-indexed integer that specifies the current offset (that is, starting
* result location, amongst the
* Document google.cloud.discoveryengine.v1.Document s deemed by the API as
* relevant) in search results. This field is only considered if
* page_token google.cloud.discoveryengine.v1.SearchRequest.page_token is
* unset.
* If this field is negative, an `INVALID_ARGUMENT` is returned.
*/
// const offset = 1234
/**
* Specs defining dataStores to filter on in a search call and configurations
* for those dataStores. This is only considered for engines with multiple
* dataStores use case. For single dataStore within an engine, they should
* use the specs at the top level.
*/
// const dataStoreSpecs = [1,2,3,4]
/**
* The filter syntax consists of an expression language for constructing a
* predicate from one or more fields of the documents being filtered. Filter
* expression is case-sensitive.
* If this field is unrecognizable, an `INVALID_ARGUMENT` is returned.
* Filtering in Vertex AI Search is done by mapping the LHS filter key to a
* key property defined in the Vertex AI Search backend -- this mapping is
* defined by the customer in their schema. For example a media customer might
* have a field 'name' in their schema. In this case the filter would look
* like this: filter --> name:'ANY("king kong")'
* For more information about filtering including syntax and filter
* operators, see
* Filter (https://cloud.google.com/generative-ai-app-builder/docs/filter-search-metadata)
*/
// const filter = 'abc123'
/**
* The default filter that is applied when a user performs a search without
* checking any filters on the search page.
* The filter applied to every search request when quality improvement such as
* query expansion is needed. In the case a query does not have a sufficient
* amount of results this filter will be used to determine whether or not to
* enable the query expansion flow. The original filter will still be used for
* the query expanded search.
* This field is strongly recommended to achieve high search quality.
* For more information about filter syntax, see
* SearchRequest.filter google.cloud.discoveryengine.v1.SearchRequest.filter.
*/
// const canonicalFilter = 'abc123'
/**
* The order in which documents are returned. Documents can be ordered by
* a field in an Document google.cloud.discoveryengine.v1.Document object.
* Leave it unset if ordered by relevance. `order_by` expression is
* case-sensitive.
* For more information on ordering for retail search, see
* Ordering (https://cloud.google.com/retail/docs/filter-and-order#order)
* If this field is unrecognizable, an `INVALID_ARGUMENT` is returned.
*/
// const orderBy = 'abc123'
/**
* Information about the end user.
* Highly recommended for analytics.
* UserInfo.user_agent google.cloud.discoveryengine.v1.UserInfo.user_agent
* is used to deduce `device_type` for analytics.
*/
// const userInfo = {}
/**
* Facet specifications for faceted search. If empty, no facets are returned.
* A maximum of 100 values are allowed. Otherwise, an `INVALID_ARGUMENT`
* error is returned.
*/
// const facetSpecs = [1,2,3,4]
/**
* Boost specification to boost certain documents.
* For more information on boosting, see
* Boosting (https://cloud.google.com/generative-ai-app-builder/docs/boost-search-results)
*/
// const boostSpec = {}
/**
* Additional search parameters.
* For public website search only, supported values are:
* * `user_country_code`: string. Default empty. If set to non-empty, results
* are restricted or boosted based on the location provided.
* For example, `user_country_code: "au"`
* For available codes see Country
* Codes (https://developers.google.com/custom-search/docs/json_api_reference#countryCodes)
* * `search_type`: double. Default empty. Enables non-webpage searching
* depending on the value. The only valid non-default value is 1,
* which enables image searching.
* For example, `search_type: 1`
*/
// const params = [1,2,3,4]
/**
* The query expansion specification that specifies the conditions under which
* query expansion occurs.
*/
// const queryExpansionSpec = {}
/**
* The spell correction specification that specifies the mode under
* which spell correction takes effect.
*/
// const spellCorrectionSpec = {}
/**
* A unique identifier for tracking visitors. For example, this could be
* implemented with an HTTP cookie, which should be able to uniquely identify
* a visitor on a single device. This unique identifier should not change if
* the visitor logs in or out of the website.
* This field should NOT have a fixed value such as `unknown_visitor`.
* This should be the same identifier as
* UserEvent.user_pseudo_id google.cloud.discoveryengine.v1.UserEvent.user_pseudo_id
* and
* CompleteQueryRequest.user_pseudo_id google.cloud.discoveryengine.v1.CompleteQueryRequest.user_pseudo_id
* The field must be a UTF-8 encoded string with a length limit of 128
* characters. Otherwise, an `INVALID_ARGUMENT` error is returned.
*/
// const userPseudoId = 'abc123'
/**
* A specification for configuring the behavior of content search.
*/
// const contentSearchSpec = {}
/**
* Whether to turn on safe search. This is only supported for
* website search.
*/
// const safeSearch = true
/**
* The user labels applied to a resource must meet the following requirements:
* * Each resource can have multiple labels, up to a maximum of 64.
* * Each label must be a key-value pair.
* * Keys have a minimum length of 1 character and a maximum length of 63
* characters and cannot be empty. Values can be empty and have a maximum
* length of 63 characters.
* * Keys and values can contain only lowercase letters, numeric characters,
* underscores, and dashes. All characters must use UTF-8 encoding, and
* international characters are allowed.
* * The key portion of a label must be unique. However, you can use the same
* key with multiple resources.
* * Keys must start with a lowercase letter or international character.
* See Google Cloud
* Document (https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements)
* for more details.
*/
// const userLabels = [1,2,3,4]
// Imports the Discoveryengine library
const {SearchServiceClient} = require('@google-cloud/discoveryengine').v1;
// Instantiates a client
const discoveryengineClient = new SearchServiceClient();
async function callSearch() {
// Construct request
const request = {
servingConfig,
};
// Run request
const iterable = discoveryengineClient.searchAsync(request);
for await (const response of iterable) {
console.log(response);
}
}
callSearch();
// [END discoveryengine_v1_generated_SearchService_Search_async]
}
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));