Exemplo n.º 1
0
 private static SortDescriptor <QueryableAddress> SortResults(SortDescriptor <QueryableAddress> srt)
 {
     return(srt
            .Descending(SortSpecialField.Score)
            .Ascending(f => f.Town)
            .Ascending(f => f.Street)
            .Field(f => f.Field(n => n.PaonStartNumber).Ascending().Missing("_last"))
            .Field(f => f.Field(n => n.UnitNumber).Ascending().Missing("_last"))
            .Field(f => f.Field(n => n.UnitName).Ascending().Missing("_last")));
 }
Exemplo n.º 2
0
        private SortDescriptor <ProductListV2> BuildSort(SearchParamModel model)
        {
            var sort = new SortDescriptor <ProductListV2>();

            sort = sort.Descending(x => x.InventoryStatus);
            if (model.order_rule == "1")
            {
                sort = sort.Descending(x => x.SalesVolume);
            }
            else if (model.order_rule == "2")
            {
                sort = sort.Ascending(x => x.SalesPrice);
            }
            else
            {
                sort = sort.Descending(x => x.SalesPrice);
            }
            return(sort);
        }
Exemplo n.º 3
0
        private SortDescriptor <TEntity> GetSortDescriptor(string sortField, OrderBy sortOrder)
        {
            SortDescriptor <TEntity> sortDesciptor = new SortDescriptor <TEntity>();

            if (!string.IsNullOrEmpty(sortField))
            {
                sortDesciptor = sortOrder == OrderBy.Ascending ? sortDesciptor.Ascending(sortField)
                                                   : sortDesciptor.Descending(sortField);
            }
            return(sortDesciptor);
        }
Exemplo n.º 4
0
        private static SortDescriptor <T> Sort <T>(SortDescriptor <T> ss, string sortingType, string selectedSortingField)
            where T : class
        {
            switch (sortingType)
            {
            case "desc":
                ss.Descending(selectedSortingField);
                break;

            case "asc":
                ss.Ascending(selectedSortingField);
                break;

            default:
                ss = BookRepositorySettings.DEFAULT_SORTING.Equals(DefaultSorting.Descending)
                        ? ss.Descending(selectedSortingField)
                        : ss.Ascending(selectedSortingField);
                break;
            }

            return(ss);
        }
Exemplo n.º 5
0
        private SortDescriptor <ProductListV2> BuildSort(SearchParamModel model)
        {
            var sort = new SortDescriptor <ProductListV2>();

            sort = sort.Descending(x => x.InventoryStatus);
            if (model.order_rule == "1")
            {
                sort = sort.Descending(x => x.SalesVolume);
            }
            else if (model.order_rule == "2")
            {
                sort = sort.Ascending(x => x.SalesPrice);
            }
            else
            {
                sort = sort.Descending(x => x.SalesPrice);
            }

            //更具坐标排序
            sort = sort.GeoDistance(x => x.Field(f => f.IsGroup).PinTo(new GeoLocation(52.310551, 4.404954)).Ascending());

            return(sort);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 搜索日志
        /// </summary>
        /// <param name="highlight"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="keyword"></param>
        /// <param name="logger_name"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public static async Task <PagerData <ESLogLine, QueryExtData> > Search(
            bool highlight = true,
            DateTime?start = null, DateTime?end       = null,
            string keyword = null, string logger_name = null,
            int page       = 1, int pagesize = 10)
        {
            var sd = new SearchDescriptor <ESLogLine>();

            sd = sd.Index(IndexName);

            var query = new QueryContainer();

            if (start != null)
            {
                query &= new DateRangeQuery()
                {
                    Field = nameof(temp.UpdateTime), GreaterThanOrEqualTo = start.Value
                };
            }
            if (end != null)
            {
                query &= new DateRangeQuery()
                {
                    Field = nameof(temp.UpdateTime), LessThan = end.Value
                };
            }
            if (ValidateHelper.IsPlumpString(keyword))
            {
                query &= new MatchQuery()
                {
                    Field              = nameof(temp.Message),
                    Query              = keyword,
                    Operator           = Operator.Or,
                    MinimumShouldMatch = "100%"
                };
            }
            if (ValidateHelper.IsPlumpString(logger_name))
            {
                query &= new TermQuery()
                {
                    Field = nameof(temp.LoggerName), Value = logger_name
                };
            }
            //查询条件
            sd = sd.Query(_ => query);
            //聚合
            sd = sd.Aggregations(x =>
                                 x.Terms(nameof(temp.LoggerName), av => av.Field(nameof(temp.LoggerName)).Size(1000))
                                 .Terms(nameof(temp.Level), av => av.Field(nameof(temp.Level)).Size(1000))
                                 .Terms(nameof(temp.Domain), av => av.Field(nameof(temp.Domain)).Size(1000)));
            //高亮
            if (highlight)
            {
                sd = sd.AddHighlightWrapper("<em class='kwd'>", "</em>", x => x.Field(nameof(temp.Message)));
            }
            //排序
            var sort = new SortDescriptor <ESLogLine>();

            sort = sort.Descending(x => x.UpdateTime);
            sort = sort.Descending(Field.Create("_score", boost: null));
            sd   = sd.Sort(_ => sort);

            //分页
            sd = sd.QueryPage_(page, pagesize);

            //请求服务器
            var client = new ElasticClient(ElasticsearchClientManager.Instance.DefaultClient);
            var re     = await client.SearchAsync <ESLogLine>(_ => sd);

            re.ThrowIfException();

            var data = new PagerData <ESLogLine, QueryExtData>();

            data.ItemCount = (int)re.Total;
            data.DataList  = re.Hits.Select(x => x.Source).ToList();
            //聚合数据
            data.ExtData           = new QueryExtData();
            data.ExtData.Ass       = re.GetAggs();
            data.ExtData.Highlight = re.GetHighlights();

            return(data);
        }
