use of org.hippoecm.hst.content.beans.query.builder.Constraint in project hippo by NHS-digital-website.
the class CiBreadcrumbProvider method loadCiLandingBean.
/**
* <p>
* Query the repository to see if this document sits under one of the Clinical Indicator
* folders, and if so load in the CiLanding bean (which is used to create the breadcrumb).
* The CiLanding document has a property called urlNameOfContentFolder which links
* the CiLanding page to the appropriate content folder
* </p>
*/
private void loadCiLandingBean() {
HstQueryBuilder queryBuilder = HstQueryBuilder.create(RequestContextProvider.get().getSiteContentBaseBean());
final HstQueryResult hstQueryResult;
Constraint[] constraints = Arrays.stream(currentDocumentBean.getPath().split("/")).map((pathSegment) -> constraint("publicationsystem:urlNameOfContentFolder").equalTo(pathSegment)).toArray(Constraint[]::new);
final HstQuery query = queryBuilder.ofTypes(CiLanding.class).where(or(constraints)).build();
try {
hstQueryResult = query.execute();
} catch (QueryException queryException) {
throw new HstComponentException("Exception occurred during ci folder search.", queryException);
}
if (hstQueryResult.getHippoBeans().hasNext()) {
isClinicalIndicator = true;
ciLandingBean = (CiLanding) hstQueryResult.getHippoBeans().nextHippoBean();
}
}
use of org.hippoecm.hst.content.beans.query.builder.Constraint in project hippo by NHS-digital-website.
the class BloomreachSearchProvider method getQuery.
private HstQuery getQuery(String queryString, SearchArea searchArea) {
HstQueryBuilder queryBuilder = HstQueryBuilder.create(RequestContextProvider.get().getSiteContentBaseBean());
queryBuilder.ofTypes(DOCUMENT_TYPES_BY_SEARCH_AREA.getOrDefault(searchArea, DOCUMENT_TYPES_BY_SEARCH_AREA.get(SearchArea.ALL)));
List<Constraint> constraintList = new ArrayList<>();
constraintList.add(or(constraint("common:searchable").equalTo(true), constraint("common:searchable").notExists()));
if (SearchArea.ALL.equals(searchArea) || SearchArea.NEWS.equals(searchArea)) {
constraintList.add(or(constraint("intranet:typeofnews").notExists(), constraint("intranet:typeofnews").equalTo("permanent"), constraint("intranet:expirydate").greaterOrEqualThan(Calendar.getInstance(), Resolution.HOUR)));
}
final Optional<String> optionalSearchQuery = Optional.ofNullable(queryString);
optionalSearchQuery.ifPresent(searchQuery -> {
String queryIncWildcards = ComponentUtils.parseAndApplyWildcards(searchQuery);
Constraint searchStringConstraint = or(constraint(".").contains(searchQuery), constraint(".").contains(queryIncWildcards));
constraintList.add(searchStringConstraint);
});
return queryBuilder.where(and(constraintList.toArray(new Constraint[0]))).build();
}
use of org.hippoecm.hst.content.beans.query.builder.Constraint in project hippo by NHS-digital-website.
the class SearchComponent method buildQuery.
private HstQuery buildQuery(HstRequest request) {
String queryParameter = getQueryParameter(request);
Constraint searchStringConstraint = null;
HstQueryBuilder queryBuilder = HstQueryBuilder.create(deriveScope(request));
if (queryParameter != null) {
String query = SearchInputParsingUtils.parse(queryParameter, true);
String queryIncWildcards = ComponentUtils.parseAndApplyWildcards(queryParameter);
searchStringConstraint = or(// forcing specific fields first: this will boost the weight of a hit fot those specific property
constraint(".").contains(query), constraint(".").contains(queryIncWildcards), constraint("website:title").contains(query), constraint("website:summary").contains(query), constraint("publicationsystem:title").contains(query), constraint("publicationsystem:summary").contains(query), constraint("nationalindicatorlibrary:title").contains(query));
}
// register content classes
deriveTypes(queryBuilder, request);
String sortParam = getSortOption(request);
switch(sortParam) {
case SORT_DATE_KEY:
queryBuilder.orderByDescending(PROPERTY_ORDERED_SEARCH_DATE, "nationalindicatorlibrary:assuranceDate", PROPERTY_SEARCH_RANK, HippoStdPubWfNodeType.HIPPOSTDPUBWF_LAST_MODIFIED_DATE);
break;
case SORT_RELEVANCE:
// This is what we want for data and info - when we have tabs this will need to be made specific
queryBuilder.orderByDescending(PROPERTY_SEARCH_RANK, "jcr:score", PROPERTY_ORDERED_SEARCH_DATE, "nationalindicatorlibrary:assuranceDate", HippoStdPubWfNodeType.HIPPOSTDPUBWF_LAST_MODIFIED_DATE);
break;
default:
LOGGER.error("Unknown sort mode: " + sortParam);
break;
}
return constructQuery(queryBuilder, searchStringConstraint);
}
use of org.hippoecm.hst.content.beans.query.builder.Constraint in project hippo by NHS-digital-website.
the class FeedHubComponent method getFeed.
private <T extends HippoBean> List<T> getFeed(HstRequest request) throws QueryException {
final HstRequestContext context = request.getRequestContext();
FeedHub feedHub = (FeedHub) context.getContentBean();
HippoBean folder = feedHub.getParentBean();
ArrayList<Constraint> constraints = new ArrayList<>();
if ("Site-wide documents".equalsIgnoreCase(feedHub.getHubType())) {
folder = RequestContextProvider.get().getSiteContentBaseBean();
if (feedHub.getFeedType().equals("Cyber Alerts")) {
constraints.add(constraint("website:publicallyaccessible").equalTo(true));
} else if (!feedHub.getFeedType().equals("Supplementary information")) {
constraints.add(constraint("website:display").equalTo(true));
}
}
String dateField = "website:publisheddatetime";
Class feedClass = null;
switch(feedHub.getFeedType()) {
case "News":
feedClass = News.class;
if (filterValues.get("year").length > 0) {
Calendar newsDateFilter = Calendar.getInstance();
newsDateFilter.set(Calendar.YEAR, Integer.parseInt(filterValues.get("year")[0]));
newsDateFilter.set(Calendar.DAY_OF_YEAR, 1);
constraints.add(constraint(dateField).equalTo(newsDateFilter, DateTools.Resolution.YEAR));
}
break;
case "Events":
feedClass = Event.class;
dateField = "website:events/@website:startdatetime";
if (filterValues.get("year").length > 0) {
Calendar eventsDateFilter = Calendar.getInstance();
eventsDateFilter.set(Calendar.YEAR, Integer.parseInt(filterValues.get("year")[0]));
eventsDateFilter.set(Calendar.DAY_OF_YEAR, 1);
constraints.add(constraint("website:events/website:startdatetime").equalTo(eventsDateFilter, DateTools.Resolution.YEAR));
if (filterValues.get("month").length > 0) {
Integer month = getMonth(filterValues.get("month")[0]);
if (month != null) {
eventsDateFilter.set(Calendar.MONTH, month);
eventsDateFilter.set(Calendar.DAY_OF_MONTH, 1);
constraints.add(constraint("website:events/website:startdatetime").equalTo(eventsDateFilter, DateTools.Resolution.MONTH));
}
}
}
if (filterValues.get("type[]").length > 0) {
String[] types = filterValues.get("type[]");
for (String type : types) {
constraints.add(constraint("website:type").equalTo(type));
}
}
break;
case "Cyber Alerts":
feedClass = CyberAlert.class;
dateField = "publicationsystem:NominalDate";
if (filterValues.get("year").length > 0) {
Calendar cyberAlertsDateFilter = Calendar.getInstance();
cyberAlertsDateFilter.set(Calendar.YEAR, Integer.parseInt(filterValues.get("year")[0]));
cyberAlertsDateFilter.set(Calendar.DAY_OF_YEAR, 1);
constraints.add(constraint(dateField).equalTo(cyberAlertsDateFilter, DateTools.Resolution.YEAR));
}
if (filterValues.get("type[]").length > 0) {
String[] types = filterValues.get("type[]");
for (String type : types) {
constraints.add(constraint("website:threattype").equalTo(type));
}
}
if (filterValues.get("severity").length > 0) {
constraints.add(constraint("website:severity").equalTo(filterValues.get("severity")[0]));
}
break;
case "Supplementary information":
feedClass = SupplementaryInformation.class;
dateField = "publicationsystem:NominalDate";
if (filterValues.get("year").length > 0) {
Calendar supplimentaryInfoDateFilter = Calendar.getInstance();
String year = filterValues.get("year")[0];
if (year.equals("Unknown")) {
constraints.add(constraint(dateField).notExists());
} else {
supplimentaryInfoDateFilter.set(Calendar.YEAR, Integer.parseInt(year));
supplimentaryInfoDateFilter.set(Calendar.DAY_OF_YEAR, 1);
DateTools.Resolution dateResolution = DateTools.Resolution.YEAR;
if (filterValues.get("month").length > 0) {
Integer month = getMonth(filterValues.get("month")[0]);
if (month != null) {
supplimentaryInfoDateFilter.set(Calendar.MONTH, month);
supplimentaryInfoDateFilter.set(Calendar.DAY_OF_MONTH, 1);
dateResolution = DateTools.Resolution.MONTH;
}
}
constraints.add(constraint(dateField).equalTo(supplimentaryInfoDateFilter, dateResolution));
}
}
break;
default:
}
if (queryText != null && !queryText.isEmpty()) {
constraints.add(or(constraint("website:title").contains(queryText), constraint("website:shortsummary").contains(queryText)));
}
HstQueryBuilder query = HstQueryBuilder.create(folder);
query.where(and(constraints.toArray(new Constraint[0]))).ofTypes(feedClass);
if (sort.equals("date-asc")) {
query.orderByAscending(dateField);
} else {
query.orderByDescending(dateField);
}
HippoBeanIterator beanIterator = query.build().execute().getHippoBeans();
return toList(beanIterator);
}
Aggregations