use of org.opengrok.indexer.analysis.CompatibleAnalyser in project OpenGrok by OpenGrok.
the class SummarizerTest method bug15858.
/**
* If the last token in a text fragment is a token we're searching for,
* and that token is also present earlier in the fragment, getSummary()
* used to throw a StringIndexOutOfBoundsException. Bug #15858.
* @throws Exception exception
*/
@Test
public void bug15858() throws Exception {
Query query = new QueryBuilder().setFreetext("beta").build();
Summarizer instance = new Summarizer(query, new CompatibleAnalyser());
// This call used to result in a StringIndexOutOfBoundsException
assertNotNull(instance.getSummary("alpha beta gamma delta beta"));
}
use of org.opengrok.indexer.analysis.CompatibleAnalyser in project OpenGrok by OpenGrok.
the class NumLinesLOCAccessor method newDSearch.
private DSearchResult newDSearch(IndexReader reader, int n) throws IOException {
// Search for existing documents with QueryBuilder.D.
IndexSearcher searcher = new IndexSearcher(reader);
Query query;
try {
QueryParser parser = new QueryParser(QueryBuilder.D, new CompatibleAnalyser());
parser.setAllowLeadingWildcard(true);
query = parser.parse("*");
} catch (ParseException ex) {
// This is not expected, so translate to RuntimeException.
throw new RuntimeException(ex);
}
TopDocs topDocs = searcher.search(query, n);
return new DSearchResult(searcher, topDocs);
}
use of org.opengrok.indexer.analysis.CompatibleAnalyser in project OpenGrok by OpenGrok.
the class NumLinesLOCAccessor method register.
/**
* Queries the stored counts from the specified reader to register them to
* the specified aggregator.
* @return a value indicating whether any defined number-of-lines and
* lines-of-code were found
*/
public boolean register(NumLinesLOCAggregator countsAggregator, IndexReader reader) throws IOException {
/*
* Search for existing documents with any value of PATH. Those are
* documents representing source code files, as opposed to source code
* directories or other object data (e.g. IndexAnalysisSettings3), which
* have no stored PATH.
*/
IndexSearcher searcher = new IndexSearcher(reader);
Query query;
try {
QueryParser parser = new QueryParser(QueryBuilder.PATH, new CompatibleAnalyser());
parser.setAllowLeadingWildcard(true);
query = parser.parse("*");
} catch (ParseException ex) {
// This is not expected, so translate to RuntimeException.
throw new RuntimeException(ex);
}
TopDocs hits = searcher.search(query, Integer.MAX_VALUE);
return processFileCounts(countsAggregator, searcher, hits);
}
use of org.opengrok.indexer.analysis.CompatibleAnalyser in project OpenGrok by OpenGrok.
the class IndexAnalysisSettingsAccessor method read.
/**
* Searches for documents with a {@link QueryBuilder#OBJUID} value matching
* {@link #INDEX_ANALYSIS_SETTINGS_OBJUID}.
* @param reader a defined instance
* @param n a limit to the number of documents returned. The method may
* return less.
* @return a defined instance, which is empty if none could be found
* @throws IOException if I/O error occurs while searching Lucene
*/
public IndexAnalysisSettings3[] read(IndexReader reader, int n) throws IOException {
IndexSearcher searcher = new IndexSearcher(reader);
Query q;
try {
q = new QueryParser(QueryBuilder.OBJUID, new CompatibleAnalyser()).parse(INDEX_ANALYSIS_SETTINGS_OBJUID);
} catch (ParseException ex) {
// This is not expected, so translate to RuntimeException.
throw new RuntimeException(ex);
}
TopDocs top = searcher.search(q, n);
int nres = top.totalHits.value > n ? n : (int) top.totalHits.value;
IndexAnalysisSettings3[] res = new IndexAnalysisSettings3[nres];
IndexAnalysisSettingsUpgrader upgrader = new IndexAnalysisSettingsUpgrader();
for (int i = 0; i < nres; ++i) {
Document doc = searcher.doc(top.scoreDocs[i].doc);
IndexableField objser = doc.getField(QueryBuilder.OBJSER);
int objver = readObjectVersion(doc);
try {
res[i] = objser == null ? null : upgrader.upgrade(objser.binaryValue().bytes, objver);
} catch (ClassNotFoundException ex) {
// This is not expected, so translate to RuntimeException.
throw new RuntimeException(ex);
}
}
return res;
}
use of org.opengrok.indexer.analysis.CompatibleAnalyser in project OpenGrok by OpenGrok.
the class SearchHelper method prepareSummary.
/**
* Prepare the fields to support printing a full blown summary. Does nothing
* if {@link #redirect} or {@link #errorMsg} have a none-{@code null} value.
*
* <p>
* Parameters which should be populated/set at this time: <ul>
* <li>{@link #query}</li> <li>{@link #builder}</li> </ul> Populates/sets:
* Otherwise the following fields are set (includes {@code null}): <ul>
* <li>{@link #sourceContext}</li> <li>{@link #summarizer}</li>
* <li>{@link #historyContext}</li> </ul>
*
* @return this instance.
*/
public SearchHelper prepareSummary() {
if (redirect != null || errorMsg != null) {
return this;
}
try {
sourceContext = new Context(query, builder);
summarizer = new Summarizer(query, new CompatibleAnalyser());
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Summarizer: {0}", e.getMessage());
}
try {
historyContext = new HistoryContext(query);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "HistoryContext: {0}", e.getMessage());
}
return this;
}
Aggregations