1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package cloudsearchdomain
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	"github.com/aws/aws-sdk-go-v2/service/cloudsearchdomain/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Retrieves a list of documents that match the specified search criteria. How you
15// specify the search criteria depends on which query parser you use. Amazon
16// CloudSearch supports four query parsers:
17//
18// * simple: search all text and
19// text-array fields for the specified string. Search for phrases, individual
20// terms, and prefixes.
21//
22// * structured: search specific fields, construct compound
23// queries using Boolean operators, and use advanced features such as term boosting
24// and proximity searching.
25//
26// * lucene: specify search criteria using the Apache
27// Lucene query parser syntax.
28//
29// * dismax: specify search criteria using the
30// simplified subset of the Apache Lucene query parser syntax defined by the DisMax
31// query parser.
32//
33// For more information, see Searching Your Data
34// (http://docs.aws.amazon.com/cloudsearch/latest/developerguide/searching.html) in
35// the Amazon CloudSearch Developer Guide. The endpoint for submitting Search
36// requests is domain-specific. You submit search requests to a domain's search
37// endpoint. To get the search endpoint for your domain, use the Amazon CloudSearch
38// configuration service DescribeDomains action. A domain's endpoints are also
39// displayed on the domain dashboard in the Amazon CloudSearch console.
40func (c *Client) Search(ctx context.Context, params *SearchInput, optFns ...func(*Options)) (*SearchOutput, error) {
41	if params == nil {
42		params = &SearchInput{}
43	}
44
45	result, metadata, err := c.invokeOperation(ctx, "Search", params, optFns, addOperationSearchMiddlewares)
46	if err != nil {
47		return nil, err
48	}
49
50	out := result.(*SearchOutput)
51	out.ResultMetadata = metadata
52	return out, nil
53}
54
55// Container for the parameters to the Search request.
56type SearchInput struct {
57
58	// Specifies the search criteria for the request. How you specify the search
59	// criteria depends on the query parser used for the request and the parser options
60	// specified in the queryOptions parameter. By default, the simple query parser is
61	// used to process requests. To use the structured, lucene, or dismax query parser,
62	// you must also specify the queryParser parameter. For more information about
63	// specifying search criteria, see Searching Your Data
64	// (http://docs.aws.amazon.com/cloudsearch/latest/developerguide/searching.html) in
65	// the Amazon CloudSearch Developer Guide.
66	//
67	// This member is required.
68	Query *string
69
70	// Retrieves a cursor value you can use to page through large result sets. Use the
71	// size parameter to control the number of hits to include in each response. You
72	// can specify either the cursor or start parameter in a request; they are mutually
73	// exclusive. To get the first cursor, set the cursor value to initial. In
74	// subsequent requests, specify the cursor value returned in the hits section of
75	// the response. For more information, see Paginating Results
76	// (http://docs.aws.amazon.com/cloudsearch/latest/developerguide/paginating-results.html)
77	// in the Amazon CloudSearch Developer Guide.
78	Cursor *string
79
80	// Defines one or more numeric expressions that can be used to sort results or
81	// specify search or filter criteria. You can also specify expressions as return
82	// fields. You specify the expressions in JSON using the form
83	// {"EXPRESSIONNAME":"EXPRESSION"}. You can define and use multiple expressions in
84	// a search request. For example:  {"expression1":"_score*rating",
85	// "expression2":"(1/rank)*year"}  For information about the variables, operators,
86	// and functions you can use in expressions, see Writing Expressions
87	// (http://docs.aws.amazon.com/cloudsearch/latest/developerguide/configuring-expressions.html#writing-expressions)
88	// in the Amazon CloudSearch Developer Guide.
89	Expr *string
90
91	// Specifies one or more fields for which to get facet information, and options
92	// that control how the facet information is returned. Each specified field must be
93	// facet-enabled in the domain configuration. The fields and options are specified
94	// in JSON using the form
95	// {"FIELD":{"OPTION":VALUE,"OPTION:"STRING"},"FIELD":{"OPTION":VALUE,"OPTION":"STRING"}}.
96	// You can specify the following faceting options:
97	//
98	// * buckets specifies an array of
99	// the facet values or ranges to count. Ranges are specified using the same syntax
100	// that you use to search for a range of values. For more information, see
101	// Searching for a Range of Values
102	// (http://docs.aws.amazon.com/cloudsearch/latest/developerguide/searching-ranges.html)
103	// in the Amazon CloudSearch Developer Guide. Buckets are returned in the order
104	// they are specified in the request. The sort and size options are not valid if
105	// you specify buckets.
106	//
107	// * size specifies the maximum number of facets to include
108	// in the results. By default, Amazon CloudSearch returns counts for the top 10.
109	// The size parameter is only valid when you specify the sort option; it cannot be
110	// used in conjunction with buckets.
111	//
112	// * sort specifies how you want to sort the
113	// facets in the results: bucket or count. Specify bucket to sort alphabetically or
114	// numerically by facet value (in ascending order). Specify count to sort by the
115	// facet counts computed for each facet value (in descending order). To retrieve
116	// facet counts for particular values or ranges of values, use the buckets option
117	// instead of sort.
118	//
119	// If no facet options are specified, facet counts are computed
120	// for all field values, the facets are sorted by facet count, and the top 10
121	// facets are returned in the results. To count particular buckets of values, use
122	// the buckets option. For example, the following request uses the buckets option
123	// to calculate and return facet counts by decade.
124	// {"year":{"buckets":["[1970,1979]","[1980,1989]","[1990,1999]","[2000,2009]","[2010,}"]}}
125	// To sort facets by facet count, use the count option. For example, the following
126	// request sets the sort option to count to sort the facet values by facet count,
127	// with the facet values that have the most matching documents listed first.
128	// Setting the size option to 3 returns only the top three facet values.
129	// {"year":{"sort":"count","size":3}}  To sort the facets by value, use the bucket
130	// option. For example, the following request sets the sort option to bucket to
131	// sort the facet values numerically by year, with earliest year listed first.
132	// {"year":{"sort":"bucket"}}  For more information, see Getting and Using Facet
133	// Information
134	// (http://docs.aws.amazon.com/cloudsearch/latest/developerguide/faceting.html) in
135	// the Amazon CloudSearch Developer Guide.
136	Facet *string
137
138	// Specifies a structured query that filters the results of a search without
139	// affecting how the results are scored and sorted. You use filterQuery in
140	// conjunction with the query parameter to filter the documents that match the
141	// constraints specified in the query parameter. Specifying a filter controls only
142	// which matching documents are included in the results, it has no effect on how
143	// they are scored and sorted. The filterQuery parameter supports the full
144	// structured query syntax. For more information about using filters, see Filtering
145	// Matching Documents
146	// (http://docs.aws.amazon.com/cloudsearch/latest/developerguide/filtering-results.html)
147	// in the Amazon CloudSearch Developer Guide.
148	FilterQuery *string
149
150	// Retrieves highlights for matches in the specified text or text-array fields.
151	// Each specified field must be highlight enabled in the domain configuration. The
152	// fields and options are specified in JSON using the form
153	// {"FIELD":{"OPTION":VALUE,"OPTION:"STRING"},"FIELD":{"OPTION":VALUE,"OPTION":"STRING"}}.
154	// You can specify the following highlight options:
155	//
156	// * format: specifies the format
157	// of the data in the text field: text or html. When data is returned as HTML, all
158	// non-alphanumeric characters are encoded. The default is html.
159	//
160	// * max_phrases:
161	// specifies the maximum number of occurrences of the search term(s) you want to
162	// highlight. By default, the first occurrence is highlighted.
163	//
164	// * pre_tag:
165	// specifies the string to prepend to an occurrence of a search term. The default
166	// for HTML highlights is <em>. The default for text highlights is *.
167	//
168	// * post_tag:
169	// specifies the string to append to an occurrence of a search term. The default
170	// for HTML highlights is </em>. The default for text highlights is *.
171	//
172	// If no
173	// highlight options are specified for a field, the returned field text is treated
174	// as HTML and the first match is highlighted with emphasis tags:
175	// <em>search-term</em>. For example, the following request retrieves highlights
176	// for the actors and title fields. { "actors": {}, "title": {"format":
177	// "text","max_phrases": 2,"pre_tag": "","post_tag": ""} }
178	Highlight *string
179
180	// Enables partial results to be returned if one or more index partitions are
181	// unavailable. When your search index is partitioned across multiple search
182	// instances, by default Amazon CloudSearch only returns results if every partition
183	// can be queried. This means that the failure of a single search instance can
184	// result in 5xx (internal server) errors. When you enable partial results, Amazon
185	// CloudSearch returns whatever results are available and includes the percentage
186	// of documents searched in the search results (percent-searched). This enables you
187	// to more gracefully degrade your users' search experience. For example, rather
188	// than displaying no results, you could display the partial results and a message
189	// indicating that the results might be incomplete due to a temporary system
190	// outage.
191	Partial bool
192
193	// Configures options for the query parser specified in the queryParser parameter.
194	// You specify the options in JSON using the following form
195	// {"OPTION1":"VALUE1","OPTION2":VALUE2"..."OPTIONN":"VALUEN"}. The options you can
196	// configure vary according to which parser you use:
197	//
198	// * defaultOperator: The
199	// default operator used to combine individual terms in the search string. For
200	// example: defaultOperator: 'or'. For the dismax parser, you specify a percentage
201	// that represents the percentage of terms in the search string (rounded down) that
202	// must match, rather than a default operator. A value of 0% is the equivalent to
203	// OR, and a value of 100% is equivalent to AND. The percentage must be specified
204	// as a value in the range 0-100 followed by the percent (%) symbol. For example,
205	// defaultOperator: 50%. Valid values: and, or, a percentage in the range 0%-100%
206	// (dismax). Default: and (simple, structured, lucene) or 100 (dismax). Valid for:
207	// simple, structured, lucene, and dismax.
208	//
209	// * fields: An array of the fields to
210	// search when no fields are specified in a search. If no fields are specified in a
211	// search and this option is not specified, all text and text-array fields are
212	// searched. You can specify a weight for each field to control the relative
213	// importance of each field when Amazon CloudSearch calculates relevance scores. To
214	// specify a field weight, append a caret (^) symbol and the weight to the field
215	// name. For example, to boost the importance of the title field over the
216	// description field you could specify: "fields":["title^5","description"]. Valid
217	// values: The name of any configured field and an optional numeric value greater
218	// than zero. Default: All text and text-array fields. Valid for: simple,
219	// structured, lucene, and dismax.
220	//
221	// * operators: An array of the operators or
222	// special characters you want to disable for the simple query parser. If you
223	// disable the and, or, or not operators, the corresponding operators (+, |, -)
224	// have no special meaning and are dropped from the search string. Similarly,
225	// disabling prefix disables the wildcard operator (*) and disabling phrase
226	// disables the ability to search for phrases by enclosing phrases in double
227	// quotes. Disabling precedence disables the ability to control order of precedence
228	// using parentheses. Disabling near disables the ability to use the ~ operator to
229	// perform a sloppy phrase search. Disabling the fuzzy operator disables the
230	// ability to use the ~ operator to perform a fuzzy search. escape disables the
231	// ability to use a backslash (</code>) to escape special characters within the
232	// search string. Disabling whitespace is an advanced option that prevents the
233	// parser from tokenizing on whitespace, which can be useful for Vietnamese. (It
234	// prevents Vietnamese words from being split incorrectly.) For example, you could
235	// disable all operators other than the phrase operator to support just simple term
236	// and phrase queries: "operators":["and","not","or", "prefix"]. Valid values: and,
237	// escape, fuzzy, near, not, or, phrase, precedence, prefix, whitespace. Default:
238	// All operators and special characters are enabled. Valid for: simple.
239	//
240	// *
241	// phraseFields: An array of the text or text-array fields you want to use for
242	// phrase searches. When the terms in the search string appear in close proximity
243	// within a field, the field scores higher. You can specify a weight for each field
244	// to boost that score. The phraseSlop option controls how much the matches can
245	// deviate from the search string and still be boosted. To specify a field weight,
246	// append a caret (^) symbol and the weight to the field name. For example, to
247	// boost phrase matches in the title field over the abstract field, you could
248	// specify: "phraseFields":["title^3", "plot"] Valid values: The name of any text
249	// or text-array field and an optional numeric value greater than zero. Default: No
250	// fields. If you don't specify any fields with phraseFields, proximity scoring is
251	// disabled even if phraseSlop is specified. Valid for: dismax.
252	//
253	// * phraseSlop: An
254	// integer value that specifies how much matches can deviate from the search phrase
255	// and still be boosted according to the weights specified in the phraseFields
256	// option; for example, phraseSlop: 2. You must also specify phraseFields to enable
257	// proximity scoring. Valid values: positive integers. Default: 0. Valid for:
258	// dismax.
259	//
260	// * explicitPhraseSlop: An integer value that specifies how much a match
261	// can deviate from the search phrase when the phrase is enclosed in double quotes
262	// in the search string. (Phrases that exceed this proximity distance are not
263	// considered a match.) For example, to specify a slop of three for dismax phrase
264	// queries, you would specify "explicitPhraseSlop":3. Valid values: positive
265	// integers. Default: 0. Valid for: dismax.
266	//
267	// * tieBreaker: When a term in the
268	// search string is found in a document's field, a score is calculated for that
269	// field based on how common the word is in that field compared to other documents.
270	// If the term occurs in multiple fields within a document, by default only the
271	// highest scoring field contributes to the document's overall score. You can
272	// specify a tieBreaker value to enable the matches in lower-scoring fields to
273	// contribute to the document's score. That way, if two documents have the same max
274	// field score for a particular term, the score for the document that has matches
275	// in more fields will be higher. The formula for calculating the score with a
276	// tieBreaker is (max field score) + (tieBreaker) * (sum of the scores for the rest
277	// of the matching fields). Set tieBreaker to 0 to disregard all but the highest
278	// scoring field (pure max): "tieBreaker":0. Set to 1 to sum the scores from all
279	// fields (pure sum): "tieBreaker":1. Valid values: 0.0 to 1.0. Default: 0.0. Valid
280	// for: dismax.
281	QueryOptions *string
282
283	// Specifies which query parser to use to process the request. If queryParser is
284	// not specified, Amazon CloudSearch uses the simple query parser. Amazon
285	// CloudSearch supports four query parsers:
286	//
287	// * simple: perform simple searches of
288	// text and text-array fields. By default, the simple query parser searches all
289	// text and text-array fields. You can specify which fields to search by with the
290	// queryOptions parameter. If you prefix a search term with a plus sign (+)
291	// documents must contain the term to be considered a match. (This is the default,
292	// unless you configure the default operator with the queryOptions parameter.) You
293	// can use the - (NOT), | (OR), and * (wildcard) operators to exclude particular
294	// terms, find results that match any of the specified terms, or search for a
295	// prefix. To search for a phrase rather than individual terms, enclose the phrase
296	// in double quotes. For more information, see Searching for Text
297	// (http://docs.aws.amazon.com/cloudsearch/latest/developerguide/searching-text.html)
298	// in the Amazon CloudSearch Developer Guide.
299	//
300	// * structured: perform advanced
301	// searches by combining multiple expressions to define the search criteria. You
302	// can also search within particular fields, search for values and ranges of
303	// values, and use advanced options such as term boosting, matchall, and near. For
304	// more information, see Constructing Compound Queries
305	// (http://docs.aws.amazon.com/cloudsearch/latest/developerguide/searching-compound-queries.html)
306	// in the Amazon CloudSearch Developer Guide.
307	//
308	// * lucene: search using the Apache
309	// Lucene query parser syntax. For more information, see Apache Lucene Query Parser
310	// Syntax
311	// (http://lucene.apache.org/core/4_6_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package_description).
312	//
313	// *
314	// dismax: search using the simplified subset of the Apache Lucene query parser
315	// syntax defined by the DisMax query parser. For more information, see DisMax
316	// Query Parser Syntax
317	// (http://wiki.apache.org/solr/DisMaxQParserPlugin#Query_Syntax).
318	QueryParser types.QueryParser
319
320	// Specifies the field and expression values to include in the response. Multiple
321	// fields or expressions are specified as a comma-separated list. By default, a
322	// search response includes all return enabled fields (_all_fields). To return only
323	// the document IDs for the matching documents, specify _no_fields. To retrieve the
324	// relevance score calculated for each document, specify _score.
325	Return *string
326
327	// Specifies the maximum number of search hits to include in the response.
328	Size int64
329
330	// Specifies the fields or custom expressions to use to sort the search results.
331	// Multiple fields or expressions are specified as a comma-separated list. You must
332	// specify the sort direction (asc or desc) for each field; for example, year
333	// desc,title asc. To use a field to sort results, the field must be sort-enabled
334	// in the domain configuration. Array type fields cannot be used for sorting. If no
335	// sort parameter is specified, results are sorted by their default relevance
336	// scores in descending order: _score desc. You can also sort by document ID (_id
337	// asc) and version (_version desc). For more information, see Sorting Results
338	// (http://docs.aws.amazon.com/cloudsearch/latest/developerguide/sorting-results.html)
339	// in the Amazon CloudSearch Developer Guide.
340	Sort *string
341
342	// Specifies the offset of the first search hit you want to return. Note that the
343	// result set is zero-based; the first result is at index 0. You can specify either
344	// the start or cursor parameter in a request, they are mutually exclusive. For
345	// more information, see Paginating Results
346	// (http://docs.aws.amazon.com/cloudsearch/latest/developerguide/paginating-results.html)
347	// in the Amazon CloudSearch Developer Guide.
348	Start int64
349
350	// Specifies one or more fields for which to get statistics information. Each
351	// specified field must be facet-enabled in the domain configuration. The fields
352	// are specified in JSON using the form: {"FIELD-A":{},"FIELD-B":{}} There are
353	// currently no options supported for statistics.
354	Stats *string
355}
356
357// The result of a Search request. Contains the documents that match the specified
358// search criteria and any requested fields, highlights, and facet information.
359type SearchOutput struct {
360
361	// The requested facet information.
362	Facets map[string]types.BucketInfo
363
364	// The documents that match the search criteria.
365	Hits *types.Hits
366
367	// The requested field statistics information.
368	Stats map[string]types.FieldStats
369
370	// The status information returned for the search request.
371	Status *types.SearchStatus
372
373	// Metadata pertaining to the operation's result.
374	ResultMetadata middleware.Metadata
375}
376
377func addOperationSearchMiddlewares(stack *middleware.Stack, options Options) (err error) {
378	err = stack.Serialize.Add(&awsRestjson1_serializeOpSearch{}, middleware.After)
379	if err != nil {
380		return err
381	}
382	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpSearch{}, middleware.After)
383	if err != nil {
384		return err
385	}
386	if err = addSetLoggerMiddleware(stack, options); err != nil {
387		return err
388	}
389	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
390		return err
391	}
392	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
393		return err
394	}
395	if err = addResolveEndpointMiddleware(stack, options); err != nil {
396		return err
397	}
398	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
399		return err
400	}
401	if err = addRetryMiddlewares(stack, options); err != nil {
402		return err
403	}
404	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
405		return err
406	}
407	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
408		return err
409	}
410	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
411		return err
412	}
413	if err = addClientUserAgent(stack); err != nil {
414		return err
415	}
416	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
417		return err
418	}
419	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
420		return err
421	}
422	if err = addOpSearchValidationMiddleware(stack); err != nil {
423		return err
424	}
425	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSearch(options.Region), middleware.Before); err != nil {
426		return err
427	}
428	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
429		return err
430	}
431	if err = addResponseErrorMiddleware(stack); err != nil {
432		return err
433	}
434	if err = addRequestResponseLogging(stack, options); err != nil {
435		return err
436	}
437	return nil
438}
439
440func newServiceMetadataMiddleware_opSearch(region string) *awsmiddleware.RegisterServiceMetadata {
441	return &awsmiddleware.RegisterServiceMetadata{
442		Region:        region,
443		ServiceID:     ServiceID,
444		SigningName:   "cloudsearch",
445		OperationName: "Search",
446	}
447}
448