public void DynamicDocumentDateTimesRoundTripAsUtc()
        {
            Run(() =>
            {
                SearchServiceClient serviceClient = Data.GetSearchServiceClient();

                Index index =
                    new Index()
                {
                    Name   = TestUtilities.GenerateName(),
                    Fields = new[]
                    {
                        new Field("ISBN", DataType.String)
                        {
                            IsKey = true
                        },
                        new Field("PublishDate", DataType.DateTimeOffset)
                    }
                };

                IndexDefinitionResponse createIndexResponse = serviceClient.Indexes.Create(index);
                Assert.Equal(HttpStatusCode.Created, createIndexResponse.StatusCode);

                SearchIndexClient indexClient = Data.GetSearchIndexClient(createIndexResponse.Index.Name);

                DateTime localDateTime       = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Local);
                DateTime utcDateTime         = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                DateTime unspecifiedDateTime = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Unspecified);

                var batch =
                    new IndexBatch(
                        new[]
                {
                    new IndexAction(new Document()
                    {
                        { "ISBN", "1" }, { "PublishDate", localDateTime }
                    }),
                    new IndexAction(new Document()
                    {
                        { "ISBN", "2" }, { "PublishDate", utcDateTime }
                    }),
                    new IndexAction(new Document()
                    {
                        { "ISBN", "3" }, { "PublishDate", unspecifiedDateTime }
                    })
                });

                indexClient.Documents.Index(batch);
                SearchTestUtilities.WaitForIndexing();

                DocumentGetResponse getResponse = indexClient.Documents.Get("1");
                Assert.Equal(new DateTimeOffset(localDateTime), getResponse.Document["PublishDate"]);

                getResponse = indexClient.Documents.Get("2");
                Assert.Equal(new DateTimeOffset(utcDateTime), getResponse.Document["PublishDate"]);

                getResponse = indexClient.Documents.Get("3");
                Assert.Equal(new DateTimeOffset(utcDateTime), getResponse.Document["PublishDate"]);
            });
        }
        public void CanUpdateIndexDefinition()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                Index fullFeaturedIndex = CreateTestIndex();
                Index initialIndex      = CreateTestIndex();

                // Start out with no scoring profiles and different CORS options.
                initialIndex.Name                       = fullFeaturedIndex.Name;
                initialIndex.ScoringProfiles            = new ScoringProfile[0];
                initialIndex.DefaultScoringProfile      = null;
                initialIndex.CorsOptions.AllowedOrigins = new[] { "*" };

                IndexDefinitionResponse createResponse = searchClient.Indexes.Create(initialIndex);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                // Give the index time to stabilize before continuing the test.
                // TODO: Remove this workaround once the retry hang bug is fixed.
                TestUtilities.Wait(TimeSpan.FromSeconds(20));

                // Now update the index.
                Index index                      = createResponse.Index;
                index.ScoringProfiles            = fullFeaturedIndex.ScoringProfiles;
                index.DefaultScoringProfile      = fullFeaturedIndex.DefaultScoringProfile;
                index.CorsOptions.AllowedOrigins = fullFeaturedIndex.CorsOptions.AllowedOrigins;

                IndexDefinitionResponse updateResponse = searchClient.Indexes.CreateOrUpdate(index);
                Assert.Equal(HttpStatusCode.OK, updateResponse.StatusCode);

                AssertIndexesEqual(fullFeaturedIndex, updateResponse.Index);
            });
        }
        public void CanCreateAndListIndexes()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                Index index1 = CreateTestIndex();
                Index index2 = CreateTestIndex();

                IndexDefinitionResponse createResponse = searchClient.Indexes.Create(index1);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                createResponse = searchClient.Indexes.Create(index2);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                IndexListResponse listResponse = searchClient.Indexes.List();
                Assert.Equal(HttpStatusCode.OK, listResponse.StatusCode);
                Assert.Equal(2, listResponse.Indexes.Count);

                IEnumerable <string> indexNames = listResponse.Indexes.Select(i => i.Name);
                Assert.Contains(index1.Name, indexNames);
                Assert.Contains(index2.Name, indexNames);

                IndexListNamesResponse listNamesResponse = searchClient.Indexes.ListNames();
                Assert.Equal(HttpStatusCode.OK, listNamesResponse.StatusCode);
                Assert.Equal(2, listNamesResponse.IndexNames.Count);

                indexNames = listNamesResponse.IndexNames;
                Assert.Contains(index1.Name, indexNames);
                Assert.Contains(index2.Name, indexNames);
            });
        }
        public void StaticallyTypedDateTimesRoundTripAsUtc()
        {
            Run(() =>
            {
                SearchServiceClient serviceClient = Data.GetSearchServiceClient();

                Index index =
                    new Index()
                {
                    Name   = TestUtilities.GenerateName(),
                    Fields = new[]
                    {
                        new Field("ISBN", DataType.String)
                        {
                            IsKey = true
                        },
                        new Field("PublishDate", DataType.DateTimeOffset)
                    }
                };

                IndexDefinitionResponse createIndexResponse = serviceClient.Indexes.Create(index);
                Assert.Equal(HttpStatusCode.Created, createIndexResponse.StatusCode);

                SearchIndexClient indexClient = Data.GetSearchIndexClient(createIndexResponse.Index.Name);

                DateTime localDateTime       = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Local);
                DateTime utcDateTime         = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                DateTime unspecifiedDateTime = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Unspecified);

                var batch =
                    IndexBatch.Create(
                        new[]
                {
                    IndexAction.Create(new Book()
                    {
                        ISBN = "1", PublishDate = localDateTime
                    }),
                    IndexAction.Create(new Book()
                    {
                        ISBN = "2", PublishDate = utcDateTime
                    }),
                    IndexAction.Create(new Book()
                    {
                        ISBN = "3", PublishDate = unspecifiedDateTime
                    })
                });

                indexClient.Documents.Index(batch);
                SearchTestUtilities.WaitForIndexing();

                DocumentGetResponse <Book> getResponse = indexClient.Documents.Get <Book>("1");
                Assert.Equal(localDateTime.ToUniversalTime(), getResponse.Document.PublishDate);

                getResponse = indexClient.Documents.Get <Book>("2");
                Assert.Equal(utcDateTime, getResponse.Document.PublishDate);

                getResponse = indexClient.Documents.Get <Book>("3");
                Assert.Equal(utcDateTime, getResponse.Document.PublishDate);
            });
        }
        public void CreateOrUpdateCreatesWhenIndexDoesNotExist()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                Index index = CreateTestIndex();

                IndexDefinitionResponse createOrUpdateResponse = searchClient.Indexes.CreateOrUpdate(index);
                Assert.Equal(HttpStatusCode.Created, createOrUpdateResponse.StatusCode);
            });
        }
        protected void TestCanSuggestWithDateTimeInStaticModel()
        {
            SearchServiceClient serviceClient = Data.GetSearchServiceClient();

            Index index =
                new Index()
            {
                Name   = TestUtilities.GenerateName(),
                Fields = new[]
                {
                    new Field("ISBN", DataType.String)
                    {
                        IsKey = true
                    },
                    new Field("Title", DataType.String)
                    {
                        IsSearchable = true
                    },
                    new Field("Author", DataType.String),
                    new Field("PublishDate", DataType.DateTimeOffset)
                },
                Suggesters = new[] { new Suggester("sg", SuggesterSearchMode.AnalyzingInfixMatching, "Title") }
            };

            IndexDefinitionResponse createIndexResponse = serviceClient.Indexes.Create(index);
            SearchIndexClient       indexClient         = Data.GetSearchIndexClient(createIndexResponse.Index.Name);

            var doc1 = new Book()
            {
                ISBN = "123", Title = "Lord of the Rings", Author = "J.R.R. Tolkien"
            };
            var doc2 = new Book()
            {
                ISBN = "456", Title = "War and Peace", PublishDate = new DateTime(2015, 8, 18)
            };
            var batch = IndexBatch.Create(IndexAction.Create(doc1), IndexAction.Create(doc2));

            indexClient.Documents.Index(batch);
            SearchTestUtilities.WaitForIndexing();

            var parameters = new SuggestParameters()
            {
                Select = new[] { "ISBN", "Title", "PublishDate" }
            };
            DocumentSuggestResponse <Book> response = indexClient.Documents.Suggest <Book>("War", "sg", parameters);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(1, response.Results.Count);
            Assert.Equal(doc2, response.Results[0].Document);
        }
        public void CreateIndexReturnsCorrectDefinition()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                Index index = CreateTestIndex();

                IndexDefinitionResponse createResponse = searchClient.Indexes.Create(index);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                AssertIndexesEqual(index, createResponse.Index);
            });
        }
        public void CanCreateAndDeleteIndex()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                Index index = CreateTestIndex();

                IndexDefinitionResponse createResponse = searchClient.Indexes.Create(index);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                // Explicitly delete the index to test the Delete operation. Otherwise the UndoHandler would delete it.
                AzureOperationResponse deleteResponse = searchClient.Indexes.Delete(index.Name);
                Assert.Equal(HttpStatusCode.NoContent, deleteResponse.StatusCode);
            });
        }
        public void CanCreateAndGetIndexStats()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                Index index = CreateTestIndex();

                IndexDefinitionResponse createResponse = searchClient.Indexes.Create(index);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                IndexGetStatisticsResponse stats = searchClient.Indexes.GetStatistics(index.Name);
                Assert.Equal(HttpStatusCode.OK, stats.StatusCode);
                Assert.Equal(0, stats.DocumentCount);
                Assert.Equal(0, stats.StorageSize);
            });
        }
