Search in sources :

Example 1 with ResultDocument

use of org.olat.search.model.ResultDocument in project OpenOLAT by OpenOLAT.

the class SearchInputController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == resultCtlr) {
        if (event instanceof SearchEvent) {
            SearchEvent goEvent = (SearchEvent) event;
            ResultDocument doc = goEvent.getDocument();
            gotoSearchResult(ureq, doc);
        } else if (event == Event.DONE_EVENT) {
            setSearchString(resultCtlr.getSearchString());
        }
    } else if (source == searchDialogBox) {
        cleanUp();
        fireEvent(ureq, Event.DONE_EVENT);
    }
}
Also used : QuickSearchEvent(org.olat.search.service.QuickSearchEvent) ResultDocument(org.olat.search.model.ResultDocument)

Example 2 with ResultDocument

use of org.olat.search.model.ResultDocument in project openolat by klemens.

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 3 with ResultDocument

use of org.olat.search.model.ResultDocument in project openolat by klemens.

the class SearchResultsImpl method createResultDocument.

/**
 * Create a result document. Return null if the identity has not enough privileges to see the document.
 * @param doc
 * @param query
 * @param analyzer
 * @param doHighlight
 * @param identity
 * @param roles
 * @return
 * @throws IOException
 */
private ResultDocument createResultDocument(Document doc, int pos, Query query, Analyzer analyzer, boolean doHighlight, Identity identity, Roles roles) throws IOException {
    boolean hasAccess = false;
    if (roles.isOLATAdmin()) {
        hasAccess = true;
    } else {
        String resourceUrl = doc.get(AbstractOlatDocument.RESOURCEURL_FIELD_NAME);
        if (resourceUrl == null) {
            resourceUrl = "";
        }
        BusinessControl businessControl = BusinessControlFactory.getInstance().createFromString(resourceUrl);
        hasAccess = mainIndexer.checkAccess(null, businessControl, identity, roles);
    }
    ResultDocument resultDoc;
    if (hasAccess) {
        resultDoc = new ResultDocument(doc, pos);
        if (doHighlight) {
            doHighlight(query, analyzer, doc, resultDoc);
        }
    } else {
        resultDoc = null;
    }
    return resultDoc;
}
Also used : BusinessControl(org.olat.core.id.context.BusinessControl) ResultDocument(org.olat.search.model.ResultDocument)

Example 4 with ResultDocument

use of org.olat.search.model.ResultDocument 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 5 with ResultDocument

use of org.olat.search.model.ResultDocument in project OpenOLAT by OpenOLAT.

the class ResultsController method nextSearchResults.

public void nextSearchResults(UserRequest ureq, SearchResults results) {
    searchResults = results;
    if (searchResults == null) {
        searchResults = SearchResults.EMPTY_SEARCH_RESULTS;
    }
    // the last result set can be empty
    if (!searchResults.getList().isEmpty()) {
        currentPage++;
        int pos = currentPage * RESULT_PER_PAGE;
        for (int i = 0; (i < RESULT_PER_PAGE) && (i < searchResults.getList().size()); i++) {
            ResultDocument document = searchResults.getList().get(i);
            if (documents.size() > pos + i) {
                documents.set(pos + i, document);
            } else {
                documents.add(document);
            }
        }
    }
    updateUI(ureq);
}
Also used : ResultDocument(org.olat.search.model.ResultDocument)

Aggregations

ResultDocument (org.olat.search.model.ResultDocument)12 ArrayList (java.util.ArrayList)4 Document (org.apache.lucene.document.Document)2 BusinessControl (org.olat.core.id.context.BusinessControl)2 AssertException (org.olat.core.logging.AssertException)2 SearchResults (org.olat.search.SearchResults)2 SearchServiceUIFactory (org.olat.search.SearchServiceUIFactory)2 AbstractOlatDocument (org.olat.search.model.AbstractOlatDocument)2 QuickSearchEvent (org.olat.search.service.QuickSearchEvent)2