use of org.olat.search.ServiceNotAvailableException in project OpenOLAT by OpenOLAT.
the class SearchOrderByCallable method call.
@Override
public List<Long> call() {
IndexSearcher searcher = null;
int found = -1;
try {
if (!searchService.existIndex()) {
log.warn("Index does not exist, can't search for queryString: " + queryString);
throw new ServiceNotAvailableException("Index does not exist");
}
searcher = searchService.getIndexSearcher();
BooleanQuery query = searchService.createQuery(queryString, condQueries);
// only search document with an primary key
String idNotNull = AbstractOlatDocument.DB_ID_NAME + ":[* TO *]";
QueryParser idQueryParser = new QueryParser(SearchService.OO_LUCENE_VERSION, idNotNull, searchService.getAnalyzer());
Query idQuery = idQueryParser.parse(idNotNull);
query.add(idQuery, Occur.MUST);
int n = searchService.getSearchModuleConfig().getMaxHits();
TopDocs docs;
if (orderBy != null && orderBy.length > 0 && orderBy[0] != null) {
SortField[] sortFields = new SortField[orderBy.length];
for (int i = 0; i < orderBy.length; i++) {
sortFields[i] = new SortField(orderBy[i].getKey(), SortField.Type.STRING_VAL, orderBy[i].isAsc());
}
Sort sort = new Sort(sortFields);
docs = searcher.search(query, n, sort);
} else {
docs = searcher.search(query, n);
}
int numOfDocs = Math.min(n, docs.totalHits);
Set<String> retrievedFields = new HashSet<String>();
retrievedFields.add(AbstractOlatDocument.DB_ID_NAME);
List<Long> res = new ArrayList<Long>();
for (int i = firstResult; i < numOfDocs && res.size() < maxResults; i++) {
Document doc = searcher.doc(docs.scoreDocs[i].doc, retrievedFields);
String dbKeyStr = doc.get(AbstractOlatDocument.DB_ID_NAME);
if (StringHelper.containsNonWhitespace(dbKeyStr)) {
res.add(Long.parseLong(dbKeyStr));
}
}
found = res.size();
return res;
} catch (Exception naex) {
log.error("", naex);
return null;
} finally {
searchService.releaseIndexSearcher(searcher);
DBFactory.getInstance().commitAndCloseSession();
log.info("queryString=" + queryString + " (" + found + " hits)");
}
}
use of org.olat.search.ServiceNotAvailableException 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.ServiceNotAvailableException in project OpenOLAT by OpenOLAT.
the class FileDocumentFactory method getDocumentFromCurrentIndex.
private Document getDocumentFromCurrentIndex(SearchResourceContext leafResourceContext, VFSLeaf leaf) {
try {
String resourceUrl = leafResourceContext.getResourceUrl();
SearchService searchService = CoreSpringFactory.getImpl(SearchServiceImpl.class);
Document indexedDoc = searchService.doSearch(resourceUrl);
if (indexedDoc != null) {
String timestamp = indexedDoc.get(AbstractOlatDocument.TIME_STAMP_NAME);
if (timestamp != null) {
Date indexLastModification = DateTools.stringToDate(timestamp);
Date docLastModificationDate = new Date(leaf.getLastModified());
if (leaf instanceof MetaTagged) {
MetaInfo metaInfo = ((MetaTagged) leaf).getMetaInfo();
Date metaDate = metaInfo.getMetaLastModified();
if (metaDate != null && metaDate.after(docLastModificationDate)) {
docLastModificationDate = metaDate;
}
}
if (docLastModificationDate.compareTo(indexLastModification) < 0) {
OlatDocument olatDoc = new OlatDocument(indexedDoc);
return olatDoc.getLuceneDocument();
}
}
}
} catch (ServiceNotAvailableException | ParseException | QueryException | java.text.ParseException e) {
log.error("", e);
}
return null;
}
use of org.olat.search.ServiceNotAvailableException in project OpenOLAT by OpenOLAT.
the class SearchClientProxy method spellCheck.
/**
* Uses Request/reply mechanism for synchronous operation.
* @see org.olat.search.service.searcher.OLATSearcher#spellCheck(java.lang.String)
*/
public Set<String> spellCheck(String query) throws ServiceNotAvailableException {
Session session = null;
try {
session = acquireSession();
TextMessage requestMessage = session.createTextMessage(query);
Message returnedMessage = doSearchRequest(session, requestMessage);
if (returnedMessage != null) {
@SuppressWarnings("unchecked") List<String> spellStringList = (List<String>) ((ObjectMessage) returnedMessage).getObject();
return new HashSet<String>(spellStringList);
} else {
// null returnedMessage
throw new ServiceNotAvailableException("spellCheck, communication error with JMS - cannot receive messages!!!");
}
} catch (JMSException e) {
throw new ServiceNotAvailableException("spellCheck, communication error with JMS - cannot send messages!!!");
} catch (ServiceNotAvailableException e) {
throw e;
} catch (Throwable th) {
throw new OLATRuntimeException("ClusteredSearchRequester.spellCheck() error!!!", th);
} finally {
releaseSession(session);
}
}
use of org.olat.search.ServiceNotAvailableException 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;
}
}
Aggregations