Search in sources :

Example 6 with QueryException

use of org.olat.search.QueryException 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 7 with QueryException

use of org.olat.search.QueryException 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 8 with QueryException

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

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)

Aggregations

ParseException (org.apache.lucene.queryparser.classic.ParseException)8 QueryException (org.olat.search.QueryException)8 ServiceNotAvailableException (org.olat.search.ServiceNotAvailableException)8 SearchResults (org.olat.search.SearchResults)6 JMSException (javax.jms.JMSException)4 Message (javax.jms.Message)4 ObjectMessage (javax.jms.ObjectMessage)4 Session (javax.jms.Session)4 TextMessage (javax.jms.TextMessage)4 Date (java.util.Date)2 MessageProducer (javax.jms.MessageProducer)2 Document (org.apache.lucene.document.Document)2 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)2 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)2 Identity (org.olat.core.id.Identity)2 SearchService (org.olat.search.SearchService)2 AbstractOlatDocument (org.olat.search.model.AbstractOlatDocument)2 OlatDocument (org.olat.search.model.OlatDocument)2