/// <summary> /// Initiates the asynchronous execution of the Search operation. /// <seealso cref="Amazon.CloudSearchDomain.IAmazonCloudSearchDomain"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the Search operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task<SearchResponse> SearchAsync(SearchRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new SearchRequestMarshaller(); var unmarshaller = SearchResponseUnmarshaller.Instance; return InvokeAsync<SearchRequest,SearchResponse>(request, marshaller, unmarshaller, cancellationToken); }
internal SearchResponse Search(SearchRequest request) { var task = SearchAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
/// <summary> /// Retrieves a list of documents that match the specified search criteria. How you specify /// the search criteria depends on which query parser you use. Amazon CloudSearch supports /// four query parsers: /// /// <ul> <li> <code>simple</code>: search all <code>text</code> and <code>text-array</code> /// fields for the specified string. Search for phrases, individual terms, and prefixes. /// </li> <li> <code>structured</code>: search specific fields, construct compound queries /// using Boolean operators, and use advanced features such as term boosting and proximity /// searching.</li> <li> <code>lucene</code>: specify search criteria using the Apache /// Lucene query parser syntax.</li> <li> <code>dismax</code>: specify search criteria /// using the simplified subset of the Apache Lucene query parser syntax defined by the /// DisMax query parser.</li> </ul> /// <para> /// For more information, see <a href="http://docs.aws.amazon.com/cloudsearch/latest/developerguide/searching.html">Searching /// Your Data</a> in the <i>Amazon CloudSearch Developer Guide</i>. /// </para> /// /// <para> /// The endpoint for submitting <code>Search</code> requests is domain-specific. You submit /// search requests to a domain's search endpoint. To get the search endpoint for your /// domain, use the Amazon CloudSearch configuration service <code>DescribeDomains</code> /// action. A domain's endpoints are also displayed on the domain dashboard in the Amazon /// CloudSearch console. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the Search service method.</param> /// /// <returns>The response from the Search service method, as returned by CloudSearchDomain.</returns> /// <exception cref="SearchException"> /// Information about any problems encountered while processing a search request. /// </exception> public SearchResponse Search(SearchRequest request) { var marshaller = new SearchRequestMarshaller(); var unmarshaller = SearchResponseUnmarshaller.Instance; return Invoke<SearchRequest,SearchResponse>(request, marshaller, unmarshaller); }
public IResultSet Search(ISearchQuery query) { AmazonCloudSearchDomainConfig config = new AmazonCloudSearchDomainConfig(); config.ServiceURL = "http://search-index2-cdduimbipgk3rpnfgny6posyzy.eu-west-1.cloudsearch.amazonaws.com/"; AmazonCloudSearchDomainClient domainClient = new AmazonCloudSearchDomainClient("AKIAJ6MPIX37TLIXW7HQ", "DnrFrw9ZEr7g4Svh0rh6z+s3PxMaypl607eEUehQ", config); SearchRequest searchRequest = new SearchRequest(); List<string> suggestions = new List<string>(); StringBuilder highlights = new StringBuilder(); highlights.Append("{\'"); if (query == null) throw new ArgumentNullException("query"); foreach (var field in query.HighlightedFields) { if (highlights.Length > 2) { highlights.Append(", \'"); } highlights.Append(field.ToUpperInvariant()); highlights.Append("\':{} "); SuggestRequest suggestRequest = new SuggestRequest(); Suggester suggester = new Suggester(); suggester.SuggesterName = field.ToUpperInvariant() + "_suggester"; suggestRequest.Suggester = suggester.SuggesterName; suggestRequest.Size = query.Take; suggestRequest.Query = query.Text; SuggestResponse suggestion = domainClient.Suggest(suggestRequest); foreach (var suggest in suggestion.Suggest.Suggestions) { suggestions.Add(suggest.Suggestion); } } highlights.Append("}"); if (query.Filter != null) { searchRequest.FilterQuery = this.BuildQueryFilter(query.Filter); } if (query.OrderBy != null) { searchRequest.Sort = string.Join(",", query.OrderBy); } if (query.Take > 0) { searchRequest.Size = query.Take; } if (query.Skip > 0) { searchRequest.Start = query.Skip; } searchRequest.Highlight = highlights.ToString(); searchRequest.Query = query.Text; searchRequest.QueryParser = QueryParser.Simple; var result = domainClient.Search(searchRequest).SearchResult; return new AmazonResultSet(result, suggestions); }
private Amazon.CloudSearchDomain.Model.SearchResponse CallAWSServiceOperation(IAmazonCloudSearchDomain client, Amazon.CloudSearchDomain.Model.SearchRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon CloudSearchDomain", "Search"); try { #if DESKTOP return(client.Search(request)); #elif CORECLR return(client.SearchAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
/// <summary> /// Initiates the asynchronous execution of the Search operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the Search operation on AmazonCloudSearchDomainClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndSearch /// operation.</returns> public IAsyncResult BeginSearch(SearchRequest request, AsyncCallback callback, object state) { var marshaller = new SearchRequestMarshaller(); var unmarshaller = SearchResponseUnmarshaller.Instance; return BeginInvoke<SearchRequest>(request, marshaller, unmarshaller, callback, state); }
/// <summary> /// Retrieves a list of documents that match the specified search criteria. How you specify /// the search criteria depends on which query parser you use. Amazon CloudSearch supports /// four query parsers: /// /// <ul> <li><code>simple</code>: search all <code>text</code> and <code>text-array</code> /// fields for the specified string. Search for phrases, individual terms, and prefixes. /// </li> <li><code>structured</code>: search specific fields, construct compound /// queries using Boolean operators, and use advanced features such as term boosting and /// proximity searching.</li> <li><code>lucene</code>: specify search criteria /// using the Apache Lucene query parser syntax.</li> <li><code>dismax</code>: /// specify search criteria using the simplified subset of the Apache Lucene query parser /// syntax defined by the DisMax query parser.</li> </ul> /// <para> /// For more information, see <a href="http://docs.aws.amazon.com/cloudsearch/latest/developerguide/searching.html">Searching /// Your Data</a> in the <i>Amazon CloudSearch Developer Guide</i>. /// </para> /// /// <para> /// The endpoint for submitting <code>Search</code> requests is domain-specific. You submit /// search requests to a domain's search endpoint. To get the search endpoint for your /// domain, use the Amazon CloudSearch configuration service <code>DescribeDomains</code> /// action. A domain's endpoints are also displayed on the domain dashboard in the Amazon /// CloudSearch console. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the Search service method.</param> /// /// <returns>The response from the Search service method, as returned by CloudSearchDomain.</returns> /// <exception cref="SearchException"> /// Information about any problems encountered while processing a search request. /// </exception> public SearchResponse Search(SearchRequest request) { IAsyncResult asyncResult = invokeSearch(request, null, null, true); return EndSearch(asyncResult); }
IAsyncResult invokeSearch(SearchRequest request, AsyncCallback callback, object state, bool synchronized) { var marshaller = new SearchRequestMarshaller(); var unmarshaller = SearchResponseUnmarshaller.Instance; return Invoke(request, callback, state, synchronized, marshaller, unmarshaller, signer); }
/// <summary> /// Initiates the asynchronous execution of the Search operation. /// <seealso cref="Amazon.CloudSearchDomain.IAmazonCloudSearchDomain"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the Search operation on AmazonCloudSearchDomainClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndSearch /// operation.</returns> public IAsyncResult BeginSearch(SearchRequest request, AsyncCallback callback, object state) { return invokeSearch(request, callback, state, false); }
/// <summary> /// Retrieving suggestions using a custom implementation. This implementation assumes a 'literal' /// field type to be used as source for suggestions. This field must have lowercase values. /// Optionally an alternate display field can be provided which can be used populate the result. /// This implementation returns similar results as the AWS CloudSearch Suggester when populate the /// suggest field with the same value field as display field (but in lowercase). /// </summary> /// <param name="parameters">Suggest request parameters</param> /// <param name="suggestFieldName">Name of the suggest field</param> /// <param name="displayFieldName">Name of the display field</param> /// <returns>SuggestResults</returns> public SuggestResults RetieveFilteredSuggestions(NameValueCollection parameters, string suggestFieldName, string displayFieldName = null) { SuggestResults suggestResults = new SuggestResults(); try { AmazonCloudSearchDomainClient client = GetCloudSearchClient(); SearchRequest request = new SearchRequest(); if (parameters["q"] != null) { request.QueryParser = QueryParser.Structured; request.Query = String.Format("(prefix field={0} '{1}')", suggestFieldName, parameters["q"].ToLower()); } if (displayFieldName == null) { request.Facet = String.Format("{{'{0}':{{'sort':'bucket'}}}}", suggestFieldName); request.Return = "_no_fields"; } else { request.Return = displayFieldName; request.Sort = String.Format("{0} asc", displayFieldName); } if (!String.IsNullOrEmpty(parameters["fq"])) { string filters = string.Empty; foreach (string filterString in parameters["fq"].Split(',')) { if (filterString.Contains(":")) { filters += (String.Format(" {0}:'{1}'", filterString.Split(':')[0], filterString.Split(':')[1])); } } request.FilterQuery = String.Format("(and{0})", filters); } request.Size = parameters["size"] != null ? Convert.ToInt32(parameters["size"]) : this.DefaultPageSize; SearchResponse response = client.Search(request); if (displayFieldName == null) { if (response.Facets.Count > 0) { suggestResults.Matches = response.Facets[suggestFieldName].Buckets.Select(b => b.Value).ToList(); } } else { if (response.Hits.Hit.Count > 0) { suggestResults.Matches = response.Hits.Hit.Select(h => h.Fields[displayFieldName].FirstOrDefault()).ToList(); } } } catch (Exception ex) { suggestResults.HasError = true; suggestResults.ErrorDetail = ex.Message + " : " + ex.StackTrace; } return suggestResults; }