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));
}
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;
}
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;
}
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;
}
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);
}
Aggregations