Beispiel #1
0
        protected override IndexWriter GetIndex(QueueModel state)
        {
            if (null == state)
            {
                return(null);
            }

            int areaID = state.AreaID;

            IndexConfig config = null;

            if (!areaHash.ContainsKey(areaID) && null == areaHash[areaID])
            {
                config           = new IndexConfig();
                config.IndexPath = IndexConfiguration.GetAreaPath(areaID);

                areaHash[areaID] = config;
            }
            else
            {
                config = areaHash[areaID] as IndexConfig;
            }

            return(config?.Writer);
        }
        /// <summary>
        /// 搜索指定类型集合的数据
        /// </summary>
        /// <param name="dataTypes"></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 <BaseIndexModel> SearchData(IndexDataType[] dataTypes, int areaID, string keyword, int pageIndex, int pageSize, out int count)
        {
            count = 0;

            if (null == dataTypes || dataTypes.Length < 1)
            {
                return(null);
            }

            string indexPath = IndexConfiguration.GetAreaPath(areaID);

            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);

            //区域条件
            Query areaQuery = new QueryParser(IndexConfiguration.LuceneMatchVersion, "areaid", analyzer).Parse(areaID.ToString());

            bquery.Add(areaQuery, Occur.MUST);

            //类型
            BooleanQuery typeQuery = new BooleanQuery();

            foreach (var t in dataTypes)
            {
                Query qt = new QueryParser(IndexConfiguration.LuceneMatchVersion, "datatype", analyzer).Parse(t.ToString("d"));
                typeQuery.Add(qt, Occur.SHOULD);
            }

            bquery.Add(typeQuery, Occur.MUST);

            Sort sort = new Sort(new SortField("updatetime", SortField.STRING, true));

            count = 0;

            var list = SearchHelper.Search <BaseIndexModel>(indexPath, bquery, sort, pageIndex, pageSize, out count);

            return(list);
        }