public static List <SearchResult> SeartchContact(string keyword, int startIndex, int pageSize, out int totalCount)
        {
            FSDirectory   directory = FSDirectory.Open(new DirectoryInfo(ContactIndexPath), new NoLockFactory());
            IndexReader   reader    = IndexReader.Open(directory, true);
            IndexSearcher searcher  = new IndexSearcher(reader);

            IEnumerable <string> keyList = SplitHelper.SplitWords(keyword);

            PhraseQuery queryContact = new PhraseQuery();

            foreach (var key in keyList)
            {
                queryContact.Add(new Term("contactInfo", key));
            }
            queryContact.SetSlop(100);

            BooleanQuery query = new BooleanQuery();

            query.Add(queryContact, BooleanClause.Occur.SHOULD); // SHOULD => 表示或者

            // TopScoreDocCollector:盛放查询结果的容器
            TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true);

            // 使用query这个查询条件进行搜索,搜索结果放入collector
            searcher.Search(query, null, collector);
            // 首先获取总条数
            totalCount = collector.GetTotalHits();
            // 从查询结果中取出第m条到第n条的数据
            ScoreDoc[] docs = collector.TopDocs(startIndex, pageSize).scoreDocs;
            // 遍历查询结果
            List <SearchResult> resultList = new List <SearchResult>();

            for (int i = 0; i < docs.Length; i++)
            {
                // 拿到文档的id
                int docId = docs[i].doc;
                // 所以查询结果中只有id,具体内容需要二次查询
                // 根据id查询内容:放进去的是Document,查出来的还是Document
                Lucene.Net.Documents.Document doc = searcher.Doc(docId);
                SearchResult result = new SearchResult();
                result.UserId      = doc.Get("id");
                result.Name        = doc.Get("name");
                result.Email       = doc.Get("email");
                result.PhoneNumber = doc.Get("phone");
                result.Position    = doc.Get("position");
                resultList.Add(result);
            }

            return(resultList);
        }
        public static List <int> SeartchUser(string keyword)
        {
            FSDirectory   directory = FSDirectory.Open(new DirectoryInfo(UserInfoIndexPath), new NoLockFactory());
            IndexReader   reader    = IndexReader.Open(directory, true);
            IndexSearcher searcher  = new IndexSearcher(reader);

            IEnumerable <string> keyList = SplitHelper.SplitWords(keyword);

            PhraseQuery queryUserInfo = new PhraseQuery();

            foreach (var key in keyList)
            {
                queryUserInfo.Add(new Term("userInfo", key));
            }
            queryUserInfo.SetSlop(100);

            BooleanQuery query = new BooleanQuery();

            query.Add(queryUserInfo, BooleanClause.Occur.SHOULD);


            // TopScoreDocCollector:盛放查询结果的容器
            TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true);

            // 使用query这个查询条件进行搜索,搜索结果放入collector
            searcher.Search(query, null, collector);
            // 首先获取总条数
            int totalCount = collector.GetTotalHits();

            //这里取所有的数据 以方便后续的查找。
            ScoreDoc[] docs = collector.TopDocs(0, totalCount).scoreDocs;
            // 遍历查询结果
            List <int> resultList = new List <int>();

            for (int i = 0; i < docs.Length; i++)
            {
                // 拿到文档的id,因为Document可能非常占内存(DataSet和DataReader的区别)
                int docId = docs[i].doc;
                // 所以查询结果中只有id,具体内容需要二次查询
                // 根据id查询内容:放进去的是Document,查出来的还是Document
                Lucene.Net.Documents.Document doc = searcher.Doc(docId);
                int uid = Convert.ToInt32(doc.Get("id"));
                resultList.Add(uid);
            }

            return(resultList);
        }