protected virtual string GenerateRelativeUrl(SearchIndexRequest request) { return(string.Format("/_design/{0}/_search/{1}{2}", request.IndexIdentity.DesignDocument, request.IndexIdentity.Name, GenerateRequestUrlQueryString(request))); }
public virtual HttpRequest Create(SearchIndexRequest request) { Ensure.That(request, "request").IsNotNull(); return(new HttpRequest(HttpMethod.Get, GenerateRelativeUrl(request)) .SetRequestTypeHeader(request.GetType())); }
protected virtual string GenerateRequestUrl(SearchIndexRequest request) { return string.Format("{0}/_design/{1}/_search/{2}{3}", Connection.Address, request.IndexIdentity.DesignDocument, request.IndexIdentity.Name, GenerateQueryString(request)); }
protected virtual string GenerateRequestUrl(SearchIndexRequest request) { return(string.Format("{0}/_design/{1}/_search/{2}{3}", Connection.Address, request.IndexIdentity.DesignDocument, request.IndexIdentity.Name, GenerateQueryString(request))); }
public virtual async Task <SearchIndexResponse> SearchAsync(SearchIndexRequest request) { Ensure.Any.IsNotNull(request, nameof(request)); var httpRequest = SearchIndexHttpRequestFactory.Create(request); using (var res = await SendAsync(httpRequest).ForAwait()) { return(await SearchIndexResponseFactory.CreateAsync(res).ForAwait()); } }
public void Can_limit() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("class:mammal") .Limit(1)); var response = SUT.SearchAsync(searchRequest).Result; response.Should().BeSuccessfulGet(numOfRows: 1); response.TotalRows.Should().Be(8); }
public virtual async Task <SearchIndexResponse> SearchAsync(SearchIndexRequest request) { Ensure.That(request, "request").IsNotNull(); var httpRequest = CreateHttpRequest(request); using (var res = await SendAsync(httpRequest).ForAwait()) { return(ProcessHttpResponse(res)); } }
public void Can_include_docs() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("kookaburra") .IncludeDocs(true)); var response = SUT.SearchAsync(searchRequest).Result; response.Should().BeSuccessfulGet(numOfRows: 1); var doc = Client.Documents.GetAsync(response.Rows[0].Id).Result; response.Rows[0].IncludedDoc.Should().Be(doc.Content); }
public void Can_include_docs_to_specific_entity() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("kookaburra") .IncludeDocs(true)); var response = SUT.SearchAsync <Animal>(searchRequest).Result; response.Should().BeSuccessfulGet(numOfRows: 1); var orgDoc = Animals.Single(a => a.AnimalId == response.Rows[0].Id); var returnedDoc = response.Rows[0].IncludedDoc; CustomAsserts.AreValueEqual(orgDoc, returnedDoc); }
public void Can_include_docs_to_specific_entity() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("kookaburra") .IncludeDocs(true)); var response = SUT.SearchAsync <Animal>(searchRequest).Result; response.IsSuccess.Should().Be(true); response.RowCount.Should().Be(1); var orgDoc = Animals.Single(a => a.AnimalId == response.Rows[0].Id); var returnedDoc = response.Rows[0].IncludedDoc; returnedDoc.Should().BeEquivalentTo(orgDoc); }
public void Can_report_counts_by_multiple_fields() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("minLength:[1 TO 3]") .Counts("diet", "class")); var response = SUT.SearchAsync(searchRequest).Result; response.Should().BeSuccessfulGet(numOfRows: 4); response.Counts.Should().NotBeNullOrWhiteSpace(); var counts = CloudantDbClient.Serializer.Deserialize <dynamic>(response.Counts); ((double)[email protected]).Should().Be(4.0); ((double)counts.diet.carnivore).Should().Be(1.0); ((double)counts.diet.herbivore).Should().Be(2.0); ((double)counts.diet.omnivore).Should().Be(1.0); }
public void Can_drilldown_searches_by_field_value() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("class:(bird OR mammal)") .Counts("diet") .DrillDown("class", "bird")); var response = SUT.SearchAsync(searchRequest).Result; response.Should().BeSuccessfulGet(numOfRows: 2); response.Rows.Should().NotContain(r => (string)r.Fields["class"] != "bird"); response.Counts.Should().NotBeNullOrWhiteSpace(); var counts = CloudantDbClient.Serializer.Deserialize <dynamic>(response.Counts); ((double)counts.diet.carnivore).Should().Be(1.0); ((double)counts.diet.omnivore).Should().Be(1.0); }
public void Can_search_on_more_complex_expressions() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("diet:carnivore AND minLength:[1 TO 3]")); var response = SUT.SearchAsync(searchRequest).Result; response.Should().BeSuccessfulGet(numOfRows: 1); response.Bookmark.Should().NotBeNullOrEmpty(); response.Rows[0].Id.Should().Be("panda"); response.Rows[0].Order.Should().BeEquivalentTo(new[] { 1.4142135381698608, 1 }); response.Rows[0].Fields.Count.Should().Be(3); response.Rows[0].Fields["diet"].Should().Be("carnivore"); response.Rows[0].Fields["minLength"].Should().Be(1.2); response.Rows[0].Fields["class"].Should().Be("mammal"); response.Rows[0].IncludedDoc.Should().BeNull(); }
public void Can_search_on_default_index_using_simple_expression() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("kookaburra")); var response = SUT.SearchAsync(searchRequest).Result; response.Should().BeSuccessfulGet(numOfRows: 1); response.Bookmark.Should().NotBeNullOrEmpty(); response.Rows[0].Id.Should().Be("kookaburra"); response.Rows[0].Order.Should().BeEquivalentTo(new[] { 1.4054651260375977, 0 }); response.Rows[0].Fields.Count.Should().Be(4); response.Rows[0].Fields["diet"].Should().Be("carnivore"); response.Rows[0].Fields["minLength"].Should().Be(0.28); response.Rows[0].Fields["class"].Should().Be("bird"); response.Rows[0].Fields["latinName"].Should().Be("Dacelo novaeguineae"); response.Rows[0].IncludedDoc.Should().BeNull(); }
public void Can_search_on_more_complex_expressions() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("diet:carnivore AND minLength:[1 TO 3]")); var response = SUT.SearchAsync(searchRequest).Result; response.IsSuccess.Should().Be(true); response.RowCount.Should().Be(1); response.Bookmark.Should().NotBeNullOrEmpty(); response.Rows[0].Id.Should().Be("panda"); response.Rows[0].Order[0].Should().Be(1.9664045572280884); response.Rows[0].Order[1].Should().Be((long)3); response.Rows[0].Fields.Count.Should().Be(4); response.Rows[0].Fields["diet"].Should().Be("carnivore"); response.Rows[0].Fields["minLength"].Should().Be(1.2); response.Rows[0].Fields["class"].Should().Be("mammal"); response.Rows[0].IncludedDoc.Should().BeNull(); }
public void Can_sort() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("diet:carnivore") .Sort("-minLength<number>")); var response = SUT.SearchAsync(searchRequest).Result; response.Should().BeSuccessfulGet(numOfRows: 2); response.Bookmark.Should().NotBeNullOrEmpty(); response.Rows[0].Id.Should().Be("panda"); response.Rows[0].Order.Should().BeEquivalentTo(new[] { 1.2, 1 }); response.Rows[0].Fields["diet"].Should().Be("carnivore"); response.Rows[0].Fields["minLength"].Should().Be(1.2); response.Rows[1].Id.Should().Be("kookaburra"); response.Rows[1].Order.Should().BeEquivalentTo(new[] { 0.28, 0 }); response.Rows[1].Fields["diet"].Should().Be("carnivore"); response.Rows[1].Fields["minLength"].Should().Be(0.28); }
public void Can_search_on_default_index_using_simple_expression() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("kookaburra")); var response = SUT.SearchAsync(searchRequest).Result; response.IsSuccess.Should().Be(true); response.RowCount.Should().Be(1); response.Bookmark.Should().NotBeNullOrEmpty(); response.Rows[0].Id.Should().Be("kookaburra"); response.Rows[0].Order[0].Should().Be(2.098612070083618); response.Rows[0].Order[1].Should().Be((long)2); response.Rows[0].Fields.Count.Should().Be(5); response.Rows[0].Fields["diet"].Should().Be("carnivore"); response.Rows[0].Fields["minLength"].Should().Be(0.28); response.Rows[0].Fields["class"].Should().Be("bird"); response.Rows[0].Fields["latinName"].Should().Be("Dacelo novaeguineae"); response.Rows[0].IncludedDoc.Should().BeNull(); }
public void Can_navigate_using_bookmarks() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("class:mammal") .Limit(1)); var response1 = SUT.SearchAsync(searchRequest).Result; response1.Should().BeSuccessfulGet(numOfRows: 1); response1.TotalRows.Should().Be(8); response1.Rows[0].Id.Should().Be("panda"); searchRequest.Configure(q => q .Bookmark(response1.Bookmark)); var response2 = SUT.SearchAsync(searchRequest).Result; response2.Should().BeSuccessfulGet(numOfRows: 1); response2.TotalRows.Should().Be(8); response2.Rows[0].Id.Should().Be("aardvark"); }
public void Can_report_ranges_by_multiple_fields() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("minLength:[1 TO 3]") .Ranges( new { minLength = new { minLow = "[0 TO 100]", minHigh = "{101 TO Infinity}" }, maxLength = new { maxLow = "[0 TO 100]", maxHigh = "{101 TO Infinity}" } } )); var response = SUT.SearchAsync(searchRequest).Result; response.Should().BeSuccessfulGet(numOfRows: 4); response.Ranges.Should().NotBeNullOrWhiteSpace(); var ranges = CloudantDbClient.Serializer.Deserialize <dynamic>(response.Ranges); ((double)ranges.minLength.minLow).Should().Be(4.0); ((double)ranges.minLength.minHigh).Should().Be(0.0); ((double)ranges.maxLength.maxLow).Should().Be(4.0); ((double)ranges.maxLength.maxHigh).Should().Be(0.0); }
public void Can_sort() { var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId).Configure(q => q .Expression("diet:carnivore") .Sort("-minLength<number>")); var response = SUT.SearchAsync(searchRequest).Result; response.IsSuccess.Should().Be(true); response.RowCount.Should().Be(2); response.Bookmark.Should().NotBeNullOrEmpty(); response.Rows[0].Id.Should().Be("panda"); response.Rows[0].Order[0].Should().Be(1.2); response.Rows[0].Order[1].Should().Be((long)3); response.Rows[0].Fields["diet"].Should().Be("carnivore"); response.Rows[0].Fields["minLength"].Should().Be(1.2); response.Rows[1].Id.Should().Be("kookaburra"); response.Rows[1].Order[0].Should().Be(0.28); response.Rows[1].Order[1].Should().Be((long)2); response.Rows[1].Fields["diet"].Should().Be("carnivore"); response.Rows[1].Fields["minLength"].Should().Be(0.28); }
public ActionResult <SearchIndexResponse> SearchExistingIndex(SearchIndexRequest model) { m_Logger.Info($"[GET] {APIRoutes.SearchInIndexRoute}"); if (string.IsNullOrWhiteSpace(model.SearchWord)) { m_Logger.Debug("Required parameter SearchWord is null, empty or whitespace"); return(BadRequest()); } if (m_Manager.GetIndexById(model.IndexID) == null) { m_Logger.Debug("Required parameter IndexID point to non existing index"); return(BadRequest()); } m_Logger.Info($"looking in index {model.IndexID} for {model.SearchWord}"); var searchResults = m_Manager.SearchInIndex(model.IndexID, model.SearchWord); return(new SearchIndexResponse { Results = searchResults.ToArray() }); }
/// <summary> /// Returns all configured options of <see cref="SearchIndexRequest"/> as key values. /// The values are formatted to JSON-compatible strings. /// </summary> /// <returns></returns> protected virtual IDictionary<string, string> ConvertRequestToJsonCompatibleKeyValues(SearchIndexRequest request) { var kvs = new Dictionary<string, string>(); if (HasValue(request.Expression)) kvs.Add(KeyNames.Expression, request.Expression); if (HasValue(request.Sort)) kvs.Add(KeyNames.Sort, FormatValues(request.Sort)); if (HasValue(request.Bookmark)) kvs.Add(KeyNames.Bookmark, request.Bookmark); if (request.Stale.HasValue) kvs.Add(KeyNames.Stale, request.Stale.Value.AsString()); if (request.Limit.HasValue) kvs.Add(KeyNames.Limit, request.Limit.Value.ToString(MyCouchRuntime.NumberFormat)); if (request.IncludeDocs.HasValue) kvs.Add(KeyNames.IncludeDocs, request.IncludeDocs.Value.ToString().ToLower()); return kvs; }
public async Task Test_SearchInIndex_Expect_Success() { using var client = m_TestServer.CreateClient(); var newPath = WebTestHelper.GetPathToTestData("Meta"); var configureModel = new { managementInformationPath = newPath }; using (var requestPayload = new StringContent(JsonConvert.SerializeObject(configureModel), Encoding.UTF8, "application/json")) using (_ = await client.PutAsync(APIRoutes.ConfigurationRoute, requestPayload)) { } var createIndexModel = new CreateIndexRequest() { SourcePath = WebTestHelper.GetPathToTestData("01_ToIndex"), FileExtensions = new[] { ".txt" } }; using (var requestPayload = new StringContent(JsonConvert.SerializeObject(createIndexModel), Encoding.UTF8, "application/json")) using (_ = await client.PostAsync(APIRoutes.CreateIndexRoute, requestPayload)) { } ICodeSearcherIndex[] indexesModel; int count = 0; do { using (var response = await client.GetAsync(APIRoutes.IndexListRoute)) { var responsePayload = await response.Content.ReadAsStringAsync(); var settings = new JsonSerializerSettings(); settings.Converters.Add(Factory.Get().GetCodeSearcherIndexJsonConverter()); indexesModel = JsonConvert.DeserializeObject <ICodeSearcherIndex[]>(responsePayload, settings); Assert.That(indexesModel, Is.Not.Null); } await Task.Delay(250); //timeout Assert.That(count++, Is.LessThan(100)); } while (indexesModel.Length < 1); var searchModel = new SearchIndexRequest() { IndexID = indexesModel[0].ID, SearchWord = "erat" }; using (var requestPayload = new StringContent(JsonConvert.SerializeObject(searchModel), Encoding.UTF8, "application/json")) { var request = new HttpRequestMessage { Method = HttpMethod.Post, Content = requestPayload, RequestUri = new Uri(client.BaseAddress, APIRoutes.SearchInIndexRoute) }; using (var response = await client.SendAsync(request)) { response.EnsureSuccessStatusCode(); var responsePayload = await response.Content.ReadAsStringAsync(); var settings = new JsonSerializerSettings(); settings.Converters.Add(Factory.Get().GetDetailedResultJsonConverter()); settings.Converters.Add(Factory.Get().GetFindingsInFileJsonConverter()); var searchIndex = JsonConvert.DeserializeObject <SearchIndexResponse>(responsePayload, settings); } } }
protected virtual IDictionary <string, string> GenerateJsonCompatibleKeyValues(SearchIndexRequest request) { var kvs = new Dictionary <string, string>(); if (!string.IsNullOrWhiteSpace(request.Expression)) { kvs.Add(KeyNames.Expression, request.Expression); } if (request.HasSortings()) { kvs.Add(KeyNames.Sort, DocumentSerializer.ToJsonArray(request.Sort.ToArray())); } if (!string.IsNullOrWhiteSpace(request.Bookmark)) { kvs.Add(KeyNames.Bookmark, request.Bookmark); } if (request.Stale.HasValue) { kvs.Add(KeyNames.Stale, request.Stale.Value.AsString()); } if (request.Limit.HasValue) { kvs.Add(KeyNames.Limit, DocumentSerializer.ToJson(request.Limit.Value)); } if (request.IncludeDocs.HasValue) { kvs.Add(KeyNames.IncludeDocs, DocumentSerializer.ToJson(request.IncludeDocs.Value)); } if (request.Ranges != null) { kvs.Add(KeyNames.Ranges, Serializer.Serialize(request.Ranges)); } if (request.HasCounts()) { kvs.Add(KeyNames.Counts, DocumentSerializer.ToJsonArray(request.Counts.ToArray())); } if (!string.IsNullOrWhiteSpace(request.GroupField)) { kvs.Add(KeyNames.GroupField, request.GroupField); } if (request.GroupLimit.HasValue) { kvs.Add(KeyNames.GroupLimit, DocumentSerializer.ToJson(request.GroupLimit.Value)); } if (request.HasGroupSortings()) { kvs.Add(KeyNames.GroupSort, DocumentSerializer.ToJsonArray(request.GroupSort.ToArray())); } if (request.DrillDown.HasValue) { kvs.Add(KeyNames.DrillDown, DocumentSerializer.ToJsonArray(new [] { request.DrillDown.Value.Key, request.DrillDown.Value.Value })); } return(kvs); }
protected virtual string GenerateQueryStringParams(SearchIndexRequest request) { return(string.Join("&", GenerateJsonCompatibleKeyValues(request) .Select(kv => string.Format("{0}={1}", kv.Key, UrlParam.Encode(kv.Value))))); }
protected virtual string GenerateRequestUrlQueryString(SearchIndexRequest request) { var p = GenerateQueryStringParams(request); return(string.IsNullOrEmpty(p) ? string.Empty : string.Concat("?", p)); }
public virtual async Task <SearchIndexResponse <TIncludedDoc> > SearchAsync <TIncludedDoc>(SearchIndexRequest request) { Ensure.That(request, "request").IsNotNull(); var httpRequest = SearchIndexHttpRequestFactory.Create(request); using (var res = await SendAsync(httpRequest).ForAwait()) { return(await SearchIndexResponseFactory.CreateAsync <TIncludedDoc>(res).ForAwait()); } }
public SearchIndexRequestConfigurator(SearchIndexRequest request) { Request = request; }
/// <summary> /// Returns all configured options of <see cref="SearchIndexRequest"/> as key values. /// The values are formatted to JSON-compatible strings. /// </summary> /// <returns></returns> protected virtual IDictionary <string, string> ConvertRequestToJsonCompatibleKeyValues(SearchIndexRequest request) { var kvs = new Dictionary <string, string>(); if (HasValue(request.Expression)) { kvs.Add(KeyNames.Expression, request.Expression); } if (HasValue(request.Sort)) { kvs.Add(KeyNames.Sort, FormatValues(request.Sort)); } if (HasValue(request.Bookmark)) { kvs.Add(KeyNames.Bookmark, request.Bookmark); } if (request.Stale.HasValue) { kvs.Add(KeyNames.Stale, request.Stale.Value.AsString()); } if (request.Limit.HasValue) { kvs.Add(KeyNames.Limit, request.Limit.Value.ToString(MyCouchRuntime.NumberFormat)); } if (request.IncludeDocs.HasValue) { kvs.Add(KeyNames.IncludeDocs, request.IncludeDocs.Value.ToString().ToLower()); } return(kvs); }
/// <summary> /// Generates <see cref="SearchIndexRequest"/> configured values as querystring params. /// </summary> /// <returns></returns> protected virtual string GenerateQueryStringParams(SearchIndexRequest request) { return(string.Join("&", ConvertRequestToJsonCompatibleKeyValues(request) .Select(kv => string.Format("{0}={1}", kv.Key, Uri.EscapeDataString(kv.Value))))); }
public virtual HttpRequest Create(SearchIndexRequest request) { Ensure.That(request, "request").IsNotNull(); return CreateFor<SearchIndexRequest>(HttpMethod.Get, GenerateRequestUrl(request)); }
public virtual HttpRequest Create(SearchIndexRequest request) { Ensure.That(request, "request").IsNotNull(); return(CreateFor <SearchIndexRequest>(HttpMethod.Get, GenerateRequestUrl(request))); }
protected virtual string GenerateQueryString(SearchIndexRequest request) { var p = GenerateQueryStringParams(request); return string.IsNullOrEmpty(p) ? string.Empty : string.Concat("?", p); }
/// <summary> /// Generates <see cref="SearchIndexRequest"/> configured values as querystring params. /// </summary> /// <returns></returns> protected virtual string GenerateQueryStringParams(SearchIndexRequest request) { return string.Join("&", ConvertRequestToJsonCompatibleKeyValues(request) .Select(kv => string.Format("{0}={1}", kv.Key, Uri.EscapeDataString(kv.Value)))); }
protected virtual HttpRequest CreateHttpRequest(SearchIndexRequest request) { return(SearchIndexHttpRequestFactory.Create(request)); }
protected virtual void WithHttpRequestFor(SearchIndexRequest request, Action <HttpRequest> a) { var req = SUT.Create(request); a(req); }