Ejemplo n.º 1
0
        //构造搜索引擎相关参数
        private ProductSearchCondition MapSearchCondition(SearchCriteriaModel criteria)
        {
            ProductSearchCondition condition = new ProductSearchCondition();

            condition.Filters = new List <FilterBase>();
            condition.Filters.Add(new FieldFilter("p_productstatus", "1"));
            condition.NValueList = ProductSearchFacade.GetNValueList(criteria.FilterValue);

            //使用关键字搜索
            string keyWord = criteria.Keywords;

            if (string.IsNullOrEmpty(keyWord))
            {
                keyWord = criteria.Barcode;
            }
            if (!string.IsNullOrEmpty(keyWord))
            {
                //解决“- +”号报错的bug
                if (!string.IsNullOrEmpty(keyWord) && keyWord.StartsWith("-"))
                {
                    keyWord = keyWord.Replace("-", "-");
                }
                if (!string.IsNullOrEmpty(keyWord) && keyWord.StartsWith("+"))
                {
                    keyWord = keyWord.Replace("+", "+");
                }
                condition.KeyWord = keyWord.Trim();
            }

            //使用CategoryID搜索
            if (criteria.CategoryID > 0)
            {
                //将商品分类ID转换成NValue格式
                var subCatNValue = ProductSearchFacade.GetSubcategoryDimensionValues(criteria.CategoryID.Value);
                condition.NValueList.Add(subCatNValue.ToString());
                condition.Filters.Add(new FieldFilter("Nvalue", subCatNValue.ToString()));
            }

            //使用品牌ID搜索
            if (criteria.BrandID > 0)
            {
                //将品牌ID转换成NValue格式
                var brandNValue = ProductSearchFacade.GetBrandNValue(criteria.BrandID.Value);
                condition.NValueList.Add(brandNValue.ToString());
                condition.Filters.Add(new FieldFilter("Nvalue", brandNValue.ToString()));
            }

            //分页
            if (criteria.PageIndex <= 0)
            {
                criteria.PageIndex = 1;
            }
            if (criteria.PageSize <= 0)
            {
                criteria.PageSize = 10;
            }
            condition.PagingInfo            = new Nesoft.Utility.DataAccess.SearchEngine.PagingInfo();
            condition.PagingInfo.PageNumber = criteria.PageIndex;
            condition.PagingInfo.PageSize   = criteria.PageSize;

            //排序
            if (criteria.SortValue <= 0)
            {
                criteria.SortValue = 10;
            }
            List <SortItem> sortItems = new List <SortItem>();

            sortItems.Add(SortKeyValueMappingConfig.SortItemList.Find(f => f.Key == criteria.SortValue).Item);
            condition.SortItems = sortItems;

            return(condition);
        }
Ejemplo n.º 2
0
        //构造搜索引擎相关参数
        private static ProductSearchCondition GetSearchCondition(SearchCriteriaModel criteria, NameValueCollection pageQueryString)
        {
            ProductSearchCondition condition = new ProductSearchCondition();

            condition.Filters    = new List <FilterBase>();
            condition.NValueList = new List <string>();

            //使用Category3ID搜索
            if (criteria.Category3ID > 0)
            {
                //将商品分类ID转换成NValue格式
                var subCatNValue = ProductSearchFacade.GetSubcategoryDimensionValues(criteria.Category3ID.Value);
                condition.NValueList.Add(subCatNValue.ToString());
            }

            //使用品牌ID搜索
            if (criteria.BrandID > 0)
            {
                //将品牌ID转换成NValue格式
                var brandNValue = ProductSearchFacade.GetBrandNValue(criteria.BrandID.Value);
                condition.NValueList.Add(brandNValue.ToString());
            }

            //使用Category1ID搜索
            if (criteria.Category1ID > 0)
            {
                condition.Filters.Add(new FieldFilter("p_tabstoreids", criteria.Category1ID.ToString()));
            }

            string keyWord   = string.Empty;
            int    sortKey   = 0,
                   pageIndex = criteria.PageIndex.GetValueOrDefault(),
                   pageSize  = criteria.PageSize.GetValueOrDefault();

            if (pageQueryString != null)
            {
                keyWord = pageQueryString["keyword"];
                int.TryParse(pageQueryString["sort"], out sortKey);

                int temp;
                if (int.TryParse(pageQueryString["pageIndex"], out temp))
                {
                    pageIndex = temp;
                }
                if (int.TryParse(pageQueryString["pageSize"], out temp))
                {
                    pageSize = temp;
                }
            }

            //使用关键字搜索
            if (!string.IsNullOrWhiteSpace(keyWord))
            {
                //解决“- +”号报错的bug
                if (!string.IsNullOrEmpty(keyWord) && keyWord.StartsWith("-"))
                {
                    keyWord = keyWord.Replace("-", "-");
                }
                if (!string.IsNullOrEmpty(keyWord) && keyWord.StartsWith("+"))
                {
                    keyWord = keyWord.Replace("+", "+");
                }
                condition.KeyWord = keyWord.Trim();
            }

            //分页
            if (pageIndex <= 0)
            {
                pageIndex = 0;
            }
            if (pageSize <= 0)
            {
                pageSize = 10;
            }
            condition.PagingInfo            = new Nesoft.Utility.DataAccess.SearchEngine.PagingInfo();
            condition.PagingInfo.PageNumber = (++pageIndex);
            condition.PagingInfo.PageSize   = pageSize;

            //排序
            if (sortKey <= 0)
            {
                sortKey = 10;
            }
            List <SortItem> sortItems = new List <SortItem>();

            sortItems.Add(SortKeyValueMappingConfig.SortItemList.Find(f => f.Key == sortKey).Item);
            condition.SortItems = sortItems;

            return(condition);
        }