Search in sources :

Example 1 with HistoryReader

use of org.opensolaris.opengrok.history.HistoryReader in project OpenGrok by OpenGrok.

the class AnalyzerGuru method populateDocument.

/**
     * Populate a Lucene document with the required fields.
     *
     * @param doc The document to populate
     * @param file The file to index
     * @param path Where the file is located (from source root)
     * @param fa The analyzer to use on the file
     * @param xrefOut Where to write the xref (possibly {@code null})
     * @throws IOException If an exception occurs while collecting the data
     */
public void populateDocument(Document doc, File file, String path, FileAnalyzer fa, Writer xrefOut) throws IOException {
    String date = DateTools.timeToString(file.lastModified(), DateTools.Resolution.MILLISECOND);
    doc.add(new Field(QueryBuilder.U, Util.path2uid(path, date), string_ft_stored_nanalyzed_norms));
    doc.add(new Field(QueryBuilder.FULLPATH, file.getAbsolutePath(), string_ft_nstored_nanalyzed_norms));
    doc.add(new SortedDocValuesField(QueryBuilder.FULLPATH, new BytesRef(file.getAbsolutePath())));
    try {
        HistoryReader hr = HistoryGuru.getInstance().getHistoryReader(file);
        if (hr != null) {
            doc.add(new TextField(QueryBuilder.HIST, hr));
        // date = hr.getLastCommentDate() //RFE
        }
    } catch (HistoryException e) {
        LOGGER.log(Level.WARNING, "An error occurred while reading history: ", e);
    }
    doc.add(new Field(QueryBuilder.DATE, date, string_ft_stored_nanalyzed_norms));
    doc.add(new SortedDocValuesField(QueryBuilder.DATE, new BytesRef(date)));
    if (path != null) {
        doc.add(new TextField(QueryBuilder.PATH, path, Store.YES));
        Project project = Project.getProject(path);
        if (project != null) {
            doc.add(new TextField(QueryBuilder.PROJECT, project.getPath(), Store.YES));
        }
    }
    if (fa != null) {
        Genre g = fa.getGenre();
        if (g == Genre.PLAIN || g == Genre.XREFABLE || g == Genre.HTML) {
            doc.add(new Field(QueryBuilder.T, g.typeName(), string_ft_stored_nanalyzed_norms));
        }
        fa.analyze(doc, StreamSource.fromFile(file), xrefOut);
        String type = fa.getFileTypeName();
        doc.add(new StringField(QueryBuilder.TYPE, type, Store.YES));
    }
}
Also used : SortedDocValuesField(org.apache.lucene.document.SortedDocValuesField) StringField(org.apache.lucene.document.StringField) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) Project(org.opensolaris.opengrok.configuration.Project) HistoryException(org.opensolaris.opengrok.history.HistoryException) StringField(org.apache.lucene.document.StringField) SortedDocValuesField(org.apache.lucene.document.SortedDocValuesField) TextField(org.apache.lucene.document.TextField) Genre(org.opensolaris.opengrok.analysis.FileAnalyzer.Genre) BytesRef(org.apache.lucene.util.BytesRef) HistoryReader(org.opensolaris.opengrok.history.HistoryReader)

Aggregations

Field (org.apache.lucene.document.Field)1 SortedDocValuesField (org.apache.lucene.document.SortedDocValuesField)1 StringField (org.apache.lucene.document.StringField)1 TextField (org.apache.lucene.document.TextField)1 BytesRef (org.apache.lucene.util.BytesRef)1 Genre (org.opensolaris.opengrok.analysis.FileAnalyzer.Genre)1 Project (org.opensolaris.opengrok.configuration.Project)1 HistoryException (org.opensolaris.opengrok.history.HistoryException)1 HistoryReader (org.opensolaris.opengrok.history.HistoryReader)1