Search in sources :

Example 1 with NullableNumLinesLOC

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

the class DirectoryListing method printNumlines.

private void printNumlines(Writer out, DirectoryEntry entry, boolean isDir) throws IOException {
    Long numlines = null;
    String readableNumlines = "";
    NullableNumLinesLOC extra = entry.getExtra();
    if (extra != null) {
        numlines = extra.getNumLines();
    }
    if (numlines != null) {
        readableNumlines = Util.readableCount(numlines, isDir);
    }
    out.write("<td class=\"numlines\">");
    out.write(readableNumlines);
    out.write("</td>");
}
Also used : NullableNumLinesLOC(org.opengrok.indexer.analysis.NullableNumLinesLOC)

Example 2 with NullableNumLinesLOC

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

the class FileExtraZipper method indexExtraByName.

private Map<String, NullableNumLinesLOC> indexExtraByName(List<NullableNumLinesLOC> extras) {
    Map<String, NullableNumLinesLOC> byPath = new HashMap<>();
    for (NullableNumLinesLOC extra : extras) {
        if (extra.getPath() != null) {
            File f = new File(extra.getPath());
            String filename = f.getName();
            byPath.put(filename, extra);
        }
    }
    return byPath;
}
Also used : NullableNumLinesLOC(org.opengrok.indexer.analysis.NullableNumLinesLOC) HashMap(java.util.HashMap) File(java.io.File)

Example 3 with NullableNumLinesLOC

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

the class FileExtraZipper method zip.

/**
 * Merge the specified lists by looking up a possible entry in
 * {@code extras} for every element in {@code files}.
 * @param dir the files' directory
 * @param files the file names
 * @param extras some OpenGrok-analyzed extra metadata
 * @return a list of the same size as {@code files}
 */
public List<DirectoryEntry> zip(File dir, List<String> files, List<NullableNumLinesLOC> extras) {
    if (extras == null) {
        return files.stream().map(f -> new DirectoryEntry(new File(dir, f))).collect(Collectors.toList());
    }
    Map<String, NullableNumLinesLOC> byName = indexExtraByName(extras);
    List<DirectoryEntry> result = new ArrayList<>(files.size());
    for (String file : files) {
        File fileobj = new File(dir, file);
        NullableNumLinesLOC extra = findExtra(byName, fileobj);
        DirectoryEntry entry = new DirectoryEntry(fileobj, extra);
        result.add(entry);
    }
    return result;
}
Also used : List(java.util.List) Map(java.util.Map) NullableNumLinesLOC(org.opengrok.indexer.analysis.NullableNumLinesLOC) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) DirectoryEntry(org.opengrok.indexer.search.DirectoryEntry) File(java.io.File) ArrayList(java.util.ArrayList) NullableNumLinesLOC(org.opengrok.indexer.analysis.NullableNumLinesLOC) ArrayList(java.util.ArrayList) DirectoryEntry(org.opengrok.indexer.search.DirectoryEntry) File(java.io.File)

Example 4 with NullableNumLinesLOC

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

the class IndexDatabase method removeFile.

/**
 * Remove a stale file (uidIter.term().text()) from the index database and
 * history cache, and queue the removal of xref.
 *
 * @param removeHistory if false, do not remove history cache for this file
 * @throws java.io.IOException if an error occurs
 */
private void removeFile(boolean removeHistory) throws IOException {
    String path = Util.uid2url(uidIter.term().utf8ToString());
    for (IndexChangedListener listener : listeners) {
        listener.fileRemove(path);
    }
    // Determine if a reversal of counts is necessary, and execute if so.
    if (isCountingDeltas) {
        postsIter = uidIter.postings(postsIter);
        while (postsIter.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
            // Read a limited-fields version of the document.
            Document doc = reader.document(postsIter.docID(), REVERT_COUNTS_FIELDS);
            if (doc != null) {
                NullableNumLinesLOC nullableCounts = NumLinesLOCUtil.read(doc);
                if (nullableCounts.getNumLines() != null && nullableCounts.getLOC() != null) {
                    NumLinesLOC counts = new NumLinesLOC(path, -nullableCounts.getNumLines(), -nullableCounts.getLOC());
                    countsAggregator.register(counts);
                }
                break;
            }
        }
    }
    writer.deleteDocuments(new Term(QueryBuilder.U, uidIter.term()));
    removeXrefFile(path);
    if (removeHistory) {
        removeHistoryFile(path);
    }
    setDirty();
    for (IndexChangedListener listener : listeners) {
        listener.fileRemoved(path);
    }
}
Also used : NullableNumLinesLOC(org.opengrok.indexer.analysis.NullableNumLinesLOC) NumLinesLOC(org.opengrok.indexer.analysis.NumLinesLOC) NullableNumLinesLOC(org.opengrok.indexer.analysis.NullableNumLinesLOC) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document)

Example 5 with NullableNumLinesLOC

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

the class DirectoryListing method printLoc.

private void printLoc(Writer out, DirectoryEntry entry, boolean isDir) throws IOException {
    Long loc = null;
    String readableLoc = "";
    NullableNumLinesLOC extra = entry.getExtra();
    if (extra != null) {
        loc = extra.getLOC();
    }
    if (loc != null) {
        readableLoc = Util.readableCount(loc, isDir);
    }
    out.write("<td class=\"loc\">");
    out.write(readableLoc);
    out.write("</td>");
}
Also used : NullableNumLinesLOC(org.opengrok.indexer.analysis.NullableNumLinesLOC)

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