Esempio n. 1
0
        internal DefineSuggesterResponse DefineSuggester(DefineSuggesterRequest request)
        {
            var marshaller   = new DefineSuggesterRequestMarshaller();
            var unmarshaller = DefineSuggesterResponseUnmarshaller.Instance;

            return(Invoke <DefineSuggesterRequest, DefineSuggesterResponse>(request, marshaller, unmarshaller));
        }
Esempio n. 2
0
        /// <summary>
        /// Initiates the asynchronous execution of the DefineSuggester operation.
        /// <seealso cref="Amazon.CloudSearch.IAmazonCloudSearch"/>
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the DefineSuggester 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 <DefineSuggesterResponse> DefineSuggesterAsync(DefineSuggesterRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new DefineSuggesterRequestMarshaller();
            var unmarshaller = DefineSuggesterResponseUnmarshaller.Instance;

            return(InvokeAsync <DefineSuggesterRequest, DefineSuggesterResponse>(request, marshaller,
                                                                                 unmarshaller, cancellationToken));
        }
Esempio n. 3
0
        public void CreateIndex(string name, IEnumerable <IFieldDefinition> fieldDefinitions)
        {
            var amazonSearchParameters = this.GetAmazonParams();
            var region = RegionEndpoint.GetBySystemName(amazonSearchParameters[Region]);

            //You must add here your accessKey and SecretAccessKey. See here how to get them: http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html
            using (IAmazonCloudSearch cloudSearchClient = AWSClientFactory.CreateAmazonCloudSearchClient(amazonSearchParameters[AccessKey], amazonSearchParameters[SecretAccessKey], region))
            {
                try
                {
                    var domainNames = cloudSearchClient.ListDomainNames();
                    if (!domainNames.DomainNames.ContainsKey(name))
                    {
                        CreateDomainRequest domainRequest = new CreateDomainRequest();
                        domainRequest.DomainName = name;
                        cloudSearchClient.CreateDomain(domainRequest);
                    }

                    if (fieldDefinitions == null)
                    {
                        throw new ArgumentNullException("fieldDefinitions");
                    }

                    foreach (var fieldDefinition in fieldDefinitions)
                    {
                        DefineIndexFieldRequest request = new DefineIndexFieldRequest();
                        request.DomainName = name;
                        request.IndexField = new IndexField();
                        request.IndexField.IndexFieldName = fieldDefinition.Name.ToLowerInvariant();
                        if (fieldDefinition.Type == null || fieldDefinition.Type == typeof(string))
                        {
                            request.IndexField.IndexFieldType = IndexFieldType.Text;
                        }
                        if (fieldDefinition.Type == typeof(string[]))
                        {
                            request.IndexField.IndexFieldType = IndexFieldType.TextArray;
                        }
                        if (fieldDefinition.Type == typeof(int))
                        {
                            request.IndexField.IndexFieldType = IndexFieldType.Int;
                        }
                        if (fieldDefinition.Type == typeof(DateTime))
                        {
                            request.IndexField.IndexFieldType = IndexFieldType.Date;
                        }
                        cloudSearchClient.DefineIndexField(request);
                    }

                    SearchResults searchResults = new SearchResults();
                    foreach (var field in searchResults.HighlightedFields)
                    {
                        Suggester suggester = new Suggester();
                        DocumentSuggesterOptions suggesterOptions = new DocumentSuggesterOptions();
                        suggesterOptions.FuzzyMatching     = SuggesterFuzzyMatching.None;
                        suggesterOptions.SourceField       = field.ToLowerInvariant();
                        suggester.DocumentSuggesterOptions = suggesterOptions;
                        suggester.SuggesterName            = this.GetSuggesterName(field);
                        DefineSuggesterRequest defineRequest = new DefineSuggesterRequest();
                        defineRequest.DomainName = name;
                        defineRequest.Suggester  = suggester;

                        cloudSearchClient.DefineSuggester(defineRequest);
                    }

                    searchResults.Dispose();

                    IndexDocumentsRequest documentRequest = new IndexDocumentsRequest();
                    documentRequest.DomainName = name;
                    cloudSearchClient.IndexDocuments(documentRequest);
                }
                catch (BaseException ex)
                {
                    Log.Write(ex.InnerException.Message);
                }
                catch (LimitExceededException ex)
                {
                    Log.Write(ex.InnerException.Message);
                }
                catch (InternalException ex)
                {
                    Log.Write(ex.InnerException.Message);
                }
            }
        }