public void CanSuggestWithSelectedFields() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClientForQuery(); var suggestParameters = new SuggestParameters() { Select = new[] { "hotelName", "baseRate" } }; DocumentSuggestResponse <Hotel> response = client.Documents.Suggest <Hotel>("luxury", "sg", suggestParameters); var expectedDoc = new Hotel() { HotelName = "Fancy Stay", BaseRate = 199.0 }; Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Results); Assert.Equal(1, response.Results.Count); Assert.Equal(expectedDoc, response.Results.First().Document); }); }
protected void TestCanSuggestDynamicDocuments() { SearchIndexClient client = GetClientForQuery(); var suggestParameters = new SuggestParameters() { OrderBy = new[] { "hotelId" } }; DocumentSuggestResponse response = client.Documents.Suggest("good", "sg", suggestParameters); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Null(response.Coverage); Assert.NotNull(response.Results); Document[] expectedDocs = Data.TestDocuments .Where(h => h.HotelId == "4" || h.HotelId == "5") .OrderBy(h => h.HotelId) .Select(h => h.AsDocument()) .ToArray(); Assert.Equal(expectedDocs.Length, response.Results.Count); for (int i = 0; i < expectedDocs.Length; i++) { SearchAssert.DocumentsEqual(expectedDocs[i], response.Results[i].Document); Assert.Equal(expectedDocs[i]["description"], response.Results[i].Text); } }
protected void TestCanSuggestStaticallyTypedDocuments() { SearchIndexClient client = GetClientForQuery(); var suggestParameters = new SuggestParameters() { OrderBy = new[] { "hotelId" } }; DocumentSuggestResponse <Hotel> response = client.Documents.Suggest <Hotel>("good", "sg", suggestParameters); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Null(response.Coverage); Assert.NotNull(response.Results); IEnumerable <Hotel> expectedDocs = Data.TestDocuments.Where(h => h.HotelId == "4" || h.HotelId == "5").OrderBy(h => h.HotelId); SearchAssert.SequenceEqual( expectedDocs, response.Results.Select(r => r.Document)); SearchAssert.SequenceEqual( expectedDocs.Select(h => h.Description), response.Results.Select(r => r.Text)); }
public void CanUseHitHighlighting() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClientForQuery(); var suggestParameters = new SuggestParameters() { HighlightPreTag = "<b>", HighlightPostTag = "</b>", Filter = "category eq 'Luxury'", Top = 1 }; DocumentSuggestResponse <Hotel> response = client.Documents.Suggest <Hotel>("hotel", "sg", suggestParameters); AssertKeySequenceEqual(response, "1"); // Note: Highlighting is not perfect due to the way Azure Search builds edge n-grams for suggestions. Assert.True( response.Results[0].Text.StartsWith("Best <b>hotel in</b> town", StringComparison.Ordinal)); }); }
private void AssertKeySequenceEqual(DocumentSuggestResponse <Hotel> response, params string[] expectedKeys) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Results); IEnumerable <string> actualKeys = response.Results.Select(r => r.Document.HotelId); SearchAssert.SequenceEqual(expectedKeys, actualKeys); }
/// <summary> /// /// </summary> public DocumentSuggestResponseViewModel(DocumentSuggestResponse <ECADocument> response) { Contract.Requires(response != null, "The response must not be null."); this.Documents = new List <SuggestResultViewModel>(); foreach (var result in response.Results) { this.Documents.Add(new SuggestResultViewModel(result)); } }
protected void TestFuzzyIsOffByDefault() { SearchIndexClient client = GetClientForQuery(); DocumentSuggestResponse <Hotel> response = client.Documents.Suggest <Hotel>("hitel", "sg"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Results); Assert.Equal(0, response.Results.Count); }
protected void TestCanSuggestWithMinimumCoverage() { SearchIndexClient client = GetClientForQuery(); var parameters = new SuggestParameters() { MinimumCoverage = 50 }; DocumentSuggestResponse <Hotel> response = client.Documents.Suggest <Hotel>("luxury", "sg", parameters); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(100, response.Coverage); }
public void FuzzyIsOffByDefault() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClientForQuery(); DocumentSuggestResponse <Hotel> response = client.Documents.Suggest <Hotel>("hitel", "sg"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Results); Assert.Equal(0, response.Results.Count); }); }
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); }
protected void TestCanFilter() { SearchIndexClient client = GetClientForQuery(); var suggestParameters = new SuggestParameters() { Filter = "rating gt 3 and lastRenovationDate gt 2000-01-01T00:00:00Z" }; DocumentSuggestResponse <Hotel> response = client.Documents.Suggest <Hotel>("hotel", "sg", suggestParameters); AssertKeySequenceEqual(response, "1", "5"); }
protected void TestCanGetFuzzySuggestions() { SearchIndexClient client = GetClientForQuery(); var suggestParameters = new SuggestParameters() { UseFuzzyMatching = true }; DocumentSuggestResponse <Hotel> response = client.Documents.Suggest <Hotel>("hitel", "sg", suggestParameters); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Results); Assert.Equal(5, response.Results.Count); }
protected void TestTopTrimsResults() { SearchIndexClient client = GetClientForQuery(); var suggestParameters = new SuggestParameters() { OrderBy = new string[] { "hotelId" }, Top = 3 }; DocumentSuggestResponse <Hotel> response = client.Documents.Suggest <Hotel>("hotel", "sg", suggestParameters); AssertKeySequenceEqual(response, "1", "2", "3"); }
protected void TestSearchFieldsExcludesFieldsFromSuggest() { SearchIndexClient client = GetClientForQuery(); var suggestParameters = new SuggestParameters() { SearchFields = new[] { "hotelName" }, }; DocumentSuggestResponse <Hotel> response = client.Documents.Suggest <Hotel>("luxury", "sg", suggestParameters); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Results); Assert.Equal(0, response.Results.Count); }
protected void TestOrderByProgressivelyBreaksTies() { SearchIndexClient client = GetClientForQuery(); var suggestParameters = new SuggestParameters() { OrderBy = new string[] { "rating desc", "lastRenovationDate asc", "geo.distance(location, geography'POINT(-122.0 49.0)')" } }; DocumentSuggestResponse <Hotel> response = client.Documents.Suggest <Hotel>("hotel", "sg", suggestParameters); AssertKeySequenceEqual(response, "1", "4", "3", "5", "2"); }
private void AssertKeySequenceEqual(DocumentSuggestResponse<Hotel> response, params string[] expectedKeys) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Results); IEnumerable<string> actualKeys = response.Results.Select(r => r.Document.HotelId); SearchAssert.SequenceEqual(expectedKeys, actualKeys); }