Search in sources :

Example 1 with SearchResultsImpl

use of org.olat.search.service.searcher.SearchResultsImpl in project openolat by klemens.

the class SearchCallable method call.

@Override
public SearchResults call() throws ParseException {
    IndexSearcher searcher = null;
    try {
        boolean debug = log.isDebug();
        if (!searchService.existIndex()) {
            log.warn("Index does not exist, can't search for queryString: " + queryString);
            throw new ServiceNotAvailableException("Index does not exist");
        }
        if (debug)
            log.debug("queryString=" + queryString);
        searcher = searchService.getIndexSearcher();
        BooleanQuery query = searchService.createQuery(queryString, condQueries);
        if (debug)
            log.debug("query=" + query);
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        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);
        if (debug)
            log.debug("found=" + docs.totalHits);
        return searchResult;
    } catch (ParseException pex) {
        throw pex;
    } catch (Exception naex) {
        log.error("", naex);
        return null;
    } finally {
        searchService.releaseIndexSearcher(searcher);
        DBFactory.getInstance().commitAndCloseSession();
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) ServiceNotAvailableException(org.olat.search.ServiceNotAvailableException) TopDocs(org.apache.lucene.search.TopDocs) BooleanQuery(org.apache.lucene.search.BooleanQuery) SearchResultsImpl(org.olat.search.service.searcher.SearchResultsImpl) ParseException(org.apache.lucene.queryparser.classic.ParseException) ParseException(org.apache.lucene.queryparser.classic.ParseException) ServiceNotAvailableException(org.olat.search.ServiceNotAvailableException)

Example 2 with SearchResultsImpl

use of org.olat.search.service.searcher.SearchResultsImpl in project OpenOLAT by OpenOLAT.

the class SearchCallable method call.

@Override
public SearchResults call() throws ParseException {
    IndexSearcher searcher = null;
    try {
        boolean debug = log.isDebug();
        if (!searchService.existIndex()) {
            log.warn("Index does not exist, can't search for queryString: " + queryString);
            throw new ServiceNotAvailableException("Index does not exist");
        }
        if (debug)
            log.debug("queryString=" + queryString);
        searcher = searchService.getIndexSearcher();
        BooleanQuery query = searchService.createQuery(queryString, condQueries);
        if (debug)
            log.debug("query=" + query);
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        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);
        if (debug)
            log.debug("found=" + docs.totalHits);
        return searchResult;
    } catch (ParseException pex) {
        throw pex;
    } catch (Exception naex) {
        log.error("", naex);
        return null;
    } finally {
        searchService.releaseIndexSearcher(searcher);
        DBFactory.getInstance().commitAndCloseSession();
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) ServiceNotAvailableException(org.olat.search.ServiceNotAvailableException) TopDocs(org.apache.lucene.search.TopDocs) BooleanQuery(org.apache.lucene.search.BooleanQuery) SearchResultsImpl(org.olat.search.service.searcher.SearchResultsImpl) ParseException(org.apache.lucene.queryparser.classic.ParseException) ParseException(org.apache.lucene.queryparser.classic.ParseException) ServiceNotAvailableException(org.olat.search.ServiceNotAvailableException)

Aggregations

ParseException (org.apache.lucene.queryparser.classic.ParseException)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 TopDocs (org.apache.lucene.search.TopDocs)2 ServiceNotAvailableException (org.olat.search.ServiceNotAvailableException)2 SearchResultsImpl (org.olat.search.service.searcher.SearchResultsImpl)2