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