Search in sources :

Example 6 with NullableNumLinesLOC

use of org.opengrok.indexer.analysis.NullableNumLinesLOC in project OpenGrok by OpenGrok.

the class NumLinesLOCAccessor method processFileCounts.

private boolean processFileCounts(NumLinesLOCAggregator countsAggregator, IndexSearcher searcher, TopDocs hits) throws IOException {
    boolean hasDefinedNumLines = false;
    for (ScoreDoc sd : hits.scoreDocs) {
        Document d = searcher.doc(sd.doc);
        NullableNumLinesLOC counts = NumLinesLOCUtil.read(d);
        if (counts.getNumLines() != null && counts.getLOC() != null) {
            NumLinesLOC defCounts = new NumLinesLOC(counts.getPath(), counts.getNumLines(), counts.getLOC());
            countsAggregator.register(defCounts);
            hasDefinedNumLines = true;
        }
    }
    return hasDefinedNumLines;
}
Also used : NullableNumLinesLOC(org.opengrok.indexer.analysis.NullableNumLinesLOC) NumLinesLOC(org.opengrok.indexer.analysis.NumLinesLOC) NullableNumLinesLOC(org.opengrok.indexer.analysis.NullableNumLinesLOC) AccumulatedNumLinesLOC(org.opengrok.indexer.analysis.AccumulatedNumLinesLOC) Document(org.apache.lucene.document.Document) ScoreDoc(org.apache.lucene.search.ScoreDoc)

Example 7 with NullableNumLinesLOC

use of org.opengrok.indexer.analysis.NullableNumLinesLOC in project OpenGrok by OpenGrok.

the class DirectoryExtraReader method processHits.

private List<NullableNumLinesLOC> processHits(IndexSearcher searcher, TopDocs hits) throws IOException {
    List<NullableNumLinesLOC> results = new ArrayList<>();
    for (ScoreDoc sd : hits.scoreDocs) {
        Document d = searcher.doc(sd.doc);
        NullableNumLinesLOC extra = NumLinesLOCUtil.read(d);
        results.add(extra);
    }
    return results;
}
Also used : NullableNumLinesLOC(org.opengrok.indexer.analysis.NullableNumLinesLOC) ArrayList(java.util.ArrayList) Document(org.apache.lucene.document.Document) ScoreDoc(org.apache.lucene.search.ScoreDoc)

Example 8 with NullableNumLinesLOC

use of org.opengrok.indexer.analysis.NullableNumLinesLOC in project OpenGrok by OpenGrok.

the class DirectoryExtraReader method search.

/**
 * Search for supplemental file information in the specified {@code path}.
 * @param searcher a defined instance
 * @param path a defined path to qualify the search
 * @return a list of results, limited to 2000 values
 * @throws IOException if an error occurs searching the index
 */
public List<NullableNumLinesLOC> search(IndexSearcher searcher, String path) throws IOException {
    if (searcher == null) {
        throw new IllegalArgumentException("`searcher' is null");
    }
    if (path == null) {
        throw new IllegalArgumentException("`path' is null");
    }
    QueryBuilder qbuild = new QueryBuilder();
    qbuild.setDirPath(path);
    Query query;
    try {
        query = qbuild.build();
    } catch (ParseException e) {
        final String PARSE_ERROR = "An error occurred while parsing dirpath query";
        LOGGER.log(Level.WARNING, PARSE_ERROR, e);
        throw new IOException(PARSE_ERROR);
    }
    Statistics stat = new Statistics();
    TopDocs hits = searcher.search(query, DIR_LIMIT_NUM);
    stat.report(LOGGER, Level.FINEST, "search via DirectoryExtraReader done", "search.latency", new String[] { "category", "extra", "outcome", hits.scoreDocs.length > 0 ? "success" : "empty" });
    List<NullableNumLinesLOC> results = processHits(searcher, hits);
    return results;
}
Also used : TopDocs(org.apache.lucene.search.TopDocs) NullableNumLinesLOC(org.opengrok.indexer.analysis.NullableNumLinesLOC) Query(org.apache.lucene.search.Query) ParseException(org.apache.lucene.queryparser.classic.ParseException) IOException(java.io.IOException) Statistics(org.opengrok.indexer.util.Statistics)

Aggregations

NullableNumLinesLOC (org.opengrok.indexer.analysis.NullableNumLinesLOC)8 Document (org.apache.lucene.document.Document)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ScoreDoc (org.apache.lucene.search.ScoreDoc)2 NumLinesLOC (org.opengrok.indexer.analysis.NumLinesLOC)2 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Term (org.apache.lucene.index.Term)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 Query (org.apache.lucene.search.Query)1 TopDocs (org.apache.lucene.search.TopDocs)1 AccumulatedNumLinesLOC (org.opengrok.indexer.analysis.AccumulatedNumLinesLOC)1 DirectoryEntry (org.opengrok.indexer.search.DirectoryEntry)1 Statistics (org.opengrok.indexer.util.Statistics)1