/// <summary> /// 用lucene进行商品查询 /// </summary> /// <param name="pageIndex">从1开始</param> /// <param name="pageSize">单页数量</param> /// <param name="totalCount">总数</param> /// <param name="keyword">搜索的关键字</param> /// <param name="categoryIdList">类别集合</param> /// <param name="priceFilter">[13,50] 13,50且包含13到50 {13,50} 13,50且不包含13到50</param> /// <param name="priceOrderBy">price desc price asc</param> /// <returns></returns> public static List <Commodity> QueryCommodity(int pageIndex, int pageSize, out int totalCount, string keyword, List <int> categoryIdList, string priceFilter, string priceOrderBy) { totalCount = 0; try { if (string.IsNullOrWhiteSpace(keyword) && (categoryIdList == null || categoryIdList.Count == 0)) { return(null); } ILuceneQuery luceneQuery = new LuceneQuery(); string queryString = string.Format(" {0} {1}", string.IsNullOrWhiteSpace(keyword) ? "" : string.Format(" +{0}", AnalyzerKeyword(keyword)), categoryIdList == null || categoryIdList.Count == 0 ? "" : string.Format(" +{0}", AnalyzerCategory(categoryIdList))); return(luceneQuery.QueryIndexPage(queryString, pageIndex, pageSize, out totalCount, priceFilter, priceOrderBy)); } catch (Exception ex) { logger.Error(string.Format("QueryCommodity参数为{0}出现异常", keyword), ex); return(null); } }
/// <summary> /// 用lucene进行商品查询 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="totalCount"></param> /// <param name="keyword"></param> /// <param name="fieldName"></param> /// <param name="categoryIdList"></param> /// <param name="priceFilter">[13,50] 13,50且包含13到50 {13,50} 13,50且不包含13到50</param> /// <param name="priceOrderBy">price desc price asc</param> /// <param name="fieldModelList"></param> /// <returns></returns> public static List <T> QueryCommodity <T>(int pageIndex, int pageSize, out int totalCount, string keyword, string fieldName, List <int> categoryIdList, Filter filter, Sort sort, IList <FieldDataModel> fieldModelList) where T : class, new() { totalCount = 0; List <T> modelList = null; try { if (string.IsNullOrWhiteSpace(keyword) && (categoryIdList == null || categoryIdList.Count == 0)) { return(null); } ILuceneQuery <T> luceneQuery = new LuceneQuery <T>(); string analyzerKeyword = string.IsNullOrWhiteSpace(keyword) ? "" : string.Format(" +{0}", AnalyzerKeyword(keyword, fieldName)); string queryString = string.Format(" {0} ", analyzerKeyword); modelList = luceneQuery.QueryIndexPage(queryString, fieldName, pageIndex, pageSize, out totalCount, filter, sort, fieldModelList); } catch (Exception ex) { m_logger.Error(string.Format("QueryCommodity参数为{0}出现异常", keyword), ex); } return(modelList); }