private static SortField GetSortField(SortingField field, ICollection <string> availableFields) { var dataType = availableFields.Contains(LuceneSearchHelper.GetFacetableFieldName(field.FieldName)) ? SortFieldType.DOUBLE : SortFieldType.STRING; var result = new SortField(LuceneSearchHelper.ToLuceneFieldName(field.FieldName), dataType, field.IsDescending); return(result); }
private static ISort GetSortingField(SortingField field) { ISort result; var geoSorting = field as GeoDistanceSortingField; if (geoSorting != null) { result = new GeoDistanceSort { Field = ElasticSearchHelper.ToElasticFieldName(field.FieldName), Points = new[] { geoSorting.Location.ToGeoLocation() } }; } else { result = new SortField { Field = ElasticSearchHelper.ToElasticFieldName(field.FieldName), Order = field.IsDescending ? SortOrder.Descending : SortOrder.Ascending, Missing = "_last", UnmappedType = FieldType.Long, }; } return(result); }
protected virtual IList <SortingField> GetSorting(ProductIndexedSearchCriteria criteria) { var result = new List <SortingField>(); var priorityFields = criteria.GetPriorityFields(); foreach (var sortInfo in criteria.SortInfos) { var sortingField = new SortingField(); if (sortInfo is GeoSortInfo geoSortInfo) { sortingField = new GeoDistanceSortingField { Location = geoSortInfo.GeoPoint }; } sortingField.FieldName = sortInfo.SortColumn.ToLowerInvariant(); sortingField.IsDescending = sortInfo.SortDirection == SortDirection.Descending; switch (sortingField.FieldName) { case "price": if (!criteria.Pricelists.IsNullOrEmpty()) { result.AddRange( criteria.Pricelists.Select(priceList => new SortingField($"price_{criteria.Currency}_{priceList}".ToLowerInvariant(), sortingField.IsDescending))); } else { result.Add(new SortingField($"price_{criteria.Currency}".ToLowerInvariant(), sortingField.IsDescending)); } break; case "priority": result.AddRange(priorityFields.Select(priorityField => new SortingField(priorityField, sortingField.IsDescending))); break; case "name": case "title": result.Add(new SortingField("name", sortingField.IsDescending)); break; default: result.Add(sortingField); break; } } if (!result.Any()) { result.AddRange(priorityFields.Select(priorityField => new SortingField(priorityField, true))); result.Add(new SortingField("__sort")); } return(result); }
private static string GetSortingField(SortingField sortingField, IList <Field> availableFields) { string result = null; var availableField = availableFields.Get(sortingField.FieldName); if (availableField != null) { var geoSorting = sortingField as GeoDistanceSortingField; var fieldName = geoSorting == null ? availableField.Name : AzureSearchHelper.GetGeoDistanceExpression(availableField.Name, geoSorting.Location); result = string.Join(" ", fieldName, sortingField.IsDescending ? "desc" : "asc"); } else if (sortingField.FieldName == "score") { result = string.Join(" ", "search.score()", sortingField.IsDescending ? "desc" : "asc"); } return(result); }
public SearchRequestBuilder AddSorting(string sort) { var sortFields = new List <SortingField>(); foreach (var sortInfo in SortInfo.Parse(sort)) { var sortingField = new SortingField(); if (sortInfo is GeoSortInfo geoSortInfo) { sortingField = new GeoDistanceSortingField { Location = geoSortInfo.GeoPoint }; } sortingField.FieldName = sortInfo.SortColumn.ToLowerInvariant(); sortingField.IsDescending = sortInfo.SortDirection == SortDirection.Descending; switch (sortingField.FieldName) { case "name": case "title": sortFields.Add(new SortingField("name", sortingField.IsDescending)); break; default: sortFields.Add(sortingField); break; } } if (sortFields.Any()) { SearchRequest.Sorting = sortFields; } return(this); }
/// <summary> /// Get page of tasks /// </summary> /// <param name="page">Page number (from 1)</param> /// <param name="sortType">Sorting type</param> /// <param name="sortField">Sort by field</param> /// <returns></returns> public static async Task <TasksData> GetTasksAsync(int page, SortingType sortType, SortingField sortField) { TasksData res = await RequestGetAsync <TasksData>(new Uri(API_URL + $"/?{PARAM_DEV}&page={page}&sort_direction={sortType}&sort_field={sortField}" )); return((res.TotalCount == 0 || res.Tasks.Count == 0) ? null : res); }
string GenerateSortingFieldAndOrder(SortingField sortingName, SortingOrder sortingOrder) { return(sortingName.ToString() + " " + sortingOrder.ToString()); }