private static void FillCustomRankingOptions <T>(CustomRankingAttribute rankingAttribute, StringBuilder sb, List <string> CustomRankingOptions) where T : class, new() { var propertyInfo = typeof(T).GetProperty(rankingAttribute.Attribute); if (propertyInfo == null) { throw new ArgumentNullException("Custom ranking attribute cannot be null"); } //Sample => asc(Productname) sb.Append(rankingAttribute.RankingType.ToString().ToLower()); sb.Append("("); sb.Append(rankingAttribute.Attribute); sb.Append(")"); CustomRankingOptions.Add(sb.ToString()); sb.Clear(); }
public async Task <IActionResult> UpdateIndexSettings() { //This settings can be edit on Algolia dashboard IndexOptions options = new IndexOptions(); List <SearchableAttribute> searchableAttributes = new List <SearchableAttribute>(); List <CustomRankingAttribute> customRankingAttributes = new List <CustomRankingAttribute>(); CustomRankingAttribute customAttributeSalary = new CustomRankingAttribute(); customAttributeSalary.Attribute = "Salary"; customAttributeSalary.RankingType = RankingFunctionsEnum.Asc; SearchableAttribute attributeSalary = new SearchableAttribute(); attributeSalary.Attribute = "Salary"; attributeSalary.SearchableAttributeFunctionType = SearchableAttributeFunctionsEnum.Ordered; SearchableAttribute attributeFirstname = new SearchableAttribute(); attributeFirstname.Attribute = "Firstname"; searchableAttributes.Add(attributeSalary); searchableAttributes.Add(attributeFirstname); customRankingAttributes.Add(customAttributeSalary); options.CustomRankingAttributes = customRankingAttributes; options.SearchableAttributes = searchableAttributes; var response = await _indexService.UpdateIndexSettings <Employee>(new UpdateIndexSettingsRequestDto() { IndexName = "Employees", IndexOptions = options }); TempData["Message"] = response.Message; return(RedirectToAction("Index", "Home")); }