public void ToString_DoesNotContainEmptyParameters() { var request = new SearchRequest { Query = "myQuery" }; var uri = new SearchUri("myId", "myKey", request); string result = uri.ToString(); StringAssert.DoesNotContain("results=", result, "Result range should not be in the URI since no explicit value was specified."); }
public void ToString_ContainsBrandId() { var request = new SearchRequest { BrandId = "myBrandId" }; var uri = new SearchUri("myId", "myKey", request); string result = uri.ToString(); StringAssert.Contains("brand_id=myBrandId", result); }
public void ToString_ContainsQuery() { var request = new SearchRequest { Query = "myQuery" }; var uri = new SearchUri("myId", "myKey", request); string result = uri.ToString(); StringAssert.Contains("/myQuery?", result); }
/// <summary> /// Searches Nutritionix for items matching the specified query. /// </summary> /// <param name="request">The query.</param> /// <returns>The search response from the Nutritionix API.</returns> /// <exception cref="Nutritionix.NutritionixException"/> public SearchResponse SearchItems(SearchRequest request) { CheckInitialized(); var searchUri = new SearchUri(_appId, _appKey, request); var response = Get <SearchResponse>(searchUri); response.Results = response.Results ?? new SearchResult[0]; return(response); }
public void ToString_ContainsStart() { var request = new SearchRequest { Query = "myQuery", Start = 100, Count = 50 }; var uri = new SearchUri("myId", "myKey", request); string result = uri.ToString(); result = HttpUtility.UrlDecode(result); StringAssert.Contains("results=100:150", result); }
public void ToString_ContainsExcludedAllergens() { var request = new SearchRequest { Query = "myQuery", ExcludeAllergens = new List <Allergen> { Allergen.Eggs, Allergen.Fish } }; var uri = new SearchUri("myId", "myKey", request); string result = uri.ToString(); StringAssert.Contains("allergen_contains_eggs", result); StringAssert.Contains("allergen_contains_fish", result); }
public ActionResult GridAjax(string keyword, Int32?page = 1, Int32?rows = 20) { var settings = new ConnectionSettings(new System.Uri(_esConnectionOptions.Host)) .DefaultIndex("uri").BasicAuthentication(_esConnectionOptions.Username, _esConnectionOptions.Password); var elasticClient = new ElasticClient(settings); var searchResponse = elasticClient.Search <UriDocument>(s => s //.Query(q =>q // .Match(m=>m.Query(keyword).Field(o=>o.BrowserText)) //) .Query(q => q.Match(m => m.Query(keyword).Field(o => o.AbsoluteUri)) || q.Match(m => m.Query(keyword).Field(o => o.BrowserText)) || q.Match(m => m.Query(keyword).Field(o => o.BrowserHtml)) || q.Match(m => m.Query(keyword).Field(o => o.OriginalUriString)) ) //.Explain(true) //.Sort(sort=>sort.Descending(i=>i)) .From(rows * (page - 1)) .Size(rows) //.StoredFields() .Highlight(h => h .PreTags("1vAn1Saw3s0me") .PostTags("em0s3waS1nAv1") .Fields( f => f.Field(o => o.AbsoluteUri) , f => f.Field(o => o.BrowserText) , f => f.Field(o => o.BrowserHtml) ) ) ); //foreach (var hit in searchResponse.Hits) //{ // var aggregate = hit.Highlight.Values // .Select(o => o.Aggregate((a, b) => a + "<br/>" + b)) // .Aggregate((o, n) => o + "<br/><br/>" + n); //} var total = searchResponse.Total; var hits = searchResponse.Hits.Select(o => o); var searchResponseHitsMetadata = searchResponse.HitsMetadata; var model = new SearchPageDto(); model.Result = hits.Select(h => { var item = new SearchUri { Uri = h.Source.AbsoluteUri, Highlight = h.Highlight.Any() ? h.Highlight.Select(o => o.Key == "browserHtml" ? o.Value.Select(v => HttpUtility.HtmlEncode(v)).Aggregate((a, b) => a + "<br/>" + b) : o.Value.Aggregate((a, b) => a + "<br/>" + b) ) .Aggregate((o, n) => o + "<hr/>" + n) : "", Score = h.Score.Value }; item.Highlight = item.Highlight .Replace("1vAn1Saw3s0me", "<em>") .Replace("em0s3waS1nAv1", "</em>"); //.Replace("<1van1saw3s0me>", "<em>") //.Replace("</1van1saw3s0me>", "</em>"); return(item); }).ToList(); model.Total = (int)total; var base64 = Request.Cookies["gridColumnSetting_search"]; if (base64 != null) { byte[] decodedBytes = Convert.FromBase64String(base64); string colSetting = System.Text.Encoding.UTF8.GetString(decodedBytes); var gridConfig = JsonConvert.DeserializeObject <GridConfig>(colSetting); //deserializeObject.columns.Select(o => o.name).ToList(); ViewBag.gridConfig = gridConfig; } return(PartialView("_SearchGridPartial", model)); }