Search in sources :

Example 1 with CompatibleAnalyser

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"));
}
Also used : Query(org.apache.lucene.search.Query) CompatibleAnalyser(org.opengrok.indexer.analysis.CompatibleAnalyser) Test(org.junit.jupiter.api.Test)

Example 2 with CompatibleAnalyser

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);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) CompatibleAnalyser(org.opengrok.indexer.analysis.CompatibleAnalyser) ParseException(org.apache.lucene.queryparser.classic.ParseException)

Example 3 with CompatibleAnalyser

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);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) CompatibleAnalyser(org.opengrok.indexer.analysis.CompatibleAnalyser) ParseException(org.apache.lucene.queryparser.classic.ParseException)

Example 4 with CompatibleAnalyser

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;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Query(org.apache.lucene.search.Query) Document(org.apache.lucene.document.Document) TopDocs(org.apache.lucene.search.TopDocs) IndexableField(org.apache.lucene.index.IndexableField) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) CompatibleAnalyser(org.opengrok.indexer.analysis.CompatibleAnalyser) ParseException(org.apache.lucene.queryparser.classic.ParseException)

Example 5 with CompatibleAnalyser

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;
}
Also used : HistoryContext(org.opengrok.indexer.search.context.HistoryContext) Context(org.opengrok.indexer.search.context.Context) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) CompatibleAnalyser(org.opengrok.indexer.analysis.CompatibleAnalyser) HistoryContext(org.opengrok.indexer.search.context.HistoryContext) Summarizer(org.opengrok.indexer.search.Summarizer) ForbiddenSymlinkException(org.opengrok.indexer.util.ForbiddenSymlinkException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.apache.lucene.queryparser.classic.ParseException) IOException(java.io.IOException)

Aggregations

CompatibleAnalyser (org.opengrok.indexer.analysis.CompatibleAnalyser)5 ParseException (org.apache.lucene.queryparser.classic.ParseException)4 Query (org.apache.lucene.search.Query)4 QueryParser (org.apache.lucene.queryparser.classic.QueryParser)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)3 TopDocs (org.apache.lucene.search.TopDocs)3 TermQuery (org.apache.lucene.search.TermQuery)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Document (org.apache.lucene.document.Document)1 IndexableField (org.apache.lucene.index.IndexableField)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 Test (org.junit.jupiter.api.Test)1 Summarizer (org.opengrok.indexer.search.Summarizer)1 Context (org.opengrok.indexer.search.context.Context)1 HistoryContext (org.opengrok.indexer.search.context.HistoryContext)1 ForbiddenSymlinkException (org.opengrok.indexer.util.ForbiddenSymlinkException)1