Search in sources :

Example 6 with SearchResults

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

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 7 with SearchResults

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

the class EPFrontendManager method fulltextSearchAfterArtefacts.

private List<Long> fulltextSearchAfterArtefacts(EPFilterSettings filterSettings, Identity identity, Roles roles) {
    String query = filterSettings.getTextFilter();
    if (StringHelper.containsNonWhitespace(query)) {
        try {
            List<String> queries = new ArrayList<String>();
            appendAnd(queries, AbstractOlatDocument.RESERVED_TO, ":\"", identity.getKey().toString(), "\"");
            appendAnd(queries, "(", AbstractOlatDocument.DOCUMENTTYPE_FIELD_NAME, ":(", PortfolioArtefactIndexer.TYPE, "*))");
            SearchResults searchResults = searchClient.doSearch(query, queries, identity, roles, 0, 1000, false);
            List<Long> keys = new ArrayList<Long>();
            if (searchResults != null) {
                String marker = AbstractArtefact.class.getSimpleName();
                for (ResultDocument doc : searchResults.getList()) {
                    String businessPath = doc.getResourceUrl();
                    int start = businessPath.indexOf(marker);
                    if (start > 0) {
                        start += marker.length() + 1;
                        int stop = businessPath.indexOf(']', start);
                        if (stop < businessPath.length()) {
                            String keyStr = businessPath.substring(start, stop);
                            try {
                                keys.add(Long.parseLong(keyStr));
                            } catch (Exception e) {
                                log.error("Not a primary key: " + keyStr, e);
                            }
                        }
                    }
                }
            }
            return keys;
        } catch (Exception e) {
            log.error("", e);
            return Collections.emptyList();
        }
    } else
        return Collections.emptyList();
}
Also used : ArrayList(java.util.ArrayList) SearchResults(org.olat.search.SearchResults) ResultDocument(org.olat.search.model.ResultDocument) AssertException(org.olat.core.logging.AssertException)

Example 8 with SearchResults

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

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

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

the class ResultsSearchController method doSearch.

private void doSearch(UserRequest ureq, int firstResult) {
    SearchResults results;
    if (extendedSearch) {
        String query = advancedSearchController.getSearchString();
        List<String> condQueries = advancedSearchController.getQueryStrings();
        String key = advancedSearchController.getContext();
        if (advancedSearchController.isDocumentTypesSelected()) {
            // if document types are selected, these queries overwrite the conditional query for document type
            // set in this controller
            results = doSearch(ureq, query, condQueries, getParentContext(), null, key, firstResult, RESULT_PER_PAGE, true);
        } else {
            results = doSearch(ureq, query, condQueries, getParentContext(), getDocumentType(), key, firstResult, RESULT_PER_PAGE, true);
        }
    } else {
        String searchString = getSearchString();
        if (StringHelper.containsNonWhitespace(searchString)) {
            String key = null;
            if (contextSelection.isOneSelected()) {
                key = contextSelection.getSelectedKey();
            }
            results = doSearch(ureq, searchString, null, getParentContext(), getDocumentType(), key, firstResult, RESULT_PER_PAGE, true);
        } else {
            results = SearchResults.EMPTY_SEARCH_RESULTS;
        }
    }
    if (firstResult == 0) {
        resultCtlr.setSearchResults(ureq, results);
    } else {
        resultCtlr.nextSearchResults(ureq, results);
    }
    persistSearch();
}
Also used : SearchResults(org.olat.search.SearchResults)

Aggregations

SearchResults (org.olat.search.SearchResults)12 ParseException (org.apache.lucene.queryparser.classic.ParseException)8 ServiceNotAvailableException (org.olat.search.ServiceNotAvailableException)8 QueryException (org.olat.search.QueryException)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 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 MessageProducer (javax.jms.MessageProducer)2 Identity (org.olat.core.id.Identity)2 AssertException (org.olat.core.logging.AssertException)2 ResultDocument (org.olat.search.model.ResultDocument)2