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> /// This method runs a search query on your cloudsearch domain /// Ref: http://docs.aws.amazon.com/cloudsearch/latest/developerguide/search-api.html#search-request-parameters /// </summary> /// <param name="searchQuery">The search query parameters</param> /// <param name="filterQuery">The filter query (fq) parameters</param> /// <param name="cursor">Cursor to paginate results</param> /// <param name="parser">The type of parser to be used. "simple" and "structured" are the most common</param> /// <param name="size">The size of the result set to be returned</param> /// <param name="expressions">A list of expressions to be calculated and returned with the results</param> /// <param name="facets">The "facets" parameter (for data grouping)</param> /// <param name="returnFields">List of fields to be returned. By default, all return-enabled fields are returned.</param> /// <param name="queryOptions">Allows searching only specific fields.</param> /// <param name="sort"></param> /// <param name="highlight">The highlight field to be used in JSON format.</param> /// <returns></returns> public bool RunDocumentSearch(string searchQuery, string filterQuery = "", string cursor = "", string parser = "simple", int start = 0, int size = 10, List <AWSCloudSearchExpressionDefinition> expressions = null, List <AWSCloudSearchFacetFieldDefinition> facets = null, List <string> returnFields = null, string queryOptions = "", string sort = "", string highlight = "") { ClearErrorInfo(); ClearSearchResults(); try { SearchRequest searchRequest = new SearchRequest(); searchRequest.Query = searchQuery; searchRequest.QueryParser = parser; searchRequest.Size = size; // Add the parameters as long as they're not null or whitespace if (!String.IsNullOrWhiteSpace(filterQuery)) { searchRequest.FilterQuery = filterQuery; } if (!String.IsNullOrWhiteSpace(cursor)) { searchRequest.Cursor = cursor; } else { searchRequest.Start = start; } if (expressions != null && expressions.Count > 0) { searchRequest.Expr = "{"; foreach (AWSCloudSearchExpressionDefinition expr in expressions) { searchRequest.Expr += "'" + expr.ExpressionName + "':'" + expr.ExpressionValue + "',"; } searchRequest.Expr = searchRequest.Expr.TrimEnd(','); searchRequest.Expr += "}"; } if (facets != null && facets.Count > 0) { searchRequest.Facet = "{"; foreach (AWSCloudSearchFacetFieldDefinition facet in facets) { searchRequest.Facet += "'" + facet.FieldName + "':{"; if (facet.buckets.Count > 0) { searchRequest.Facet += "buckets:['" + String.Join("','", facet.buckets) + "']"; } else if (!String.IsNullOrEmpty(facet.sort)) { searchRequest.Facet += "sort:'" + facet.sort + "', size:" + facet.size; } searchRequest.Facet += "},"; } searchRequest.Facet = searchRequest.Facet.TrimEnd(','); searchRequest.Facet += "}"; } if (returnFields != null && returnFields.Count > 0) { searchRequest.Return = String.Join(",", returnFields); } if (!String.IsNullOrWhiteSpace(queryOptions)) { searchRequest.QueryOptions = queryOptions; } if (!String.IsNullOrWhiteSpace(sort)) { searchRequest.Sort = sort; } if (!String.IsNullOrWhiteSpace(highlight)) { searchRequest.Highlight = highlight; } SearchResponse searchResponse = CloudSearchClient.Search(searchRequest); // Check response for errors if (searchResponse.HttpStatusCode != HttpStatusCode.OK) { ErrorCode = Convert.ToInt32(searchResponse.HttpStatusCode); ErrorMessage = "Http Error [" + searchResponse.HttpStatusCode.ToString() + "]"; } else { // Save the response on our objects this.LastSearchResults = searchResponse; } } catch (Exception ex) { ErrorCode = -1; ErrorMessage = ex.Message + "::" + ex.InnerException; } return(ErrorCode == 0); }