use of org.opengrok.indexer.analysis.AccumulatedNumLinesLOC in project OpenGrok by OpenGrok.
the class NumLinesLOCAggregatorTest method shouldEnumerateToRoot.
@Test
public void shouldEnumerateToRoot() {
NumLinesLOCAggregator aggtor = new NumLinesLOCAggregator();
final String PATH = "/a/b/c/f0";
aggtor.register(new NumLinesLOC(PATH, 2, 1));
List<AccumulatedNumLinesLOC> counts = new ArrayList<>();
aggtor.iterator().forEachRemaining(counts::add);
counts.sort(Comparator.comparingInt(o -> o.getPath().length()));
assertEquals(4, counts.size(), "agg count");
AccumulatedNumLinesLOC entry = counts.get(0);
assertEquals("/", entry.getPath(), "counts[0] path");
assertEquals(2, entry.getNumLines(), "counts[0] numLines");
assertEquals(1, entry.getLOC(), "counts[0] LOC");
entry = counts.get(1);
assertEquals("/a", entry.getPath(), "counts[1] path");
assertEquals(2, entry.getNumLines(), "counts[1] numLines");
assertEquals(1, entry.getLOC(), "counts[1] LOC");
entry = counts.get(2);
assertEquals("/a/b", entry.getPath(), "counts[2] path");
assertEquals(2, entry.getNumLines(), "counts[2] numLines");
assertEquals(1, entry.getLOC(), "counts[2] LOC");
entry = counts.get(3);
assertEquals("/a/b/c", entry.getPath(), "counts[2] path");
assertEquals(2, entry.getNumLines(), "counts[2] numLines");
assertEquals(1, entry.getLOC(), "counts[2] LOC");
}
use of org.opengrok.indexer.analysis.AccumulatedNumLinesLOC in project OpenGrok by OpenGrok.
the class NumLinesLOCAggregatorTest method shouldAggregateToRoot.
@Test
public void shouldAggregateToRoot() {
NumLinesLOCAggregator aggtor = new NumLinesLOCAggregator();
aggtor.register(new NumLinesLOC("/a/b/f0", 2, 1));
aggtor.register(new NumLinesLOC("/a/c/f1", 5, 3));
aggtor.register(new NumLinesLOC("/a/f2", 11, 7));
List<AccumulatedNumLinesLOC> counts = new ArrayList<>();
aggtor.iterator().forEachRemaining(counts::add);
counts.sort(Comparator.comparingInt((AccumulatedNumLinesLOC o) -> o.getPath().length()).thenComparing(AccumulatedNumLinesLOC::getPath));
assertEquals(4, counts.size(), "agg count");
AccumulatedNumLinesLOC entry = counts.get(0);
assertEquals("/", entry.getPath(), "counts[0] path");
assertEquals(18, entry.getNumLines(), "counts[0] numLines");
assertEquals(11, entry.getLOC(), "counts[0] LOC");
entry = counts.get(1);
assertEquals("/a", entry.getPath(), "counts[1] path");
assertEquals(18, entry.getNumLines(), "counts[1] numLines");
assertEquals(11, entry.getLOC(), "counts[1] LOC");
entry = counts.get(2);
assertEquals("/a/b", entry.getPath(), "counts[2] path");
assertEquals(2, entry.getNumLines(), "counts[2] numLines");
assertEquals(1, entry.getLOC(), "counts[2] LOC");
entry = counts.get(3);
assertEquals("/a/c", entry.getPath(), "counts[2] path");
assertEquals(5, entry.getNumLines(), "counts[2] numLines");
assertEquals(3, entry.getLOC(), "counts[2] LOC");
}
use of org.opengrok.indexer.analysis.AccumulatedNumLinesLOC in project OpenGrok by OpenGrok.
the class NumLinesLOCAccessor method storeBulk.
private void storeBulk(IndexWriter writer, IndexReader reader, List<AccumulatedNumLinesLOC> counts, boolean isAggregatingDeltas) throws IOException {
DSearchResult searchResult = newDSearch(reader, Integer.MAX_VALUE);
// Index the existing document IDs by QueryBuilder.D.
HashMap<String, Integer> byDir = new HashMap<>();
int intMaximum = Integer.MAX_VALUE < searchResult.hits.totalHits.value ? Integer.MAX_VALUE : (int) searchResult.hits.totalHits.value;
for (int i = 0; i < intMaximum; ++i) {
int docID = searchResult.hits.scoreDocs[i].doc;
Document doc = searchResult.searcher.doc(docID);
String dirPath = doc.get(QueryBuilder.D);
byDir.put(dirPath, docID);
}
for (AccumulatedNumLinesLOC entry : counts) {
Integer docID = byDir.get(entry.getPath());
updateDocumentData(writer, searchResult.searcher, entry, docID, isAggregatingDeltas);
}
}
use of org.opengrok.indexer.analysis.AccumulatedNumLinesLOC in project OpenGrok by OpenGrok.
the class NumLinesLOCAccessor method storeIterative.
private void storeIterative(IndexWriter writer, IndexReader reader, List<AccumulatedNumLinesLOC> counts, boolean isAggregatingDeltas) throws IOException {
// Search for existing documents with QueryBuilder.D.
IndexSearcher searcher = new IndexSearcher(reader);
for (AccumulatedNumLinesLOC entry : counts) {
Query query = new TermQuery(new Term(QueryBuilder.D, entry.getPath()));
TopDocs hits = searcher.search(query, 1);
Integer docID = null;
if (hits.totalHits.value > 0) {
docID = hits.scoreDocs[0].doc;
}
updateDocumentData(writer, searcher, entry, docID, isAggregatingDeltas);
}
}
Aggregations