关于Lucene分页标准

 public IEnumerable<SearchResult> Search(string keyword, string[] fieldNames, int pageSize, int pageIndex)

        {

            if (fieldNames.Length == 0)

            {

                return null;

            }



            // 计算开始的索引

            int start = pageSize * (pageIndex - 1);



            // 需要的记录数

            int count = start + pageSize;



            // 结果集

            TopScoreDocCollector results = TopScoreDocCollector.Create(count, false);



            try

            {

                var tem = new MultiPhraseQuery();



                QueryParser qp = new MultiFieldQueryParser(LuceneVersion.Version.LUCENE_30, fieldNames, analyzer);

                Query query = qp.Parse(keyword);

                // 查询填充结果集

                searcher.Search(query, results);

                //总条数

                var totalCount = results.TopDocs().TotalHits;

                //分页后的数据

                TopDocs topDocs = results.TopDocs(start, pageSize);







                return BuildSearchResult(topDocs, searcher);

            }

            catch (Exception ex)

            {

                throw ex;

            }

        }

 

你可能感兴趣的:(Lucene)