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 IEnumerable<Data.Product> Search(ProductSearchArgs args, out int count) { if (args != null && (!String.IsNullOrWhiteSpace(args.Keyword) || !String.IsNullOrWhiteSpace(args.Color)) ) { args.Keyword = ((args.Keyword ?? String.Empty) +" "+ args.Color).Trim(); return _SearchManager.Search(args, out count); } else { int start = 0; int limit = 30; var source = _Repository.EnabledProduct; if (args != null) { if (!String.IsNullOrWhiteSpace(args.ClassNo)) { source = source.Where(d => d.classNo.StartsWith(args.ClassNo.Trim())); } if (!String.IsNullOrWhiteSpace(args.Keyword)) { var keyword = args.Keyword.Trim(); source = source.Where(d => d.name.Contains(keyword) || d.keywords.Contains(keyword)); } if (!String.IsNullOrWhiteSpace(args.Color)) { source = source.Where(d=>d.color.Contains(args.Color)); } if (args.PriceMin.HasValue) { source = source.Where(d => d.unitPrice >= args.PriceMin.Value); } if (args.PriceMax.HasValue) { source = source.Where(d => d.unitPrice <= args.PriceMax.Value); } start = Math.Max(0, args.Start); if (args.Limit > 0) limit = args.Limit; } count = source.Count(); if (args.Sort == null) { source = source.OrderByDescending(p => p.sortNo) .ThenByDescending(p => p.updated); } else if (args.Sort == SortType.TimeDesc) { source = source.OrderByDescending(p => p.updated); } else if (args.Sort == SortType.PriceAsc) { source = source.OrderBy(p => p.unitPrice); } else if (args.Sort == SortType.ViewDesc) { source = source.OrderByDescending(p => p.viewCount); } return source.Skip(start).Take(limit).ToArray(); } }
public IEnumerable <Data.Product> Search(ProductSearchArgs args, out int count) { if (args != null && (!String.IsNullOrWhiteSpace(args.Keyword) || !String.IsNullOrWhiteSpace(args.Color)) ) { args.Keyword = ((args.Keyword ?? String.Empty) + " " + args.Color).Trim(); return(_SearchManager.Search(args, out count)); } else { int start = 0; int limit = 30; var source = _Repository.EnabledProduct; if (args != null) { if (!String.IsNullOrWhiteSpace(args.ClassNo)) { source = source.Where(d => d.classNo.StartsWith(args.ClassNo.Trim())); } if (!String.IsNullOrWhiteSpace(args.Keyword)) { var keyword = args.Keyword.Trim(); source = source.Where(d => d.name.Contains(keyword) || d.keywords.Contains(keyword)); } if (!String.IsNullOrWhiteSpace(args.Color)) { source = source.Where(d => d.color.Contains(args.Color)); } if (args.PriceMin.HasValue) { source = source.Where(d => d.unitPrice >= args.PriceMin.Value); } if (args.PriceMax.HasValue) { source = source.Where(d => d.unitPrice <= args.PriceMax.Value); } start = Math.Max(0, args.Start); if (args.Limit > 0) { limit = args.Limit; } } count = source.Count(); if (args.Sort == null) { source = source.OrderByDescending(p => p.sortNo) .ThenByDescending(p => p.updated); } else if (args.Sort == SortType.TimeDesc) { source = source.OrderByDescending(p => p.updated); } else if (args.Sort == SortType.PriceAsc) { source = source.OrderBy(p => p.unitPrice); } else if (args.Sort == SortType.ViewDesc) { source = source.OrderByDescending(p => p.viewCount); } return(source.Skip(start).Take(limit).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()); }