Search in sources :

Example 11 with ServiceNotAvailableException

use of org.olat.search.ServiceNotAvailableException in project OpenOLAT by OpenOLAT.

the class SearchInputController method doSearch.

protected SearchResults doSearch(UserRequest ureq, String searchString, List<String> condSearchStrings, String parentCtxt, String docType, String rsrcUrl, int firstResult, int maxReturns, boolean doSpellCheck) {
    String query = null;
    List<String> condQueries = null;
    try {
        if (doSpellCheck) {
            // remove first old "did you mean words"
            hideDidYouMeanWords();
        }
        query = getQueryString(searchString, false);
        condQueries = getCondQueryStrings(condSearchStrings, parentCtxt, docType, rsrcUrl);
        SearchResults searchResults = searchClient.doSearch(query, condQueries, ureq.getIdentity(), ureq.getUserSession().getRoles(), firstResult, maxReturns, true);
        if (firstResult == 0 && searchResults.size() == 0 && StringHelper.containsNonWhitespace(query) && !query.endsWith(FUZZY_SEARCH)) {
            // result-list was empty => first try to find word via spell-checker
            if (doSpellCheck) {
                Set<String> didYouMeansWords = searchClient.spellCheck(searchString);
                if (didYouMeansWords != null && !didYouMeansWords.isEmpty()) {
                    setDidYouMeanWords(didYouMeansWords);
                } else {
                    searchResults = doFuzzySearch(ureq, searchString, null, parentCtxt, docType, rsrcUrl, firstResult, maxReturns);
                }
            } else {
                searchResults = doFuzzySearch(ureq, searchString, null, parentCtxt, docType, rsrcUrl, firstResult, maxReturns);
            }
        }
        if (firstResult == 0 && searchResults.getList().isEmpty()) {
            showInfo("found.no.result.try.fuzzy.search");
        }
        return searchResults;
    } catch (ParseException e) {
        if (log.isDebug())
            log.debug("Query cannot be parsed: " + query);
        getWindowControl().setWarning(translate("invalid.search.query"));
    } catch (QueryException e) {
        getWindowControl().setWarning(translate("invalid.search.query.with.wildcard"));
    } catch (ServiceNotAvailableException e) {
        getWindowControl().setWarning(translate("search.service.not.available"));
    } catch (Exception e) {
        log.error("Unexpected exception while searching", e);
        getWindowControl().setWarning(translate("search.service.unexpected.error"));
    }
    return SearchResults.EMPTY_SEARCH_RESULTS;
}
Also used : ServiceNotAvailableException(org.olat.search.ServiceNotAvailableException) QueryException(org.olat.search.QueryException) ParseException(org.apache.lucene.queryparser.classic.ParseException) SearchResults(org.olat.search.SearchResults) ParseException(org.apache.lucene.queryparser.classic.ParseException) QueryException(org.olat.search.QueryException) ServiceNotAvailableException(org.olat.search.ServiceNotAvailableException)

Example 12 with ServiceNotAvailableException

use of org.olat.search.ServiceNotAvailableException in project OpenOLAT by OpenOLAT.

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);
    }
}
Also used : ServiceNotAvailableException(org.olat.search.ServiceNotAvailableException) QueryException(org.olat.search.QueryException) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JMSException(javax.jms.JMSException) ParseException(org.apache.lucene.queryparser.classic.ParseException) SearchResults(org.olat.search.SearchResults) Session(javax.jms.Session)

Example 13 with ServiceNotAvailableException

use of org.olat.search.ServiceNotAvailableException in project OpenOLAT by OpenOLAT.

the class JmsSearchProvider method onSearchMessage.