Exemplo n.º 7
0
        public PagerData <CommentEs> QueryCommentFromEs(
            string user_product_id = null, string user_uid = null, string q = null, int page = 1, int pagesize = 10)
        {
            var data     = new PagerData <CommentEs>();
            var client   = ElasticsearchClientManager.Instance.DefaultClient.CreateClient();
            var temp     = new CommentEs();
            var tag_temp = new TagEs();

            var sd = new SearchDescriptor <CommentEs>();

            sd = sd.Index(INDEX_NAME);

            #region where
            var query = new QueryContainer();
            if (ValidateHelper.IsPlumpString(user_product_id))
            {
                query &= new TermQuery()
                {
                    Field = nameof(temp.UserProductUID), Value = user_product_id
                };
            }
            if (ValidateHelper.IsPlumpString(user_uid))
            {
                query &= new TermQuery()
                {
                    Field = nameof(temp.UserUID), Value = user_uid
                };
            }
            if (ValidateHelper.IsPlumpString(q))
            {
                query &= new MatchQuery()
                {
                    Field = nameof(temp.Comment), Query = q, Operator = Operator.Or, MinimumShouldMatch = "100%"
                };
            }
            sd = sd.Query(_ => query);
            #endregion

            #region order
            var sort = new SortDescriptor <CommentEs>();
            sort = sort.Descending(x => x.CreateTime);
            sd   = sd.Sort(_ => sort);
            #endregion

            #region aggs
            sd = sd.Aggregations(x => x
                                 .Terms("tags", av => av.Field($"{nameof(temp.Tags)}.{nameof(tag_temp.TagName)}").Size(10))
                                 .Terms("shops", av => av.Field(f => f.TraderUID).Size(10))
                                 .Average("score", av => av.Field(f => f.Score)));
            #endregion

            #region pager
            sd = sd.QueryPage_(page, pagesize);
            #endregion

            var response = client.Search <CommentEs>(_ => sd);
            response.ThrowIfException();

            data.ItemCount = (int)response.Total;
            data.DataList  = response.Documents.ToList();

            var tags_agg  = response.Aggs.Terms("tags");
            var shops_agg = response.Aggs.Terms("shops");
            var score_agg = response.Aggs.Average("score");

            return(data);
        }
 public SortDescriptor <QueryableTransaction> GetSortDescriptor(SortDescriptor <QueryableTransaction> descriptor)
 {
     return(descriptor
            .Descending(f => f.TransactionDate));
 }
Exemplo n.º 9
0
 public SortDescriptor <QueryablePerson> GetSortDescriptor(SortDescriptor <QueryablePerson> descriptor)
 {
     return(descriptor
            .Descending(f => f.Surname)
            .Descending(f => f.Firstname));
 }
Exemplo n.º 10
0
 public void SortDesc(Expression <Func <TEntity, object> > expression)
 {
     sort.Descending(expression);
 }
Exemplo n.º 11
0
 public SortDescriptor <QueryableAsset> GetSortDescriptor(SortDescriptor <QueryableAsset> descriptor)
 {
     return(descriptor
            .Descending(f => f.Id.Suffix("keyword")));
 }