/// <summary> /// From a result set, look for refiners that represent the set of Elasticsearch indexes /// Difference from a regular refiner is that this is not going to be used as a refiner parameter /// instead it will switch the request to use a specific elasticsearch index, using the indexCatalogue parameter /// By default, a request will have indexCatalogue set to _all, which is interpreted as search over all registered indexes. /// Here will find a set of potential refiners by catalogue, and if one is selected, submit a request with a new /// indexCatalogue parameter, with the same query. /// </summary> /// <param name="refiner"></param> /// <param name="refinerName"></param> /// <returns></returns> private List <RefinerItem> GetAlternatesList(IList <Nest.KeyedBucket <string> > refiner, string refinerName, string query) { List <RefinerItem> refinementItems = new List <RefinerItem>(); foreach (var aggs in refiner) { // update the refiner model with the refiner details RefinerItem aggsValues = new RefinerItem(); aggsValues.RefinementValue = aggs.Key; aggsValues.RefinementCount = aggs.DocCount.ToString(); string refinerLabelOrig = Regex.Replace(aggs.Key.ToLower(), @"\s+", ""); string refinerLabel = QueryModel.getRefinerLabel(refinerLabelOrig); aggsValues.RefinementLabel = refinerLabel; // Get the current query string and create a parameter for the refiners string currURLString = GetCurrentUrlString(); string sq = ""; string baseUrl = ""; if (currURLString.IndexOf("searchQuery=") > 0) { sq = currURLString.Substring(currURLString.IndexOf("searchQuery=") + 12); if (sq != null && sq.IndexOf("&") > 0) { sq = sq.Substring(0, sq.IndexOf("&")); } } else { sq = "*"; } if (currURLString.IndexOf("?") > 0) { baseUrl = currURLString.Substring(0, currURLString.IndexOf("?")); } else { baseUrl = "/search-landing"; } string newurl = baseUrl + "?indexCatalogue=" + Regex.Replace(aggs.Key.ToLower(), @"\s+", "") + "&searchQuery=" + sq; aggsValues.RefinementUrl = newurl; refinementItems.Add(aggsValues); } return(refinementItems); }
/// <summary> /// From a result set, look for the aggregate values for potential refiner objects /// Remove any the match the currently applied refiner /// Get the list of refiner key, values /// </summary> /// <param name="refiner"></param> /// <param name="refinerName"></param> /// <returns></returns> private List <RefinerItem> GetRefinerList(IList <Nest.KeyedBucket <string> > refiner, string refinerName) { List <RefinerItem> refinementItems = new List <RefinerItem>(); foreach (var aggs in refiner) { // update the refiner model with the refiner details RefinerItem aggsValues = new RefinerItem(); aggsValues.RefinementValue = aggs.Key; aggsValues.RefinementCount = aggs.DocCount.ToString(); aggsValues.RefinementLabel = aggs.Key; // Get the current query string and create a parameter for the refiners string currURLString = GetCurrentUrlString(); aggsValues.RefinementUrl = String.Format("{0}&r={1}:{2}", currURLString, refinerName, aggs.Key); refinementItems.Add(aggsValues); } return(refinementItems); }