|
48 | 48 | import org.apache.lucene.search.IndexSearcher; |
49 | 49 | import org.apache.lucene.search.Query; |
50 | 50 | import org.apache.lucene.search.ScoreDoc; |
51 | | -import org.apache.lucene.search.TopScoreDocCollectorManager; |
| 51 | +import org.apache.lucene.search.TopScoreDocCollector; |
52 | 52 | import org.apache.lucene.util.Version; |
53 | 53 | import org.opengrok.indexer.analysis.AbstractAnalyzer; |
54 | 54 | import org.opengrok.indexer.analysis.CompatibleAnalyser; |
@@ -132,7 +132,7 @@ public class SearchEngine { |
132 | 132 | int cachePages = RuntimeEnvironment.getInstance().getCachePages(); |
133 | 133 | int totalHits = 0; |
134 | 134 | private ScoreDoc[] hits; |
135 | | - private TopScoreDocCollectorManager collectorManager; |
| 135 | + private TopScoreDocCollector collector; |
136 | 136 | private IndexSearcher searcher; |
137 | 137 | boolean allCollected; |
138 | 138 | private final ArrayList<SuperIndexSearcher> searcherList = new ArrayList<>(); |
@@ -205,20 +205,18 @@ private void searchMultiDatabase(List<Project> projectList, boolean paging) thro |
205 | 205 | } |
206 | 206 |
|
207 | 207 | private void searchIndex(IndexSearcher searcher, boolean paging) throws IOException { |
208 | | - collectorManager = new TopScoreDocCollectorManager(hitsPerPage * cachePages, Short.MAX_VALUE); |
| 208 | + collector = TopScoreDocCollector.create(hitsPerPage * cachePages, Short.MAX_VALUE); |
209 | 209 | Statistics stat = new Statistics(); |
210 | | - hits = searcher.search(query, collectorManager).scoreDocs; |
211 | | - totalHits = searcher.count(query); |
| 210 | + searcher.search(query, collector); |
| 211 | + totalHits = collector.getTotalHits(); |
212 | 212 | stat.report(LOGGER, Level.FINEST, "search via SearchEngine done", |
213 | 213 | "search.latency", new String[]{"category", "engine", |
214 | 214 | "outcome", totalHits > 0 ? "success" : "empty"}); |
215 | | - if (!paging && totalHits > hitsPerPage * cachePages) { |
216 | | - collectorManager = new TopScoreDocCollectorManager(totalHits, Short.MAX_VALUE); |
217 | | - hits = searcher.search(query, collectorManager).scoreDocs; |
218 | | - stat.report(LOGGER, Level.FINEST, "FULL search via SearchEngine done", |
219 | | - "search.latency", new String[]{"category", "engine", |
220 | | - "outcome", totalHits > 0 ? "success" : "empty"}); |
| 215 | + if (!paging && totalHits > 0) { |
| 216 | + collector = TopScoreDocCollector.create(totalHits, Short.MAX_VALUE); |
| 217 | + searcher.search(query, collector); |
221 | 218 | } |
| 219 | + hits = collector.topDocs().scoreDocs; |
222 | 220 | StoredFields storedFields = searcher.storedFields(); |
223 | 221 | for (ScoreDoc hit : hits) { |
224 | 222 | int docId = hit.doc; |
@@ -414,13 +412,14 @@ public void results(int start, int end, List<Hit> ret) { |
414 | 412 | // TODO check if below fits for if end=old hits.length, or it should include it |
415 | 413 | if (end > hits.length && !allCollected) { |
416 | 414 | //do the requery, we want more than 5 pages |
417 | | - collectorManager = new TopScoreDocCollectorManager(totalHits, Short.MAX_VALUE); |
| 415 | + collector = TopScoreDocCollector.create(totalHits, Short.MAX_VALUE); |
418 | 416 | try { |
419 | | - hits = searcher.search(query, collectorManager).scoreDocs; |
| 417 | + searcher.search(query, collector); |
420 | 418 | } catch (Exception e) { // this exception should never be hit, since search() will hit this before |
421 | 419 | LOGGER.log( |
422 | 420 | Level.WARNING, SEARCH_EXCEPTION_MSG, e); |
423 | 421 | } |
| 422 | + hits = collector.topDocs().scoreDocs; |
424 | 423 | StoredFields storedFields = null; |
425 | 424 | try { |
426 | 425 | storedFields = searcher.storedFields(); |
|
0 commit comments