Example #10
0
        public void CanIndexWithPascalCaseFields()
        {
            Run(() =>
            {
                SearchServiceClient serviceClient = Data.GetSearchServiceClient();

                Index index =
                    new Index()
                {
                    Name   = TestUtilities.GenerateName(),
                    Fields = new[]
                    {
                        new Field("ISBN", DataType.String)
                        {
                            IsKey = true
                        },
                        new Field("Title", DataType.String),
                        new Field("Author", DataType.String)
                    }
                };

                IndexDefinitionResponse createIndexResponse = serviceClient.Indexes.Create(index);
                Assert.Equal(HttpStatusCode.Created, createIndexResponse.StatusCode);

                SearchIndexClient indexClient = Data.GetSearchIndexClient(createIndexResponse.Index.Name);

                var batch =
                    IndexBatch.Create(
                        new[]
                {
                    IndexAction.Create(
                        new Book()
                    {
                        ISBN = "123", Title = "Lord of the Rings", Author = "J.R.R. Tolkien"
                    })
                });

                DocumentIndexResponse indexResponse = indexClient.Documents.Index(batch);
                Assert.Equal(HttpStatusCode.OK, indexResponse.StatusCode);

                Assert.Equal(1, indexResponse.Results.Count);
                AssertIndexActionSucceeded("123", indexResponse.Results[0]);
            });
        }
        public void CreateIndexReturnsCorrectDefaultValues()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                Index inputIndex = CreateTestIndex();

                // Default values for field properties are tested elsewhere.
                inputIndex.CorsOptions = new CorsOptions()
                {
                    AllowedOrigins = new[] { "*" }
                };
                inputIndex.ScoringProfiles = new[]
                {
                    new ScoringProfile("MyProfile")
                    {
                        Functions = new ScoringFunction[]
                        {
                            new MagnitudeScoringFunction(new MagnitudeScoringParameters(1, 4), "rating", 2.0)
                        }
                    }
                };

                IndexDefinitionResponse createResponse = searchClient.Indexes.Create(inputIndex);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                Index resultIndex = createResponse.Index;

                const long ExpectedMaxAgeInSeconds = 5 * 60;
                Assert.Equal(ExpectedMaxAgeInSeconds, resultIndex.CorsOptions.MaxAgeInSeconds);

                Assert.Equal(ScoringFunctionAggregation.Sum, resultIndex.ScoringProfiles[0].FunctionAggregation);

                var function = resultIndex.ScoringProfiles[0].Functions[0] as MagnitudeScoringFunction;
                Assert.NotNull(function);
                Assert.False(function.Parameters.ShouldBoostBeyondRangeByConstant);
                Assert.Equal(ScoringFunctionInterpolation.Linear, function.Interpolation);
            });
        }
        public void CanGetStaticallyTypedDocumentWithPascalCaseFields()
        {
            Run(() =>
            {
                SearchServiceClient serviceClient = Data.GetSearchServiceClient();

                Index index =
                    new Index()
                {
                    Name   = TestUtilities.GenerateName(),
                    Fields = new[]
                    {
                        new Field("ISBN", DataType.String)
                        {
                            IsKey = true
                        },
                        new Field("Title", DataType.String),
                        new Field("Author", DataType.String)
                    }
                };

                IndexDefinitionResponse createIndexResponse = serviceClient.Indexes.Create(index);
                Assert.Equal(HttpStatusCode.Created, createIndexResponse.StatusCode);

                SearchIndexClient indexClient = Data.GetSearchIndexClient(createIndexResponse.Index.Name);

                var expectedDoc = new Book()
                {
                    ISBN = "123", Title = "Lord of the Rings", Author = "J.R.R. Tolkien"
                };
                var batch = IndexBatch.Create(IndexAction.Create(expectedDoc));
                indexClient.Documents.Index(batch);

                DocumentGetResponse <Book> response = indexClient.Documents.Get <Book>("123");
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(expectedDoc, response.Document);
            });
        }
        public void DeleteIndexIsIdempotent()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                Index index = CreateTestIndex();

                // Try delete before the index even exists.
                AzureOperationResponse deleteResponse = searchClient.Indexes.Delete(index.Name);
                Assert.Equal(HttpStatusCode.NotFound, deleteResponse.StatusCode);

                IndexDefinitionResponse createResponse = searchClient.Indexes.Create(index);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                // Now delete twice.
                deleteResponse = searchClient.Indexes.Delete(index.Name);
                Assert.Equal(HttpStatusCode.NoContent, deleteResponse.StatusCode);

                deleteResponse = searchClient.Indexes.Delete(index.Name);
                Assert.Equal(HttpStatusCode.NotFound, deleteResponse.StatusCode);
            });
        }
