Package org.olat.core.commons.services.search

Examples of org.olat.core.commons.services.search.ServiceNotAvailableException


   */
  public SearchResults doSearch(String queryString, Identity identity, Roles roles, boolean doHighlighting) throws ServiceNotAvailableException, ParseException, QueryException {
    try {
      if (!existIndex()) {
        log.warn("Index does not exist, can't search for queryString: "+queryString);
        throw new ServiceNotAvailableException("Index does not exist");
      }
      synchronized (createIndexSearcherLock) {//o_clusterOK by:fj if service is only configured on one vm, which is recommended way
        if (searcher == null) {
          try {
            createIndexSearcher(indexPath);
            checkIsIndexUpToDate();
          } catch(IOException ioEx) {
            log.warn("Can not create searcher", ioEx);
            throw new ServiceNotAvailableException("Index is not available");
          }
        }
        if ( hasNewerIndexFile() ) {
          reopenIndexSearcher();
          checkIsIndexUpToDate();
        }     
      }
      log.info("queryString=" + queryString);
     
      QueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_CURRENT, fields, analyzer);
      queryParser.setLowercaseExpandedTerms(false);//some add. fields are not tokenized and not lowered case
      Query query = queryParser.parse(queryString);
      try {
        query = searcher.rewrite(query);
      } catch (Exception ex) {
        throw new QueryException("Rewrite-Exception query because too many clauses. Query=" + query);
      }
      long startTime = System.currentTimeMillis();
      int n = SearchServiceImpl.getInstance().getSearchModuleConfig().getMaxHits() + 1;
      TopDocs docs = searcher.search(query, n);
      long queryTime = System.currentTimeMillis() - startTime;
      if (log.isDebug()) log.debug("hits.length()=" + docs.totalHits);
      SearchResultsImpl searchResult = new SearchResultsImpl(searcher, docs, query, analyzer, identity, roles, doHighlighting);
      searchResult.setQueryTime(queryTime);
      searchResult.setNumberOfIndexDocuments(searcher.maxDoc());
      queryCount++;
      return searchResult;
    } catch (ServiceNotAvailableException naex) {
      // pass exception
      throw new ServiceNotAvailableException(naex.getMessage());
    } catch (ParseException pex) {
      throw new ParseException("can not parse query=" + queryString);
    } catch (QueryException qex) {
      throw new QueryException(qex.getMessage());
    } catch (Exception ex) {
      log.warn("Exception in search", ex);
      throw new ServiceNotAvailableException(ex.getMessage());
    }
   }
View Full Code Here


        } 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 {
          Tracing.logWarn("doSearch: receive unkown responseStatus=" + responseStatus, ClusteredSearchRequester.class);
          return null;
        }
      } else {
        //null returnedMessage
        throw new ServiceNotAvailableException("communication error with JMS - cannot receive messages!!!");
      }       
    } catch (JMSException e) {
      Tracing.logError("Search failure I",e,ClusteredSearchRequester.class);
      throw new ServiceNotAvailableException("communication error with JMS - cannot send messages!!!");
    } finally {
      releaseSession(session);
    }
  }
View Full Code Here

      if(returnedMessage!=null){
        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{
View Full Code Here

TOP

Related Classes of org.olat.core.commons.services.search.ServiceNotAvailableException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.