예제 #1
0
        /// <summary>
        /// 搜索商品
        /// </summary>
        /// <param name="criteria">搜索条件</param>
        /// <returns></returns>
        public SearchResultModel Search(SearchCriteriaModel criteria)
        {
            var searchCondition = MapSearchCondition(criteria);
            var searchResult    = ProductSearchFacade.GetProductSearchResultBySolr(searchCondition);

            SearchResultModel model = new SearchResultModel();

            model.ProductListItems   = TransformResultItemList(searchResult.ProductDataList);
            model.PageInfo           = MapPageInfo(searchResult.ProductDataList);
            model.PageInfo.PageIndex = criteria.PageIndex;
            model.Filters            = MapSearchFilter(searchResult.Navigation);

            return(model);
        }
예제 #2
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);
        }