use of org.olat.search.SearchResults in project OpenOLAT by OpenOLAT.
the class SearchServiceImpl method doSearch.
/**
* Do search a certain query. The results will be filtered for the identity and roles.
* @param queryString Search query-string.
* @param identity Filter results for this identity (user).
* @param roles Filter results for this roles (role of user).
* @return SearchResults object for this query
*/
@Override
public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, int firstResult, int maxResults, boolean doHighlighting) throws ServiceNotAvailableException, ParseException {
Future<SearchResults> futureResults = null;
try {
SearchCallable run = new SearchCallable(queryString, condQueries, identity, roles, firstResult, maxResults, doHighlighting, this);
futureResults = searchExecutor.submit(run);
SearchResults results = futureResults.get(searchModuleConfig.getSearchTimeout(), TimeUnit.SECONDS);
queryCount++;
return results;
} catch (InterruptedException e) {
log.error("", e);
return null;
} catch (TimeoutException e) {
cancelSearch(futureResults);
log.error("", e);
return null;
} catch (ExecutionException e) {
Throwable e1 = e.getCause();
if (e1 instanceof ParseException) {
throw (ParseException) e1;
} else if (e1 instanceof ServiceNotAvailableException) {
throw (ServiceNotAvailableException) e1;
}
log.error("", e);
return null;
}
}
use of org.olat.search.SearchResults in project openolat by klemens.
the class EPFrontendManager method fulltextSearchAfterArtefacts.
private List<Long> fulltextSearchAfterArtefacts(EPFilterSettings filterSettings, Identity identity, Roles roles) {
String query = filterSettings.getTextFilter();
if (StringHelper.containsNonWhitespace(query)) {
try {
List<String> queries = new ArrayList<String>();
appendAnd(queries, AbstractOlatDocument.RESERVED_TO, ":\"", identity.getKey().toString(), "\"");
appendAnd(queries, "(", AbstractOlatDocument.DOCUMENTTYPE_FIELD_NAME, ":(", PortfolioArtefactIndexer.TYPE, "*))");
SearchResults searchResults = searchClient.doSearch(query, queries, identity, roles, 0, 1000, false);
List<Long> keys = new ArrayList<Long>();
if (searchResults != null) {
String marker = AbstractArtefact.class.getSimpleName();
for (ResultDocument doc : searchResults.getList()) {
String businessPath = doc.getResourceUrl();
int start = businessPath.indexOf(marker);
if (start > 0) {
start += marker.length() + 1;
int stop = businessPath.indexOf(']', start);
if (stop < businessPath.length()) {
String keyStr = businessPath.substring(start, stop);
try {
keys.add(Long.parseLong(keyStr));
} catch (Exception e) {
log.error("Not a primary key: " + keyStr, e);
}
}
}
}
}
return keys;
} catch (Exception e) {
log.error("", e);
return Collections.emptyList();
}
} else
return Collections.emptyList();
}
use of org.olat.search.SearchResults in project openolat by klemens.
the class SearchServiceImpl method doSearch.
/**
* Do search a certain query. The results will be filtered for the identity and roles.
* @param queryString Search query-string.
* @param identity Filter results for this identity (user).
* @param roles Filter results for this roles (role of user).
* @return SearchResults object for this query
*/
@Override
public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, int firstResult, int maxResults, boolean doHighlighting) throws ServiceNotAvailableException, ParseException {
Future<SearchResults> futureResults = null;
try {
SearchCallable run = new SearchCallable(queryString, condQueries, identity, roles, firstResult, maxResults, doHighlighting, this);
futureResults = searchExecutor.submit(run);
SearchResults results = futureResults.get(searchModuleConfig.getSearchTimeout(), TimeUnit.SECONDS);
queryCount++;
return results;
} catch (InterruptedException e) {
log.error("", e);
return null;
} catch (TimeoutException e) {
cancelSearch(futureResults);
log.error("", e);
return null;
} catch (ExecutionException e) {
Throwable e1 = e.getCause();
if (e1 instanceof ParseException) {
throw (ParseException) e1;
} else if (e1 instanceof ServiceNotAvailableException) {
throw (ServiceNotAvailableException) e1;
}
log.error("", e);
return null;
}
}
use of org.olat.search.SearchResults in project openolat by klemens.
the class SearchClientProxy method doSearch.
/**
* Uses Request/reply mechanism for synchronous operation.
* @see org.olat.search.service.searcher.OLATSearcher#doSearch(java.lang.String, org.olat.core.id.Identity, org.olat.core.id.Roles, boolean)
*/
@Override
public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, int firstResult, int maxResults, boolean doHighlighting) throws ServiceNotAvailableException, ParseException, QueryException {
boolean isDebug = log.isDebug();
if (isDebug) {
log.debug("STARTqueryString=" + queryString);
}
SearchRequest searchRequest = new SearchRequest(queryString, condQueries, identity.getKey(), roles, firstResult, maxResults, doHighlighting);
Session session = null;
try {
session = acquireSession();
if (isDebug) {
log.debug("doSearch session=" + session);
}
Message requestMessage = session.createObjectMessage(searchRequest);
Message returnedMessage = doSearchRequest(session, requestMessage);
queryCount_++;
if (returnedMessage != null) {
String responseStatus = returnedMessage.getStringProperty(JMS_RESPONSE_STATUS_PROPERTY_NAME);
if (responseStatus.equalsIgnoreCase(JMS_RESPONSE_STATUS_OK)) {
SearchResults searchResult = (SearchResults) ((ObjectMessage) returnedMessage).getObject();
if (isDebug) {
log.debug("ENDqueryString=" + queryString);
}
return searchResult;
} else if (responseStatus.equalsIgnoreCase(JMS_RESPONSE_STATUS_PARSE_EXCEPTION)) {
throw new ParseException("can not parse query=" + queryString);
} else if (responseStatus.equalsIgnoreCase(JMS_RESPONSE_STATUS_QUERY_EXCEPTION)) {
throw new QueryException("invalid query=" + queryString);
} else if (responseStatus.equalsIgnoreCase(JMS_RESPONSE_STATUS_SERVICE_NOT_AVAILABLE_EXCEPTION)) {
throw new ServiceNotAvailableException("Remote search service not available" + queryString);
} else {
log.warn("doSearch: receive unkown responseStatus=" + responseStatus);
return null;
}
} else {
// null returnedMessage
throw new ServiceNotAvailableException("communication error with JMS - cannot receive messages!!!");
}
} catch (JMSException e) {
log.error("Search failure I", e);
throw new ServiceNotAvailableException("communication error with JMS - cannot send messages!!!");
} finally {
releaseSession(session);
}
}
use of org.olat.search.SearchResults in project openolat by klemens.
the class ResultsSearchController method doSearch.
private void doSearch(UserRequest ureq, int firstResult) {
SearchResults results;
if (extendedSearch) {
String query = advancedSearchController.getSearchString();
List<String> condQueries = advancedSearchController.getQueryStrings();
String key = advancedSearchController.getContext();
if (advancedSearchController.isDocumentTypesSelected()) {
// if document types are selected, these queries overwrite the conditional query for document type
// set in this controller
results = doSearch(ureq, query, condQueries, getParentContext(), null, key, firstResult, RESULT_PER_PAGE, true);
} else {
results = doSearch(ureq, query, condQueries, getParentContext(), getDocumentType(), key, firstResult, RESULT_PER_PAGE, true);
}
} else {
String searchString = getSearchString();
if (StringHelper.containsNonWhitespace(searchString)) {
String key = null;
if (contextSelection.isOneSelected()) {
key = contextSelection.getSelectedKey();
}
results = doSearch(ureq, searchString, null, getParentContext(), getDocumentType(), key, firstResult, RESULT_PER_PAGE, true);
} else {
results = SearchResults.EMPTY_SEARCH_RESULTS;
}
}
if (firstResult == 0) {
resultCtlr.setSearchResults(ureq, results);
} else {
resultCtlr.nextSearchResults(ureq, results);
}
persistSearch();
}
Aggregations