void onSearchMessage(SearchRequest searchRequest, String correlationID, Destination replyTo) {
    if (log_.isDebug()) {
        log_.debug("onSearchMessage, correlationID=" + correlationID + " , replyTo=" + replyTo + " , searchRequest=" + searchRequest);
    }
    Session session = null;
    try {
        Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(searchRequest.getIdentityId());
        SearchResults searchResults = this.doSearch(searchRequest.getQueryString(), searchRequest.getCondQueries(), identity, searchRequest.getRoles(), searchRequest.getFirstResult(), searchRequest.getMaxResults(), searchRequest.isDoHighlighting());
        if (log_.isDebug()) {
            log_.debug("searchResults: " + searchResults.size());
        }
        if (searchResults != null) {
            session = acquireSession();
            Message responseMessage = session.createObjectMessage(searchResults);
            responseMessage.setJMSCorrelationID(correlationID);
            responseMessage.setStringProperty(SearchClientProxy.JMS_RESPONSE_STATUS_PROPERTY_NAME, SearchClientProxy.JMS_RESPONSE_STATUS_OK);
            MessageProducer producer = session.createProducer(replyTo);
            if (log_.isDebug()) {
                log_.debug("onSearchMessage, send ResponseMessage=" + responseMessage + " to replyTo=" + replyTo);
            }
            producer.send(responseMessage);
            producer.close();
            return;
        } else {
            log_.info("onSearchMessage, no searchResults (searchResults=null)");
        }
    } catch (JMSException e) {
        log_.error("error when receiving jms messages", e);
        // signal search not available
        return;
    // do not throw exceptions here throw new OLATRuntimeException();
    } catch (ServiceNotAvailableException sex) {
        sendErrorResponse(SearchClientProxy.JMS_RESPONSE_STATUS_SERVICE_NOT_AVAILABLE_EXCEPTION, correlationID, replyTo);
    } catch (ParseException pex) {
        sendErrorResponse(SearchClientProxy.JMS_RESPONSE_STATUS_PARSE_EXCEPTION, correlationID, replyTo);
    } catch (QueryException qex) {
        sendErrorResponse(SearchClientProxy.JMS_RESPONSE_STATUS_QUERY_EXCEPTION, correlationID, replyTo);
    } catch (Throwable th) {
        log_.error("error at ClusteredSearchProvider.receive()", th);
        // signal search not available
        return;
    // do not throw exceptions throw new OLATRuntimeException();
    } finally {
        releaseSession(session);
        DBFactory.getInstance().commitAndCloseSession();
    }
}
Also used : ServiceNotAvailableException(org.olat.search.ServiceNotAvailableException) QueryException(org.olat.search.QueryException) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) ParseException(org.apache.lucene.queryparser.classic.ParseException) Identity(org.olat.core.id.Identity) SearchResults(org.olat.search.SearchResults) Session(javax.jms.Session)

Example 14 with ServiceNotAvailableException

use of org.olat.search.ServiceNotAvailableException in project openolat by klemens.

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;
}
Also used : ServiceNotAvailableException(org.olat.search.ServiceNotAvailableException) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) OlatDocument(org.olat.search.model.OlatDocument) QueryException(org.olat.search.QueryException) SearchService(org.olat.search.SearchService) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) ParseException(org.apache.lucene.queryparser.classic.ParseException) Document(org.apache.lucene.document.Document) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) OlatDocument(org.olat.search.model.OlatDocument) Date(java.util.Date)

Example 15 with ServiceNotAvailableException

use of org.olat.search.ServiceNotAvailableException in project openolat by klemens.

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);
    }
}
Also used : ServiceNotAvailableException(org.olat.search.ServiceNotAvailableException) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) LinkedList(java.util.LinkedList) List(java.util.List) JMSException(javax.jms.JMSException) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) HashSet(java.util.HashSet)

Aggregations

ServiceNotAvailableException (org.olat.search.ServiceNotAvailableException)16 ParseException (org.apache.lucene.queryparser.classic.ParseException)12 QueryException (org.olat.search.QueryException)8 SearchResults (org.olat.search.SearchResults)8 JMSException (javax.jms.JMSException)6 Message (javax.jms.Message)6 ObjectMessage (javax.jms.ObjectMessage)6 Session (javax.jms.Session)6 TextMessage (javax.jms.TextMessage)6 HashSet (java.util.HashSet)4 Document (org.apache.lucene.document.Document)4 BooleanQuery (org.apache.lucene.search.BooleanQuery)4 IndexSearcher (org.apache.lucene.search.IndexSearcher)4 TopDocs (org.apache.lucene.search.TopDocs)4 AbstractOlatDocument (org.olat.search.model.AbstractOlatDocument)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2