diff --git a/src/main/java/org/olat/search/service/SearchCallable.java b/src/main/java/org/olat/search/service/SearchCallable.java index 0c0aa5bcdbaa767ceb088a75acdd6b1cf6924f39..209120fb8fa70e04fd960c00d00d689cbe9cab7b 100644 --- a/src/main/java/org/olat/search/service/SearchCallable.java +++ b/src/main/java/org/olat/search/service/SearchCallable.java @@ -22,6 +22,7 @@ package org.olat.search.service; import java.util.List; import java.util.concurrent.Callable; +import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.TopDocs; @@ -66,7 +67,7 @@ class SearchCallable implements Callable<SearchResults> { } @Override - public SearchResults call() { + public SearchResults call() throws ParseException { try { boolean debug = log.isDebug(); @@ -80,17 +81,19 @@ class SearchCallable implements Callable<SearchResults> { BooleanQuery query = searchService.createQuery(queryString, condQueries); if(debug) log.debug("query=" + query); - long startTime = System.currentTimeMillis(); - int n = SearchServiceFactory.getService().getSearchModuleConfig().getMaxHits(); + long startTime = System.currentTimeMillis(); + int n = SearchServiceFactory.getService().getSearchModuleConfig().getMaxHits(); - TopDocs docs = searcher.search(query, n); - long queryTime = System.currentTimeMillis() - startTime; - if(debug) log.debug("hits.length()=" + docs.totalHits); - SearchResultsImpl searchResult = new SearchResultsImpl(searchService.getMainIndexer(), searcher, docs, query, searchService.getAnalyzer(), identity, roles, firstResult, maxResults, doHighlighting, false); - searchResult.setQueryTime(queryTime); - searchResult.setNumberOfIndexDocuments(docs.totalHits); + TopDocs docs = searcher.search(query, n); + long queryTime = System.currentTimeMillis() - startTime; + if(debug) log.debug("hits.length()=" + docs.totalHits); + SearchResultsImpl searchResult = new SearchResultsImpl(searchService.getMainIndexer(), searcher, docs, query, searchService.getAnalyzer(), identity, roles, firstResult, maxResults, doHighlighting, false); + searchResult.setQueryTime(queryTime); + searchResult.setNumberOfIndexDocuments(docs.totalHits); return searchResult; + } catch(ParseException pex) { + throw pex; } catch (Exception naex) { log.error("", naex); return null; diff --git a/src/main/java/org/olat/search/service/SearchServiceImpl.java b/src/main/java/org/olat/search/service/SearchServiceImpl.java index 6fe5b13e8b2e8d6142e38edba29fd9315a67d180..f68b96e68b1ba019a900c8bd509b1a042d96c428 100644 --- a/src/main/java/org/olat/search/service/SearchServiceImpl.java +++ b/src/main/java/org/olat/search/service/SearchServiceImpl.java @@ -32,6 +32,7 @@ import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Set; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; @@ -228,13 +229,23 @@ public class SearchServiceImpl implements SearchService { public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, int firstResult, int maxResults, boolean doHighlighting) throws ServiceNotAvailableException, ParseException { + try { SearchCallable run = new SearchCallable(queryString, condQueries, identity, roles, firstResult, maxResults, doHighlighting, this); Future<SearchResults> futureResults = searchExecutor.submit(run); SearchResults results = futureResults.get(); queryCount++; return results; - } catch (Exception e) { + } catch (InterruptedException e) { + 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; }