use of org.opengrok.indexer.search.context.Context 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 newBuilder = createQueryBuilder();
try {
query = newBuilder.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, newBuilder);
if (sourceContext.isEmpty()) {
sourceContext = null;
}
summarizer = new Summarizer(query, analyzer);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "An error occurred 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 occurred while getting history context", e);
}
}
int count = hits == null ? 0 : hits.length;
queryBuilder = newBuilder;
return count;
}
use of org.opengrok.indexer.search.context.Context 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