use of org.opengrok.indexer.analysis.AbstractAnalyzer in project OpenGrok by OpenGrok.
the class SearchAndContextFormatterTest method getFirstFragments.
private String[] getFirstFragments(SearchEngine instance) throws IOException {
ContextArgs args = new ContextArgs((short) 1, (short) 10);
/*
* The following `anz' should go unused, but UnifiedHighlighter demands
* an analyzer "even if in some circumstances it isn't used."
*/
PlainAnalyzerFactory fac = PlainAnalyzerFactory.DEFAULT_INSTANCE;
AbstractAnalyzer anz = fac.getAnalyzer();
ContextFormatter formatter = new ContextFormatter(args);
OGKUnifiedHighlighter uhi = new OGKUnifiedHighlighter(env, instance.getSearcher(), anz);
uhi.setBreakIterator(StrictLineBreakIterator::new);
uhi.setFormatter(formatter);
ScoreDoc[] docs = instance.scoreDocs();
for (ScoreDoc scoreDoc : docs) {
int docid = scoreDoc.doc;
Document doc = instance.doc(docid);
String path = doc.get(QueryBuilder.PATH);
System.out.println(path);
formatter.setUrl("/source" + path);
for (String contextField : instance.getQueryBuilder().getContextFields()) {
Map<String, String[]> res = uhi.highlightFields(new String[] { contextField }, instance.getQueryObject(), new int[] { docid }, new int[] { 10 });
String[] frags = res.getOrDefault(contextField, null);
if (frags != null) {
return frags;
}
}
}
return null;
}
use of org.opengrok.indexer.analysis.AbstractAnalyzer in project OpenGrok by OpenGrok.
the class SearchAndContextFormatterTest2 method getFirstFragments.
private String[] getFirstFragments(SearchEngine instance) throws IOException, InvalidTokenOffsetsException {
ContextArgs args = new ContextArgs((short) 1, (short) 10);
/*
* The following `anz' should go unused, but UnifiedHighlighter demands
* an analyzer "even if in some circumstances it isn't used."
*/
PlainAnalyzerFactory fac = PlainAnalyzerFactory.DEFAULT_INSTANCE;
AbstractAnalyzer anz = fac.getAnalyzer();
ContextFormatter formatter = new ContextFormatter(args);
OGKUnifiedHighlighter uhi = new OGKUnifiedHighlighter(env, instance.getSearcher(), anz);
uhi.setBreakIterator(StrictLineBreakIterator::new);
uhi.setFormatter(formatter);
uhi.setTabSize(TABSIZE);
ScoreDoc[] docs = instance.scoreDocs();
for (ScoreDoc scoreDoc : docs) {
int docid = scoreDoc.doc;
Document doc = instance.doc(docid);
String path = doc.get(QueryBuilder.PATH);
System.out.println(path);
formatter.setUrl("/source" + path);
for (String contextField : instance.getQueryBuilder().getContextFields()) {
Map<String, String[]> res = uhi.highlightFields(new String[] { contextField }, instance.getQueryObject(), new int[] { docid }, new int[] { 10 });
String[] frags = res.getOrDefault(contextField, null);
if (frags != null) {
return frags;
}
}
}
return null;
}
use of org.opengrok.indexer.analysis.AbstractAnalyzer in project OpenGrok by OpenGrok.
the class BZip2Analyzer method analyze.
@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException, InterruptedException {
AbstractAnalyzer fa;
StreamSource bzSrc = wrap(src);
String path = doc.get(QueryBuilder.PATH);
if (path != null && (path.endsWith(".bz2") || path.endsWith(".BZ2") || path.endsWith(".bz"))) {
String newname = path.substring(0, path.lastIndexOf('.'));
// System.err.println("BZIPPED OF = " + newname);
try (InputStream in = bzSrc.getStream()) {
fa = AnalyzerGuru.getAnalyzer(in, newname);
}
if (!(fa instanceof BZip2Analyzer)) {
if (fa.getGenre() == Genre.PLAIN || fa.getGenre() == Genre.XREFABLE) {
this.g = Genre.XREFABLE;
} else {
this.g = Genre.DATA;
}
fa.analyze(doc, bzSrc, xrefOut);
if (doc.get(QueryBuilder.T) != null) {
doc.removeField(QueryBuilder.T);
if (g == Genre.XREFABLE) {
doc.add(new Field(QueryBuilder.T, g.typeName(), AnalyzerGuru.string_ft_stored_nanalyzed_norms));
}
}
}
}
}
use of org.opengrok.indexer.analysis.AbstractAnalyzer in project OpenGrok by OpenGrok.
the class XMLAnalyzerTest method bug806.
@Test
public void bug806() throws IOException {
String xmlText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<server>\n" + " <mbean code=\"QuartzBean\" \n" + " name=\"user:service=QuartzService,name=QuartzService\">\n" + " <depends>jboss.jca:service=DataSourceBinding,name=ServerDS</depends>\n" + " <attribute name=\"JndiName\">Quartz</attribute>\n" + " <attribute name=\"Properties\">\n" + " org.quartz.plugin.jobInitializer.fileNames = ../server/default/conf/scheduler/quartz_jobs.xml\n" + " </attribute>\n" + " </mbean>\n" + "</server>";
StringReader sr = new StringReader(xmlText);
StringWriter sw = new StringWriter();
XMLAnalyzerFactory fac = new XMLAnalyzerFactory();
AbstractAnalyzer analyzer = fac.getAnalyzer();
analyzer.writeXref(new WriteXrefArgs(sr, sw));
String[] xref = sw.toString().split("\n");
// don't remove ../
assertTrue(xref[7].contains("org.quartz.plugin.jobInitializer.fileNames</a> = <a href=\"/source/s?path=../\">..</a>/"));
}
use of org.opengrok.indexer.analysis.AbstractAnalyzer in project OpenGrok by OpenGrok.
the class PhpXrefTest method basicTest.
@Test
public void basicTest() throws IOException {
String s = "<?php foo bar";
Writer w = new StringWriter();
PhpAnalyzerFactory fac = new PhpAnalyzerFactory();
AbstractAnalyzer analyzer = fac.getAnalyzer();
WriteXrefArgs xargs = new WriteXrefArgs(new StringReader(s), w);
Xrefer xref = analyzer.writeXref(xargs);
assertEquals("<a class=\"l\" name=\"1\" href=\"#1\">1</a><strong><?php</strong> <a href=\"/" + "source/s?defs=foo\" class=\"intelliWindow-symbol\" data-definition-place=\"undefined-in-file\">foo</a>" + " <a href=\"/source/s?defs=bar\" class=\"intelliWindow-symbol\" data-definition-place=\"undefined-in-file\">bar</a>", w.toString());
assertEquals(1, xref.getLOC(), "PHP LOC");
}
Aggregations