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(); }
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()); }