public IFieldSort SortOrderCustom(SortFieldDescriptor <T> f, string ordername = "", SortOrder?order = null)
        {
            switch (order)
            {
            case SortOrder.Ascending:
                f.Field(ordername).Ascending();
                break;

            case SortOrder.Descending:
                f.Field(ordername).Descending();
                break;
            }

            return(f);
        }
示例#2
0
        public static AggregationContainerDescriptor <T> SortedTopHits <T>(this AggregationContainerDescriptor <T> agg, int size, Expression <Func <T, object> > fieldSort, SortType sorttype, params Expression <Func <T, object> >[] fieldGetter) where T : class
        {
            var aggName             = sorttype + fieldSort.GetAggName(AggType.TopHits);
            var sortFieldDescriptor = new SortFieldDescriptor <T>();
            var fieldSortName       = Names.GetNameFromGetFieldNamed(fieldSort.Body);

            sortFieldDescriptor = fieldSortName != null?sortFieldDescriptor.Field(fieldSortName) : sortFieldDescriptor.Field(fieldSort);

            sortFieldDescriptor = sorttype == SortType.Ascending ? sortFieldDescriptor.Ascending() : sortFieldDescriptor.Descending();

            var fieldNames   = fieldGetter.Select(x => Names.GetNameFromGetFieldNamed(x.Body)).Where(x => x != null);
            var fieldGetters = fieldGetter.Where(x => Names.GetNameFromGetFieldNamed(x.Body) == null);

            var allFields = fieldNames.Select(x => new Field(x)).Concat(fieldGetters.Select(x => new Field(x)));

            return(agg.TopHits(
                       aggName,
                       x =>
                       x
                       .Size(size)
                       .Source(i => i.Includes(f => f.Fields(allFields)))
                       .Sort(s => new PromiseValue <IList <ISort> >(new List <ISort> {
                sortFieldDescriptor
            }))));
        }
        private IFieldSort SortFromUserInput(SortFieldDescriptor <Document> f, string userInput)
        {
            f.Order(Nest.SortOrder.Descending);

            switch (userInput)
            {
            case "uploadDate":
                f.Field(ff => ff.UploadDate);
                break;

            case "meetDate":
                f.Field(ff => ff.DateOfMeeting);
                break;

            default:
                f.Field("_score");
                f.Descending();
                break;
            }

            return(f);
        }
示例#4
0
        public static AggregationContainerDescriptor <T> SortedTopHits <T>(this AggregationContainerDescriptor <T> agg, int size, Expression <Func <T, object> > fieldSort, SortType sorttype, params Expression <Func <T, object> >[] fieldGetter) where T : class
        {
            var aggName             = sorttype + fieldSort.GetAggName(AggType.TopHits);
            var sortFieldDescriptor = new SortFieldDescriptor <T>();

            sortFieldDescriptor = sortFieldDescriptor.Field(fieldSort);
            if (sorttype == SortType.Ascending)
            {
                sortFieldDescriptor = sortFieldDescriptor.Ascending();
            }
            else
            {
                sortFieldDescriptor = sortFieldDescriptor.Descending();
            }
            return(agg.TopHits(aggName, x => x.Size(size).Source(i => i.Include(f => f.Fields(fieldGetter))).Sort(s => sortFieldDescriptor)));
        }