Search in sources :

Example 1 with AccumulatedNumLinesLOC

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");
}
Also used : AccumulatedNumLinesLOC(org.opengrok.indexer.analysis.AccumulatedNumLinesLOC) Test(org.junit.jupiter.api.Test) List(java.util.List) NumLinesLOC(org.opengrok.indexer.analysis.NumLinesLOC) AccumulatedNumLinesLOC(org.opengrok.indexer.analysis.AccumulatedNumLinesLOC) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Comparator(java.util.Comparator) ArrayList(java.util.ArrayList) NumLinesLOC(org.opengrok.indexer.analysis.NumLinesLOC) AccumulatedNumLinesLOC(org.opengrok.indexer.analysis.AccumulatedNumLinesLOC) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 2 with AccumulatedNumLinesLOC

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");
}
Also used : AccumulatedNumLinesLOC(org.opengrok.indexer.analysis.AccumulatedNumLinesLOC) NumLinesLOC(org.opengrok.indexer.analysis.NumLinesLOC) AccumulatedNumLinesLOC(org.opengrok.indexer.analysis.AccumulatedNumLinesLOC) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 3 with AccumulatedNumLinesLOC

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);
    }
}
Also used : AccumulatedNumLinesLOC(org.opengrok.indexer.analysis.AccumulatedNumLinesLOC) HashMap(java.util.HashMap) Document(org.apache.lucene.document.Document)

Example 4 with AccumulatedNumLinesLOC

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);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) AccumulatedNumLinesLOC(org.opengrok.indexer.analysis.AccumulatedNumLinesLOC) TopDocs(org.apache.lucene.search.TopDocs) TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term)

Aggregations

AccumulatedNumLinesLOC (org.opengrok.indexer.analysis.AccumulatedNumLinesLOC)4 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 NumLinesLOC (org.opengrok.indexer.analysis.NumLinesLOC)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Document (org.apache.lucene.document.Document)1 Term (org.apache.lucene.index.Term)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 Query (org.apache.lucene.search.Query)1 TermQuery (org.apache.lucene.search.TermQuery)1 TopDocs (org.apache.lucene.search.TopDocs)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1