/// <summary> /// Initiates the asynchronous execution of the Suggest operation. /// <seealso cref="Amazon.CloudSearchDomain.IAmazonCloudSearchDomain"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the Suggest 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<SuggestResponse> SuggestAsync(SuggestRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new SuggestRequestMarshaller(); var unmarshaller = SuggestResponseUnmarshaller.Instance; return InvokeAsync<SuggestRequest,SuggestResponse>(request, marshaller, unmarshaller, cancellationToken); }
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); }
/// <summary> /// Retrieves autocomplete suggestions for a partial query string. You can use suggestions /// enable you to display likely matches before users finish typing. In Amazon CloudSearch, /// suggestions are based on the contents of a particular text field. When you request /// suggestions, Amazon CloudSearch finds all of the documents whose values in the suggester /// field start with the specified query string. The beginning of the field must match /// the query string to be considered a match. /// /// /// <para> /// For more information about configuring suggesters and retrieving suggestions, see /// <a href="http://docs.aws.amazon.com/cloudsearch/latest/developerguide/getting-suggestions.html">Getting /// Suggestions</a> in the <i>Amazon CloudSearch Developer Guide</i>. /// </para> /// /// <para> /// The endpoint for submitting <code>Suggest</code> requests is domain-specific. You /// submit suggest 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 Suggest service method.</param> /// /// <returns>The response from the Suggest service method, as returned by CloudSearchDomain.</returns> /// <exception cref="SearchException"> /// Information about any problems encountered while processing a search request. /// </exception> public SuggestResponse Suggest(SuggestRequest request) { var marshaller = new SuggestRequestMarshaller(); var unmarshaller = SuggestResponseUnmarshaller.Instance; return Invoke<SuggestRequest,SuggestResponse>(request, marshaller, unmarshaller); }
internal SuggestResponse Suggest(SuggestRequest request) { var task = SuggestAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
/// <summary> /// Initiates the asynchronous execution of the Suggest operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the Suggest 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 EndSuggest /// operation.</returns> public IAsyncResult BeginSuggest(SuggestRequest request, AsyncCallback callback, object state) { var marshaller = new SuggestRequestMarshaller(); var unmarshaller = SuggestResponseUnmarshaller.Instance; return BeginInvoke<SuggestRequest>(request, marshaller, unmarshaller, callback, state); }
IAsyncResult invokeSuggest(SuggestRequest request, AsyncCallback callback, object state, bool synchronized) { var marshaller = new SuggestRequestMarshaller(); var unmarshaller = SuggestResponseUnmarshaller.Instance; return Invoke(request, callback, state, synchronized, marshaller, unmarshaller, signer); }
/// <summary> /// Initiates the asynchronous execution of the Suggest operation. /// <seealso cref="Amazon.CloudSearchDomain.IAmazonCloudSearchDomain"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the Suggest 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 EndSuggest /// operation.</returns> public IAsyncResult BeginSuggest(SuggestRequest request, AsyncCallback callback, object state) { return invokeSuggest(request, callback, state, false); }
/// <summary> /// Retrieves autocomplete suggestions for a partial query string. You can use suggestions /// enable you to display likely matches before users finish typing. In Amazon CloudSearch, /// suggestions are based on the contents of a particular text field. When you request /// suggestions, Amazon CloudSearch finds all of the documents whose values in the suggester /// field start with the specified query string. The beginning of the field must match /// the query string to be considered a match. /// /// /// <para> /// For more information about configuring suggesters and retrieving suggestions, see /// <a href="http://docs.aws.amazon.com/cloudsearch/latest/developerguide/getting-suggestions.html">Getting /// Suggestions</a> in the <i>Amazon CloudSearch Developer Guide</i>. /// </para> /// /// <para> /// The endpoint for submitting <code>Suggest</code> requests is domain-specific. You /// submit suggest 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 Suggest service method.</param> /// /// <returns>The response from the Suggest service method, as returned by CloudSearchDomain.</returns> /// <exception cref="SearchException"> /// Information about any problems encountered while processing a search request. /// </exception> public SuggestResponse Suggest(SuggestRequest request) { IAsyncResult asyncResult = invokeSuggest(request, null, null, true); return EndSuggest(asyncResult); }
private Amazon.CloudSearchDomain.Model.SuggestResponse CallAWSServiceOperation(IAmazonCloudSearchDomain client, Amazon.CloudSearchDomain.Model.SuggestRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon CloudSearchDomain", "Suggest"); try { #if DESKTOP return(client.Suggest(request)); #elif CORECLR return(client.SuggestAsync(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> /// Retrieving suggestions using the AWS CloudSearch Suggester. The AWS CloudSearch Suggester /// returns results from the entire index and does not suport query filtering. /// </summary> /// <param name="parameters">Suggest request parameters</param> /// <returns>SuggestResults</returns> public SuggestResults RetieveSuggestions(NameValueCollection parameters) { SuggestResults suggestResults = new SuggestResults(); try { AmazonCloudSearchDomainClient client = GetCloudSearchClient(); SuggestRequest request = new SuggestRequest(); if (parameters["suggestername"] != null) { request.Suggester = parameters["suggestername"]; } if (parameters["q"] != null) { request.Query = parameters["q"]; } request.Size = parameters["size"] != null ? Convert.ToInt32(parameters["size"]) : this.DefaultPageSize; SuggestResponse results = client.Suggest(request); suggestResults.Matches = results.Suggest.Suggestions.Select(c => c.Suggestion).ToList(); } catch (Exception ex) { suggestResults.HasError = true; suggestResults.ErrorDetail = ex.Message + " : " + ex.StackTrace; } return suggestResults; }