*/
public SearchResults doSearch(String queryString, Identity identity, Roles roles, boolean doHighlighting) throws ServiceNotAvailableException, ParseException, QueryException {
try {
if (!existIndex()) {
log.warn("Index does not exist, can't search for queryString: "+queryString);
throw new ServiceNotAvailableException("Index does not exist");
}
synchronized (createIndexSearcherLock) {//o_clusterOK by:fj if service is only configured on one vm, which is recommended way
if (searcher == null) {
try {
createIndexSearcher(indexPath);
checkIsIndexUpToDate();
} catch(IOException ioEx) {
log.warn("Can not create searcher", ioEx);
throw new ServiceNotAvailableException("Index is not available");
}
}
if ( hasNewerIndexFile() ) {
reopenIndexSearcher();
checkIsIndexUpToDate();
}
}
log.info("queryString=" + queryString);
QueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_CURRENT, fields, analyzer);
queryParser.setLowercaseExpandedTerms(false);//some add. fields are not tokenized and not lowered case
Query query = queryParser.parse(queryString);
try {
query = searcher.rewrite(query);
} catch (Exception ex) {
throw new QueryException("Rewrite-Exception query because too many clauses. Query=" + query);
}
long startTime = System.currentTimeMillis();
int n = SearchServiceImpl.getInstance().getSearchModuleConfig().getMaxHits() + 1;
TopDocs docs = searcher.search(query, n);
long queryTime = System.currentTimeMillis() - startTime;
if (log.isDebug()) log.debug("hits.length()=" + docs.totalHits);
SearchResultsImpl searchResult = new SearchResultsImpl(searcher, docs, query, analyzer, identity, roles, doHighlighting);
searchResult.setQueryTime(queryTime);
searchResult.setNumberOfIndexDocuments(searcher.maxDoc());
queryCount++;
return searchResult;
} catch (ServiceNotAvailableException naex) {
// pass exception
throw new ServiceNotAvailableException(naex.getMessage());
} catch (ParseException pex) {
throw new ParseException("can not parse query=" + queryString);
} catch (QueryException qex) {
throw new QueryException(qex.getMessage());
} catch (Exception ex) {
log.warn("Exception in search", ex);
throw new ServiceNotAvailableException(ex.getMessage());
}
}