Skip to content

Commit 1204ce3

Browse files
author
Vladimir Kotal
committed
refactor to avoid duplicate code
1 parent 08ac2a3 commit 1204ce3

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/search/SearchEngine.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,7 @@ public boolean isValidQuery() {
188188
private void searchSingleDatabase(File root, boolean paging) throws IOException {
189189
IndexReader ireader = DirectoryReader.open(FSDirectory.open(root.toPath()));
190190
searcher = new IndexSearcher(ireader);
191-
collector = TopScoreDocCollector.create(hitsPerPage * cachePages);
192-
searcher.search(query, collector);
193-
totalHits = collector.getTotalHits();
194-
if (!paging && totalHits > 0) {
195-
collector = TopScoreDocCollector.create(totalHits);
196-
searcher.search(query, collector);
197-
}
198-
hits = collector.topDocs().scoreDocs;
199-
for (ScoreDoc hit : hits) {
200-
int docId = hit.doc;
201-
Document d = searcher.doc(docId);
202-
docs.add(d);
203-
}
191+
searchIndex(searcher, paging);
204192
}
205193

206194
/**
@@ -222,6 +210,10 @@ private void searchMultiDatabase(List<Project> root, boolean paging) throws IOEx
222210
MultiReader searchables = RuntimeEnvironment.getInstance().
223211
getMultiReader(projects, searcherList);
224212
searcher = new IndexSearcher(searchables);
213+
searchIndex(searcher, paging);
214+
}
215+
216+
private void searchIndex(IndexSearcher searcher, boolean paging) throws IOException {
225217
collector = TopScoreDocCollector.create(hitsPerPage * cachePages);
226218
searcher.search(query, collector);
227219
totalHits = collector.getTotalHits();

0 commit comments

Comments
 (0)