public async Task Search_DiscoverFacets() { var brs = new BingCommerceSearch(Credentials, new TestTrafficHandler()); var request = new CommerceSearchPostRequest() { Query = new RequestQuery() { MatchAll = "diamond" }, Items = new RequestItems(), Aggregations = new RequestAggregationBase[] { new RequestDiscoverFacets("discovered facets"), } }; var response = await brs.Search.PostAsync(request, TenantId, IndexId); Assert.IsNotNull(response, "Expected non-null response"); var items = response.Items as ResponseItems; Assert.IsNotNull(items, "Expected non-null items response"); Assert.IsNotNull(items.Value, "Expected non-null items.value"); Assert.AreEqual(1, response.Aggregations?.Count ?? 0, "Expected 1 aggregation in the response"); var discoveredFacets = response.Aggregations[0] as ResponseDiscoveredFacets; Assert.IsNotNull(discoveredFacets, "Expected discovered facets response"); Assert.AreEqual(discoveredFacets.Name, request.Aggregations[0].Name, "Expected facet response name to match the request"); Assert.AreNotEqual(0, discoveredFacets.Aggregations?.Count ?? 0, "Expected at least 1 discovered facet"); }
public async Task Search_MatchItems() { var brs = new BingCommerceSearch(Credentials, new TestTrafficHandler()); var request = new CommerceSearchPostRequest() { Query = new RequestQuery() { MatchAll = "diamond" }, Items = new RequestItems() { Select = new[] { "_itemId", "name" } } }; var response = await brs.Search.PostAsync(request, TenantId, IndexId); Assert.IsNotNull(response, "Expected non-null response"); var items = response.Items as ResponseItems; Assert.IsNotNull(items, "Expected non-null items response"); Assert.IsNotNull(items.TotalEstimatedMatches, "Expected items.totalEstimatedMatches"); Assert.IsNotNull(items.Value, "Expected non-null items.value"); Assert.AreNotEqual(0, items.TotalEstimatedMatches, "Expected non-zero items.totalEstimatedMatches"); Assert.AreNotEqual(0, items.Value.Count, "Expected at least one item"); for (var i = 0; i < items.Value.Count; i++) { var item = items.Value[i]; Assert.IsNotNull(item?.ItemId, "Expected non-null item with an item ID at position " + i); var fields = item.Fields as JObject; Assert.IsNotNull(fields, "Expected item fields to be a JObject at position " + i); var title = fields.Value <string>("name"); Assert.IsNotNull(title, "Expected item to have a title at position " + i); } }
private static async Task <long> PostSearch(BingCommerceSearch client, string indexId) { var query = new RequestQuery() { MatchAll = "Product", Filter = new StringSetCondition() { Values = new List <string>() { "1", "2" }, Field = "ProductId" } }; var request = new CommerceSearchPostRequest() { Query = query, Items = new RequestItems() { Select = new List <string>() { "*" } }, Aggregations = new List <RequestAggregationBase>() { new RequestDiscoverFacets() { Name = "discovered facets" } } }; var response = await client.Search.PostAsync(request, TENANT_ID, indexId); return(response.Items.TotalEstimatedMatches.Value); }
private static async Task <long> GetSearch(BingCommerceSearch client, string indexId) { var response = await client.Search.GetAsync("first", TENANT_ID, indexId); return(response.Items.TotalEstimatedMatches.Value); }