Search in sources :

Example 1 with HistoryContext

use of org.opensolaris.opengrok.search.context.HistoryContext in project OpenGrok by OpenGrok.

the class SearchEngine method search.

/**
     * Execute a search on projects or root file.
     *
     * If @param projects is an empty list it tries to search in @code
     * searchSingleDatabase with root set to @param root
     *
     * Call to search() must be eventually followed by call to destroy()
     * so that IndexSearcher objects are properly freed.
     *
     * @return The number of hits
     */
private int search(List<Project> projects, File root) {
    source = RuntimeEnvironment.getInstance().getSourceRootPath();
    data = RuntimeEnvironment.getInstance().getDataRootPath();
    docs.clear();
    QueryBuilder queryBuilder = createQueryBuilder();
    try {
        query = queryBuilder.build();
        if (query != null) {
            if (projects.isEmpty()) {
                // search the index database
                //NOTE this assumes that src does not contain any project, just
                // data files - so no authorization can be enforced
                searchSingleDatabase(root, true);
            } else {
                // search all projects
                //TODO support paging per project (in search.java)
                //TODO optimize if only one project by falling back to SingleDatabase ?
                //NOTE projects are already filtered if we accessed through web page @see search(HttpServletRequest)
                searchMultiDatabase(projects, false);
            }
        }
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, SEARCH_EXCEPTION_MSG, e);
    }
    if (!docs.isEmpty()) {
        sourceContext = null;
        summarizer = null;
        try {
            sourceContext = new Context(query, queryBuilder.getQueries());
            if (sourceContext.isEmpty()) {
                sourceContext = null;
            }
            summarizer = new Summarizer(query, analyzer);
        } catch (Exception e) {
            LOGGER.log(Level.WARNING, "An error occured while creating summary", e);
        }
        historyContext = null;
        try {
            historyContext = new HistoryContext(query);
            if (historyContext.isEmpty()) {
                historyContext = null;
            }
        } catch (Exception e) {
            LOGGER.log(Level.WARNING, "An error occured while getting history context", e);
        }
    }
    int count = hits == null ? 0 : hits.length;
    return count;
}
Also used : HistoryContext(org.opensolaris.opengrok.search.context.HistoryContext) Context(org.opensolaris.opengrok.search.context.Context) HistoryContext(org.opensolaris.opengrok.search.context.HistoryContext) ParseException(org.apache.lucene.queryparser.classic.ParseException) HistoryException(org.opensolaris.opengrok.history.HistoryException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with HistoryContext

use of org.opensolaris.opengrok.search.context.HistoryContext 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)

Aggregations

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