Exemplo n.º 1
0
 public void UpdateSearchIndex(Data.Product entity)
 {
     if (entity != null)
     {
         AliyunHelper.UpdateIndexDoc(new ProductAliyunIndexer(), new Dictionary <string, object>[] { new Dictionary <string, object> {
                                                                                                         { TableKey, entity.pid },
                                                                                                         { name, entity.name },
                                                                                                         { enname, entity.enName },
                                                                                                         { description, entity.description },
                                                                                                         { endescription, entity.enDescription },
                                                                                                         { size, entity.size },
                                                                                                         { ensize, entity.enSize },
                                                                                                         { color, entity.color },
                                                                                                         { encolor, entity.enColor },
                                                                                                         { material, entity.material },
                                                                                                         { enmaterial, entity.enMaterial },
                                                                                                         { technique, entity.technique },
                                                                                                         { entechnique, entity.enTechnique },
                                                                                                         { minquantity, entity.minQuantity },
                                                                                                         { deliveryday, entity.deliveryDay },
                                                                                                         { keywords, entity.keywords },
                                                                                                         { enkeywords, entity.enKeywords },
                                                                                                         { unitprice, entity.unitPrice },
                                                                                                         { imagepath, entity.imagePath },
                                                                                                         { classno, entity.classNo },
                                                                                                         { sortno, entity.sortNo },
                                                                                                         { createuid, entity.createUid },
                                                                                                         { created, entity.created },
                                                                                                         { updated, entity.updated },
                                                                                                         { enabled, entity.enabled },
                                                                                                         { updater, entity.updater ?? 0 },
                                                                                                         { viewcount, entity.viewCount ?? 0 },
                                                                                                     } });
     }
 }
Exemplo n.º 2
0
 public void DeleteIndex(params long[] pids)
 {
     AliyunHelper.DeleteIndexDoc(new ProductAliyunIndexer(), TableKey, pids.Select(p => p.ToString()).ToArray());
 }
Exemplo n.º 3
0
        public Data.Product[] Search(ProductSearchArgs args, out int count)
        {
            var querys = new List <IQuery>();

            if (!String.IsNullOrWhiteSpace(args.Keyword))
            {
                querys.Add(Query.Or(
                               new QueryItem("keyword", args.Keyword)
                               , new QueryItem("enkeyword", args.Keyword)
                               ));
            }
            if (!String.IsNullOrWhiteSpace(args.ClassNo))
            {
                querys.Add(new KeywordQuery("classno", String.Format("^{0}", args.ClassNo)));
            }

            if (args.Pids != null && args.Pids.Any())
            {
                List <QueryItem> queryItems = new List <QueryItem>();
                foreach (var pid in args.Pids)
                {
                    queryItems.Add(new QueryItem("pid", pid.ToString()));
                }
                querys.Add(Query.Or(queryItems.ToArray()));
            }

            List <IFilter> filters = new List <IFilter>();

            filters = AliyunHelper.RangeToFilters(filters, unitprice, new Range <decimal?>(args.PriceMin, args.PriceMax));

            //排序策略
            var sort = new SourtItemCollection(new SortItem(sortno, SortKinds.Desc), new SortItem(updated, SortKinds.Desc));//默认排序

            if (args.Sort == null)
            {
                if (args.Sort == SortType.PriceAsc)//价格排序
                {
                    sort = new SourtItemCollection(new SortItem(unitprice, SortKinds.Asc));
                }
                else if (args.Sort == SortType.TimeDesc)//更新时间排序
                {
                    sort = new SourtItemCollection(new SortItem(updated, SortKinds.Desc));
                }
                else if (args.Sort == SortType.ViewDesc)//查看量排序
                {
                    sort = new SourtItemCollection(new SortItem(viewcount, SortKinds.Desc));
                }
            }

            var query = new QueryBuilder
            {
                Config = new Config {
                    Start = Math.Max(0, args.Start), Hit = Math.Max(1, args.Limit)
                },
                Query  = Query.And(querys.ToArray()),
                Filter = filters.Count > 0 ? Filter.And(filters.ToArray()) : null,
                Sort   = sort,
            };
            var result = AliyunHelper.Search(new ProductAliyunIndexer(), query, String.Empty);
            List <Data.Product> products = new List <Data.Product>();

            foreach (var item in result.Items)
            {
                products.Add(GetProduct(item));
            }
            count = result.Total;
            return(products.ToArray());
        }