Search in sources :

Example 1 with CompatibleAnalyser

use of org.opensolaris.opengrok.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.getQueries());
        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;
}
Also used : HistoryContext(org.opensolaris.opengrok.search.context.HistoryContext) Context(org.opensolaris.opengrok.search.context.Context) CompatibleAnalyser(org.opensolaris.opengrok.analysis.CompatibleAnalyser) HistoryContext(org.opensolaris.opengrok.search.context.HistoryContext) Summarizer(org.opensolaris.opengrok.search.Summarizer) ParseException(org.apache.lucene.queryparser.classic.ParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with CompatibleAnalyser

use of org.opensolaris.opengrok.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.
     */
@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"));
}
Also used : Query(org.apache.lucene.search.Query) CompatibleAnalyser(org.opensolaris.opengrok.analysis.CompatibleAnalyser) Test(org.junit.Test)

Aggregations

CompatibleAnalyser (org.opensolaris.opengrok.analysis.CompatibleAnalyser)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 Query (org.apache.lucene.search.Query)1 Test (org.junit.Test)1 Summarizer (org.opensolaris.opengrok.search.Summarizer)1 Context (org.opensolaris.opengrok.search.context.Context)1 HistoryContext (org.opensolaris.opengrok.search.context.HistoryContext)1