Example #14
0
        static void Main(string[] args)
        {
            string searchServiceName = args[0];
            var    credentials       = new SearchCredentials(args[1]);
            var    searchClient      = new SearchServiceClient(searchServiceName, credentials);

            try
            {
                IndexDefinitionResponse getResponse = searchClient.Indexes.Get(IndexName);
                if (getResponse?.Index != null)
                {
                    Console.WriteLine("Deleting and recreating index " + IndexName);
                    searchClient.Indexes.Delete(IndexName);
                }
            }
            catch (CloudException)
            {
                // We expect this if the index does not yet exist.
            }

            IndexDefinitionResponse createIndexResponse = searchClient.Indexes.Create(new Index(
                                                                                          IndexName,
                                                                                          new[]
            {
                new Field("ItemId", DataType.String)
                {
                    IsKey = true
                },
                new Field("Title", DataType.String)
                {
                    IsSearchable = true
                },
                new Field("Content", DataType.String)
                {
                    IsSearchable = true
                },
                new Field("CommentThreadId", DataType.Int32),
                new Field("TimelineEntryId", DataType.Int32),
                new Field("MediaAlbumId", DataType.Int32),
                new Field("UserMediaId", DataType.Int32)
            }));

            Index index       = createIndexResponse.Index;
            var   indexClient = new SearchIndexClient(searchServiceName, IndexName, credentials);

            using (var dbContext = new ApplicationDbContext(args[2]))
            {
                IEnumerable <TimelineEntry> timelineEntries = dbContext.TimelineEntries
                                                              .Include(te => te.Message)
                                                              .Include(te => te.CommentThread.Comments.Select(c => c.Text));

                foreach (TimelineEntry entry in timelineEntries)
                {
                    var batchActions = new List <IndexAction <MessageIndexEntry> >();

                    batchActions.Add(new IndexAction <MessageIndexEntry>(
                                         IndexActionType.Upload,
                                         new MessageIndexEntry
                    {
                        ItemId          = "timeline-" + entry.TimelineEntryId,
                        Content         = entry.Message.Content,
                        TimelineEntryId = entry.TimelineEntryId
                    }));

                    if (entry.CommentThread != null)
                    {
                        foreach (Comment comment in entry.CommentThread.Comments)
                        {
                            batchActions.Add(new IndexAction <MessageIndexEntry>(
                                                 IndexActionType.Upload,
                                                 new MessageIndexEntry
                            {
                                ItemId          = "comment-" + comment.CommentId,
                                Content         = comment.Text.Content,
                                TimelineEntryId = entry.TimelineEntryId,
                                CommentThreadId = comment.CommentThreadId
                            }));
                        }
                    }
                    var batch = new IndexBatch <MessageIndexEntry>(batchActions);
                    DocumentIndexResponse indexDocumentsResponse = indexClient.Documents.Index(batch);
                }

                IEnumerable <MediaAlbum> albums = dbContext.MediaAlbums
                                                  .Include(a => a.CommentThread.Comments.Select(c => c.Text));

                foreach (MediaAlbum album in albums)
                {
                    var batchActions = new List <IndexAction <MessageIndexEntry> >();

                    batchActions.Add(new IndexAction <MessageIndexEntry>(
                                         IndexActionType.Upload,
                                         new MessageIndexEntry
                    {
                        ItemId       = "album-" + album.MediaAlbumId,
                        Title        = album.Title,
                        Content      = album.Description,
                        MediaAlbumId = album.MediaAlbumId
                    }));

                    if (album.CommentThread != null)
                    {
                        foreach (Comment comment in album.CommentThread.Comments)
                        {
                            batchActions.Add(new IndexAction <MessageIndexEntry>(
                                                 IndexActionType.Upload,
                                                 new MessageIndexEntry
                            {
                                ItemId          = "comment-" + comment.CommentId,
                                Content         = comment.Text.Content,
                                MediaAlbumId    = album.MediaAlbumId,
                                CommentThreadId = comment.CommentThreadId
                            }));
                        }
                    }
                    var batch = new IndexBatch <MessageIndexEntry>(batchActions);
                    DocumentIndexResponse indexDocumentsResponse = indexClient.Documents.Index(batch);
                }


                IEnumerable <UserMedia> medias = dbContext.UserMedias
                                                 .Include(m => m.Description)
                                                 .Include(m => m.CommentThread.Comments.Select(c => c.Text));

                foreach (UserMedia media in medias)
                {
                    var batchActions = new List <IndexAction <MessageIndexEntry> >();

                    batchActions.Add(new IndexAction <MessageIndexEntry>(
                                         IndexActionType.Upload,
                                         new MessageIndexEntry
                    {
                        ItemId       = "media-" + media.UserMediaId,
                        Title        = media.Title,
                        Content      = media.Description?.Content,
                        UserMediaId  = media.UserMediaId,
                        MediaAlbumId = media.MediaAlbumId
                    }));

                    if (media.CommentThread != null)
                    {
                        foreach (Comment comment in media.CommentThread.Comments)
                        {
                            batchActions.Add(new IndexAction <MessageIndexEntry>(
                                                 IndexActionType.Upload,
                                                 new MessageIndexEntry
                            {
                                ItemId          = "comment-" + comment.CommentId,
                                Content         = comment.Text.Content,
                                UserMediaId     = media.UserMediaId,
                                MediaAlbumId    = media.MediaAlbumId,
                                CommentThreadId = comment.CommentThreadId
                            }));
                        }
                    }
                    var batch = new IndexBatch <MessageIndexEntry>(batchActions);
                    DocumentIndexResponse indexDocumentsResponse = indexClient.Documents.Index(batch);
                }
            }
        }
        public void CanUseAllAnalyzerNamesInIndexDefinition()
        {
            Run(() =>
            {
                SearchServiceClient client = Data.GetSearchServiceClient();

                Index index = new Index()
                {
                    Name = TestUtilities.GenerateName()
                };
                index.Fields.Add(new Field("id", DataType.String)
                {
                    IsKey = true
                });

                var allAnalyzers =
                    new[]
                {
                    AnalyzerName.ArLucene,
                    AnalyzerName.CsLucene,
                    AnalyzerName.DaLucene,
                    AnalyzerName.DeLucene,
                    AnalyzerName.ElLucene,
                    AnalyzerName.EnLucene,
                    AnalyzerName.EsLucene,
                    AnalyzerName.FiLucene,
                    AnalyzerName.FrLucene,
                    AnalyzerName.HiLucene,
                    AnalyzerName.HuLucene,
                    AnalyzerName.IdLucene,
                    AnalyzerName.ItLucene,
                    AnalyzerName.JaLucene,
                    AnalyzerName.KoLucene,
                    AnalyzerName.LvLucene,
                    AnalyzerName.NlLucene,
                    AnalyzerName.NoLucene,
                    AnalyzerName.PlLucene,
                    AnalyzerName.PtBRLucene,
                    AnalyzerName.PtPTLucene,
                    AnalyzerName.RoLucene,
                    AnalyzerName.RuLucene,
                    AnalyzerName.StandardAsciiFoldingLucene,
                    AnalyzerName.StandardLucene,
                    AnalyzerName.SvLucene,
                    AnalyzerName.ThLucene,
                    AnalyzerName.ZhHansLucene,
                    AnalyzerName.ZhHantLucene
                };

                for (int i = 0; i < allAnalyzers.Length; i++)
                {
                    string fieldName = String.Format("field{0}", i);

                    DataType fieldType = (i % 2 == 0) ? DataType.String : DataType.Collection(DataType.String);
                    index.Fields.Add(new Field(fieldName, fieldType, allAnalyzers[i]));
                }

                IndexDefinitionResponse createResponse = client.Indexes.Create(index);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);
            });
        }
        public IndexFixture()
        {
            SearchServiceClient searchClient = this.GetSearchServiceClient();

            IndexName = TestUtilities.GenerateName();

            // This is intentionally a different index definition than the one returned by IndexTests.CreateTestIndex().
            // That index is meant to exercise serialization of the index definition itself, while this one is tuned
            // more for exercising document serialization, indexing, and querying operations.
            var index =
                new Index()
            {
                Name   = IndexName,
                Fields = new[]
                {
                    new Field("hotelId", DataType.String)
                    {
                        IsKey = true, IsFilterable = true, IsSortable = true, IsFacetable = true
                    },
                    new Field("baseRate", DataType.Double)
                    {
                        IsFilterable = true, IsSortable = true, IsFacetable = true
                    },
                    new Field("description", DataType.String)
                    {
                        IsSearchable = true
                    },
                    new Field("descriptionFr", AnalyzerName.FrLucene),
                    new Field("hotelName", DataType.String)
                    {
                        IsSearchable = true, IsFilterable = true, IsSortable = true, IsFacetable = true
                    },
                    new Field("category", DataType.String)
                    {
                        IsSearchable = true, IsFilterable = true, IsSortable = true, IsFacetable = true
                    },
                    new Field("tags", DataType.Collection(DataType.String))
                    {
                        IsSearchable = true, IsFilterable = true, IsFacetable = true
                    },
                    new Field("parkingIncluded", DataType.Boolean)
                    {
                        IsFilterable = true, IsSortable = true, IsFacetable = true
                    },
                    new Field("smokingAllowed", DataType.Boolean)
                    {
                        IsFilterable = true, IsSortable = true, IsFacetable = true
                    },
                    new Field("lastRenovationDate", DataType.DateTimeOffset)
                    {
                        IsFilterable = true, IsSortable = true, IsFacetable = true
                    },
                    new Field("rating", DataType.Int32)
                    {
                        IsFilterable = true, IsSortable = true, IsFacetable = true
                    },
                    new Field("location", DataType.GeographyPoint)
                    {
                        IsFilterable = true, IsSortable = true
                    }
                },
                Suggesters = new[]
                {
                    new Suggester(
                        name: "sg",
                        searchMode: SuggesterSearchMode.AnalyzingInfixMatching,
                        sourceFields: new[] { "description", "hotelName" })
                },
                ScoringProfiles = new[]
                {
                    new ScoringProfile("nearest")
                    {
                        FunctionAggregation = ScoringFunctionAggregation.Sum,
                        Functions           = new[]
                        {
                            new DistanceScoringFunction(new DistanceScoringParameters("myloc", 100), "location", 2)
                        }
                    }
                }
            };

            IndexDefinitionResponse createIndexResponse = searchClient.Indexes.Create(index);

            Assert.Equal(HttpStatusCode.Created, createIndexResponse.StatusCode);

            // Give the index time to stabilize before running tests.
            // TODO: Remove this workaround once the retry hang bug is fixed.
            TestUtilities.Wait(TimeSpan.FromSeconds(20));
        }
        public void CanUseAllAnalyzerNamesInIndexDefinition()
        {
            Run(() =>
            {
                SearchServiceClient client = Data.GetSearchServiceClient();

                Index index = new Index()
                {
                    Name = TestUtilities.GenerateName()
                };
                index.Fields.Add(new Field("id", DataType.String)
                {
                    IsKey = true
                });

                var allAnalyzers =
                    new[]
                {
                    AnalyzerName.ArLucene,
                    AnalyzerName.CsLucene,
                    AnalyzerName.DaLucene,
                    AnalyzerName.DeLucene,
                    AnalyzerName.ElLucene,
                    AnalyzerName.EnLucene,
                    AnalyzerName.EsLucene,
                    AnalyzerName.FiLucene,
                    AnalyzerName.FrLucene,
                    AnalyzerName.HiLucene,
                    AnalyzerName.HuLucene,
                    AnalyzerName.IdLucene,
                    AnalyzerName.ItLucene,
                    AnalyzerName.JaLucene,
                    AnalyzerName.KoLucene,
                    AnalyzerName.LvLucene,
                    AnalyzerName.NlLucene,
                    AnalyzerName.NoLucene,
                    AnalyzerName.PlLucene,
                    AnalyzerName.PtBRLucene,
                    AnalyzerName.PtPTLucene,
                    AnalyzerName.RoLucene,
                    AnalyzerName.RuLucene,
                    AnalyzerName.StandardAsciiFoldingLucene,
                    AnalyzerName.StandardLucene,
                    AnalyzerName.SvLucene,
                    AnalyzerName.ThLucene,
                    AnalyzerName.ZhHansLucene,
                    AnalyzerName.ZhHantLucene,
                    AnalyzerName.ArMicrosoft,
                    AnalyzerName.BgMicrosoft,
                    AnalyzerName.BnMicrosoft,
                    AnalyzerName.CaMicrosoft,
                    AnalyzerName.CsMicrosoft,
                    AnalyzerName.DaMicrosoft,
                    AnalyzerName.DeMicrosoft,
                    AnalyzerName.ElMicrosoft,
                    AnalyzerName.EnMicrosoft,
                    AnalyzerName.EsMicrosoft,
                    AnalyzerName.EtMicrosoft,
                    AnalyzerName.FiMicrosoft,
                    AnalyzerName.FrMicrosoft,
                    AnalyzerName.HeMicrosoft,
                    AnalyzerName.HiMicrosoft,
                    AnalyzerName.HrMicrosoft,
                    AnalyzerName.HuMicrosoft,
                    AnalyzerName.GuMicrosoft,
                    AnalyzerName.IdMicrosoft,
                    AnalyzerName.IsMicrosoft,
                    AnalyzerName.ItMicrosoft,
                    AnalyzerName.JaMicrosoft,
                    AnalyzerName.KnMicrosoft,
                    AnalyzerName.LtMicrosoft,
                    AnalyzerName.LvMicrosoft,
                    AnalyzerName.NlMicrosoft,
                    AnalyzerName.NbMicrosoft,
                    AnalyzerName.MlMicrosoft,
                    AnalyzerName.MsMicrosoft,
                    AnalyzerName.MrMicrosoft,
                    AnalyzerName.PaMicrosoft,
                    AnalyzerName.PlMicrosoft,
                    AnalyzerName.PtPtMicrosoft,
                    AnalyzerName.PtBrMicrosoft,
                    AnalyzerName.RoMicrosoft,
                    AnalyzerName.RuMicrosoft,
                    AnalyzerName.SkMicrosoft,
                    AnalyzerName.SlMicrosoft,
                    AnalyzerName.SrCyrillicMicrosoft,
                    AnalyzerName.SrLatinMicrosoft,
                    AnalyzerName.SvMicrosoft,
                    AnalyzerName.TaMicrosoft,
                    AnalyzerName.TeMicrosoft,
                    AnalyzerName.TrMicrosoft,
                    AnalyzerName.ThMicrosoft,
                    AnalyzerName.UkMicrosoft,
                    AnalyzerName.UrMicrosoft,
                    AnalyzerName.ViMicrosoft,
                    AnalyzerName.ZhHansMicrosoft,
                    AnalyzerName.ZhHantMicrosoft
                };

                for (int i = 0; i < allAnalyzers.Length; i++)
                {
                    string fieldName = String.Format("field{0}", i);

                    DataType fieldType = (i % 2 == 0) ? DataType.String : DataType.Collection(DataType.String);
                    index.Fields.Add(new Field(fieldName, fieldType, allAnalyzers[i]));
                }

                IndexDefinitionResponse createResponse = client.Indexes.Create(index);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);
            });
        }