Search in sources :

Example 6 with ResultDocument

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

the class ResultsController method updateUI.

private void updateUI(UserRequest ureq) {
    removeResultsController();
    int start = currentPage * RESULT_PER_PAGE;
    SearchServiceUIFactory searchUIFactory = (SearchServiceUIFactory) CoreSpringFactory.getBean(SearchServiceUIFactory.class);
    int count = 0;
    for (int i = start; (count < RESULT_PER_PAGE) && (i < documents.size()); i++) {
        ResultDocument document = documents.get(i);
        ResultController ctrl = searchUIFactory.createController(ureq, getWindowControl(), mainForm, document);
        ctrl.setHighlight(highlight);
        listenTo(ctrl);
        flc.add("result_" + (++count), ctrl.getInitialFormItem());
        resultsCtrl.add(ctrl);
    }
    flc.contextPut("numOfPages", getMaxPage() + 1);
    flc.contextPut("numOfResults", getNumOfResults());
    flc.contextPut("results", resultsCtrl);
    flc.contextPut("hasResult", searchResults != null);
    flc.contextPut("emptyResult", documents.isEmpty());
    flc.contextPut("searchResults", searchResults);
    flc.contextPut("currentPage", currentPage + 1);
    previousLink.setEnabled(currentPage != 0);
    nextLink.setEnabled(currentPage != getMaxPage());
    String[] args = { Integer.toString(getStartResult()), Integer.toString(getEndResult()), Integer.toString(getNumOfResults()) };
    flc.contextPut("resultTitle", getTranslator().translate("search.result.title", args));
}
Also used : SearchServiceUIFactory(org.olat.search.SearchServiceUIFactory) ResultDocument(org.olat.search.model.ResultDocument)

Example 7 with ResultDocument

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

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

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

the class SearchResultsImpl method initResultList.

private List<ResultDocument> initResultList(Identity identity, Roles roles, Query query, Analyzer analyzer, IndexSearcher searcher, TopDocs docs, int firstResult, int maxReturns, final boolean doHighlight, boolean onlyDbKeys) throws IOException {
    Set<String> fields = AbstractOlatDocument.getFields();
    if (onlyDbKeys) {
        fields.clear();
        fields.add(AbstractOlatDocument.DB_ID_NAME);
    } else if (!doHighlight) {
        fields.remove(AbstractOlatDocument.CONTENT_FIELD_NAME);
    }
    maxHits = SearchServiceFactory.getService().getSearchModuleConfig().getMaxHits();
    totalHits = docs.totalHits;
    totalDocs = (docs.scoreDocs == null ? 0 : docs.scoreDocs.length);
    int numOfDocs = Math.min(maxHits, docs.totalHits);
    List<ResultDocument> res = new ArrayList<ResultDocument>(maxReturns + 1);
    for (int i = firstResult; i < numOfDocs && res.size() < maxReturns; i++) {
        Document doc;
        if (doHighlight) {
            doc = searcher.doc(docs.scoreDocs[i].doc);
        } else {
            doc = searcher.doc(docs.scoreDocs[i].doc, fields);
        }
        String reservedTo = doc.get(AbstractOlatDocument.RESERVED_TO);
        if (StringHelper.containsNonWhitespace(reservedTo) && !"public".equals(reservedTo) && !reservedTo.contains(identity.getKey().toString())) {
            // admin cannot see private documents
            continue;
        }
        ResultDocument rDoc = createResultDocument(doc, i, query, analyzer, doHighlight, identity, roles);
        if (rDoc != null) {
            res.add(rDoc);
        }
        if (!roles.isOLATAdmin() && i % 10 == 0) {
            // Do commit after certain number of documents because the transaction should not be too big
            DBFactory.getInstance().commitAndCloseSession();
        }
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) ResultDocument(org.olat.search.model.ResultDocument) Document(org.apache.lucene.document.Document) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) ResultDocument(org.olat.search.model.ResultDocument)

Example 9 with ResultDocument

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

the class SearchResultsImpl method initResultList.

private List<ResultDocument> initResultList(Identity identity, Roles roles, Query query, Analyzer analyzer, IndexSearcher searcher, TopDocs docs, int firstResult, int maxReturns, final boolean doHighlight, boolean onlyDbKeys) throws IOException {
    Set<String> fields = AbstractOlatDocument.getFields();
    if (onlyDbKeys) {
        fields.clear();
        fields.add(AbstractOlatDocument.DB_ID_NAME);
    } else if (!doHighlight) {
        fields.remove(AbstractOlatDocument.CONTENT_FIELD_NAME);
    }
    maxHits = SearchServiceFactory.getService().getSearchModuleConfig().getMaxHits();
    totalHits = docs.totalHits;
    totalDocs = (docs.scoreDocs == null ? 0 : docs.scoreDocs.length);
    int numOfDocs = Math.min(maxHits, docs.totalHits);
    List<ResultDocument> res = new ArrayList<ResultDocument>(maxReturns + 1);
    for (int i = firstResult; i < numOfDocs && res.size() < maxReturns; i++) {
        Document doc;
        if (doHighlight) {
            doc = searcher.doc(docs.scoreDocs[i].doc);
        } else {
            doc = searcher.doc(docs.scoreDocs[i].doc, fields);
        }
        String reservedTo = doc.get(AbstractOlatDocument.RESERVED_TO);
        if (StringHelper.containsNonWhitespace(reservedTo) && !"public".equals(reservedTo) && !reservedTo.contains(identity.getKey().toString())) {
            // admin cannot see private documents
            continue;
        }
        ResultDocument rDoc = createResultDocument(doc, i, query, analyzer, doHighlight, identity, roles);
        if (rDoc != null) {
            res.add(rDoc);
        }
        if (!roles.isOLATAdmin() && i % 10 == 0) {
            // Do commit after certain number of documents because the transaction should not be too big
            DBFactory.getInstance().commitAndCloseSession();
        }
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) ResultDocument(org.olat.search.model.ResultDocument) Document(org.apache.lucene.document.Document) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) ResultDocument(org.olat.search.model.ResultDocument)

Example 10 with ResultDocument

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

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