/// <summary> /// 搜索指定类型的数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dataType"></param> /// <param name="areaID"></param> /// <param name="keyword"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="count"></param> /// <returns></returns> private List <T> SearchData <T>(IndexDataType dataType, int?areaID, string keyword, int pageIndex, int pageSize, out int count) where T : BaseIndexModel { string indexPath = string.Empty; switch (dataType) { case IndexDataType.Job: indexPath = IndexConfiguration.GetJobPath(); break; case IndexDataType.MallProduct: indexPath = IndexConfiguration.GetMallProductPath(); break; case IndexDataType.Merchant: indexPath = IndexConfiguration.GetMerchantPath(); break; case IndexDataType.MerchantProduct: indexPath = IndexConfiguration.GetMerchantProductPath(); break; } List <string> fields = new List <string> { "name" }; //, "desc" BooleanQuery bquery = new BooleanQuery(); //分词器 Analyzer analyzer = new StandardAnalyzer(IndexConfiguration.LuceneMatchVersion); //搜索条件 Query kwdQuery = MultiFieldQueryParser.Parse(IndexConfiguration.LuceneMatchVersion, keyword, fields.ToArray(), new Occur[] { Occur.SHOULD }, analyzer);//, Occur.SHOULD bquery.Add(kwdQuery, Occur.MUST); if (areaID.HasValue && areaID.Value > 0) { Query query = new QueryParser(IndexConfiguration.LuceneMatchVersion, "areaid", analyzer).Parse(areaID.Value.ToString()); bquery.Add(query, Occur.MUST); } Sort sort = new Sort(new SortField("updatetime", SortField.STRING, true)); count = 0; var list = SearchHelper.Search <T>(indexPath, bquery, sort, pageIndex, pageSize, out count); return(list); }
private MerchantProductIndexManager() { _config = new IndexConfig(); _config.IndexPath = IndexConfiguration.GetMerchantProductPath(); }