Search in sources :

Example 6 with OGKTextField

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

the class TroffAnalyzer method analyze.

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
    // this is to explicitly use appropriate analyzers tokenstream to workaround #1376 symbols search works like full text search
    JFlexTokenizer symbolTokenizer = symbolTokenizerFactory.get();
    symbolTokenizer.setReader(getReader(src.getStream()));
    OGKTextField full = new OGKTextField(QueryBuilder.FULL, symbolTokenizer);
    doc.add(full);
    if (xrefOut != null) {
        try (Reader in = getReader(src.getStream())) {
            WriteXrefArgs args = new WriteXrefArgs(in, xrefOut);
            args.setProject(project);
            Xrefer xref = writeXref(args);
            String path = doc.get(QueryBuilder.PATH);
            addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC()));
        }
    }
}
Also used : JFlexTokenizer(org.opengrok.indexer.analysis.JFlexTokenizer) OGKTextField(org.opengrok.indexer.analysis.OGKTextField) NumLinesLOC(org.opengrok.indexer.analysis.NumLinesLOC) Xrefer(org.opengrok.indexer.analysis.Xrefer) Reader(java.io.Reader) WriteXrefArgs(org.opengrok.indexer.analysis.WriteXrefArgs)

Example 7 with OGKTextField

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

the class TarAnalyzer method analyze.

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
    ArrayList<String> names = new ArrayList<>();
    try (TarInputStream zis = new TarInputStream(src.getStream())) {
        TarEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            String name = entry.getName();
            names.add(name);
            if (xrefOut != null) {
                Util.htmlize(name, xrefOut);
                xrefOut.append("<br/>");
            }
        }
    }
    doc.add(new OGKTextField(QueryBuilder.FULL, new IteratorReader(names)));
}
Also used : OGKTextField(org.opengrok.indexer.analysis.OGKTextField) IteratorReader(org.opengrok.indexer.analysis.IteratorReader) TarInputStream(org.apache.tools.tar.TarInputStream) ArrayList(java.util.ArrayList) TarEntry(org.apache.tools.tar.TarEntry)

Example 8 with OGKTextField

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

the class ZipAnalyzer method analyze.

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
    ArrayList<String> names = new ArrayList<>();
    try (ZipInputStream zis = new ZipInputStream(src.getStream())) {
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            String name = entry.getName();
            names.add(name);
            if (xrefOut != null) {
                Util.htmlize(name, xrefOut);
                xrefOut.append("<br/>");
            }
        }
    }
    doc.add(new OGKTextField(QueryBuilder.FULL, new IteratorReader(names)));
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) OGKTextField(org.opengrok.indexer.analysis.OGKTextField) IteratorReader(org.opengrok.indexer.analysis.IteratorReader) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList)

Example 9 with OGKTextField

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

the class JavaClassAnalyzer method analyze.

void analyze(Document doc, InputStream in, Writer xrefOut, JFieldBuilder jfbuilder) throws IOException {
    List<String> defs = new ArrayList<>();
    List<String> refs = new ArrayList<>();
    List<String> full = new ArrayList<>();
    StringWriter dout, rout, fout;
    if (jfbuilder == null) {
        dout = new StringWriter();
        rout = new StringWriter();
        fout = new StringWriter();
    } else {
        dout = jfbuilder.write(QueryBuilder.DEFS);
        rout = jfbuilder.write(QueryBuilder.REFS);
        fout = jfbuilder.write(QueryBuilder.FULL);
    }
    ClassParser classparser = new ClassParser(in, doc.get(QueryBuilder.PATH));
    StringWriter xout = new StringWriter();
    getContent(xout, fout, classparser.parse(), defs, refs, full);
    String xref = xout.toString();
    if (xrefOut != null) {
        xrefOut.append(xref);
        try {
            xrefOut.flush();
        } catch (IOException ex) {
            LOGGER.log(Level.WARNING, "Couldn''t flush. Will retry once added to doc", ex);
        }
    }
    appendValues(dout, defs);
    appendValues(rout, refs);
    appendValues(fout, full);
    if (jfbuilder == null) {
        String dstr = dout.toString();
        doc.add(new OGKTextField(QueryBuilder.DEFS, dstr, Store.NO));
        String rstr = rout.toString();
        doc.add(new OGKTextField(QueryBuilder.REFS, rstr, Store.NO));
        String fstr = fout.toString();
        doc.add(new OGKTextField(QueryBuilder.FULL, fstr, Store.NO));
    }
}
Also used : OGKTextField(org.opengrok.indexer.analysis.OGKTextField) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) ConstantString(org.apache.bcel.classfile.ConstantString) IOException(java.io.IOException) ClassParser(org.apache.bcel.classfile.ClassParser)

Example 10 with OGKTextField

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

the class JarAnalyzer method analyze.

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
    JFieldBuilder jfbuilder = new JFieldBuilder();
    try (ZipInputStream zis = new ZipInputStream(src.getStream())) {
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            String ename = entry.getName();
            if (xrefOut != null) {
                xrefOut.append("<br/><b>");
                Util.htmlize(ename, xrefOut);
                xrefOut.append("</b>");
            }
            StringWriter fout = jfbuilder.write(QueryBuilder.FULL);
            fout.write(ename);
            fout.write("\n");
            AnalyzerFactory fac = AnalyzerGuru.find(ename);
            if (fac instanceof JavaClassAnalyzerFactory) {
                if (xrefOut != null) {
                    xrefOut.append("<br/>");
                }
                JavaClassAnalyzer jca = (JavaClassAnalyzer) fac.getAnalyzer();
                jca.analyze(doc, new BufferedInputStream(zis), xrefOut, jfbuilder);
            }
        }
    }
    for (String name : FIELD_NAMES) {
        if (jfbuilder.hasField(name)) {
            String fstr = jfbuilder.write(name).toString();
            doc.add(new OGKTextField(name, fstr, Store.NO));
        }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) OGKTextField(org.opengrok.indexer.analysis.OGKTextField) StringWriter(java.io.StringWriter) BufferedInputStream(java.io.BufferedInputStream) ZipEntry(java.util.zip.ZipEntry) AnalyzerFactory(org.opengrok.indexer.analysis.AnalyzerFactory)

Aggregations

OGKTextField (org.opengrok.indexer.analysis.OGKTextField)10 Reader (java.io.Reader)5 WriteXrefArgs (org.opengrok.indexer.analysis.WriteXrefArgs)5 JFlexTokenizer (org.opengrok.indexer.analysis.JFlexTokenizer)4 NumLinesLOC (org.opengrok.indexer.analysis.NumLinesLOC)4 Xrefer (org.opengrok.indexer.analysis.Xrefer)4 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 ZipEntry (java.util.zip.ZipEntry)2 ZipInputStream (java.util.zip.ZipInputStream)2 IteratorReader (org.opengrok.indexer.analysis.IteratorReader)2 BufferedInputStream (java.io.BufferedInputStream)1 RandomAccessFile (java.io.RandomAccessFile)1 ExecutionException (java.util.concurrent.ExecutionException)1 ClassParser (org.apache.bcel.classfile.ClassParser)1 ConstantString (org.apache.bcel.classfile.ConstantString)1 StoredField (org.apache.lucene.document.StoredField)1 TarEntry (org.apache.tools.tar.TarEntry)1 TarInputStream (org.apache.tools.tar.TarInputStream)1