Exemple #1
0
        /// <summary>
        /// <para>Configures an <c>IndexField</c> for the search domain. Used to create new fields and modify existing ones. If the field exists, the
        /// new configuration replaces the old one. You can configure a maximum of 200 index fields.</para>
        /// </summary>
        ///
        /// <param name="defineIndexFieldRequest">Container for the necessary parameters to execute the DefineIndexField service method on
        /// AmazonCloudSearch.</param>
        ///
        /// <returns>The response from the DefineIndexField service method, as returned by AmazonCloudSearch.</returns>
        ///
        /// <exception cref="T:Amazon.CloudSearch.Model.BaseException" />
        /// <exception cref="T:Amazon.CloudSearch.Model.ResourceNotFoundException" />
        /// <exception cref="T:Amazon.CloudSearch.Model.LimitExceededException" />
        /// <exception cref="T:Amazon.CloudSearch.Model.InternalException" />
        /// <exception cref="T:Amazon.CloudSearch.Model.InvalidTypeException" />
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        public Task <DefineIndexFieldResponse> DefineIndexFieldAsync(DefineIndexFieldRequest defineIndexFieldRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new DefineIndexFieldRequestMarshaller();
            var unmarshaller = DefineIndexFieldResponseUnmarshaller.GetInstance();

            return(Invoke <IRequest, DefineIndexFieldRequest, DefineIndexFieldResponse>(defineIndexFieldRequest, marshaller, unmarshaller, signer, cancellationToken));
        }
Exemple #2
0
        internal DefineIndexFieldResponse DefineIndexField(DefineIndexFieldRequest request)
        {
            var marshaller   = new DefineIndexFieldRequestMarshaller();
            var unmarshaller = DefineIndexFieldResponseUnmarshaller.Instance;

            return(Invoke <DefineIndexFieldRequest, DefineIndexFieldResponse>(request, marshaller, unmarshaller));
        }
Exemple #3
0
        /// <summary>
        /// Initiates the asynchronous execution of the DefineIndexField operation.
        /// <seealso cref="Amazon.CloudSearch_2011_02_01.IAmazonCloudSearch"/>
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the DefineIndexField 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 <DefineIndexFieldResponse> DefineIndexFieldAsync(DefineIndexFieldRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new DefineIndexFieldRequestMarshaller();
            var unmarshaller = DefineIndexFieldResponseUnmarshaller.Instance;

            return(InvokeAsync <DefineIndexFieldRequest, DefineIndexFieldResponse>(request, marshaller,
                                                                                   unmarshaller, cancellationToken));
        }
Exemple #4
0
        internal DefineIndexFieldResponse DefineIndexField(DefineIndexFieldRequest request)
        {
            var task = DefineIndexFieldAsync(request);

            try
            {
                return(task.Result);
            }
            catch (AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return(null);
            }
        }
Exemple #5
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);
                }
            }
        }