/** * Same as {@link #getFacetNavigationBean(String)} only now instead of a {@link String} query we * pass in a {@link HstQuery} * @see {@link #getFacetNavigationBean(String)} * */ public static HippoFacetNavigationBean getFacetNavigationBean(HstQuery query) throws HstComponentException { if(query == null) { return getFacetNavigationBean((String)null); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetNavigationBean(queryAsString); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
/** * Same as {@link #getFacetNavigationBean(HstQuery)} only now instead of having the faceted navigation * node from the {@link ResolvedSiteMapItem} we add a <code>relPath</code> where it should be found * @see {@link #getFacetNavigationBean(String)} * @param query a {@link HstQuery} object * @param relPath the relative path from site base content to the faceted navigation node, which must not start with a / and is relative to the site content base path * @return the <code>HippoFacetNavigationBean</code> accounted for this <code>query</code> and <code>relPath</code> and <code>null</code> if we could not find the HippoFacetNavigationBean when the <code>query</code> is applied * @throws HstComponentException */ public static HippoFacetNavigationBean getFacetNavigationBean(HstQuery query, String relPath) throws HstComponentException { if(query == null) { return getFacetNavigationBean((String)null); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetNavigationBean(relPath, queryAsString); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
/** * Same as {@link #getFacetNavigationBean(HstQuery)} only now instead of having the faceted navigation * node from the {@link ResolvedSiteMapItem} we add <code>absBasePath</code> and <code>relPath</code> where it should be found * @see {@link #getFacetNavigationBean(String)} * @param query a {@link HstQuery} object * @param absBasePath the absolute path (starting with /) from where to get the faceted navigation bean for <code>relPath</code> and * <code>query</code>. The <code>absBasePath</code> is NOT allowed to point to or to a descendant of a faceted navigation * node * @param relPath the relative path from absBasePath to the faceted navigation node, which must not start with a / and is relative to the site content base path * @return the <code>HippoFacetNavigationBean</code> accounted for this <code>query</code> and <code>relPath</code> and <code>null</code> if we could not find the HippoFacetNavigationBean when the <code>query</code> is applied * @throws HstComponentException */ public static HippoFacetNavigationBean getFacetNavigationBean(HstQuery query, String absBasePath, String relPath) throws HstComponentException { if(query == null) { return getFacetNavigationBean((String)null); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetNavigationBean(absBasePath, relPath, queryAsString); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
protected HippoFacetNavigationBean getFacetNavigationBean(final HstRequestContext context, String path, String query) { if (Strings.isNullOrEmpty(path)) { log.warn("Facetpath was empty {}", path); return null; } ResolvedSiteMapItem resolvedSiteMapItem = context.getResolvedSiteMapItem(); String resolvedContentPath = PathUtils.normalizePath(resolvedSiteMapItem.getRelativeContentPath()); String parsedQuery = cleanupSearchQuery(query); HippoFacetNavigationBean facNavBean; if (!StringUtils.isBlank(resolvedContentPath) && !resolvedContentPath.startsWith("/") && context.getSiteContentBaseBean().getBean(resolvedContentPath, HippoFacetNavigationBean.class) != null) { facNavBean = ContentBeanUtils.getFacetNavigationBean(resolvedContentPath, parsedQuery); } else { facNavBean = ContentBeanUtils.getFacetNavigationBean(path, parsedQuery); } return facNavBean; } }
/** * @see {@link #getFacetNavigationBean(String, String, String)} with <code>absBasePath</code> as "/"+ requestContext.getSiteContentBasePath(); */ public static HippoFacetNavigationBean getFacetNavigationBean(String relPath, String query) throws HstComponentException { final HstRequestContext requestContext = RequestContextProvider.get(); if (requestContext == null) { throw new HstComponentException("Cannot call #getFacetNavigationBean without HstRequestContext"); } if(relPath == null) { log.warn("Cannot return a content bean for relative path null for resolvedSitemapItem belonging to '{}'. Return null", requestContext.getResolvedSiteMapItem().getHstSiteMapItem().getId()); return null; } String absBasePath = "/"+ requestContext.getSiteContentBasePath(); return getFacetNavigationBean(absBasePath, relPath, query); }
/** * @see {@link #getFacetNavigationBean(String, String, String)} with <code>absBasePath</code> as "/"+ requestContext.getSiteContentBasePath() and * <code>relPath </code> as requestContext.getResolvedSiteMapItem().getRelativeContentPath() */ public static HippoFacetNavigationBean getFacetNavigationBean(String query) throws HstComponentException { final HstRequestContext requestContext = RequestContextProvider.get(); if (requestContext == null) { throw new HstComponentException("Cannot call #getFacetNavigationBean without HstRequestContext"); } ResolvedSiteMapItem resolvedSiteMapItem = requestContext.getResolvedSiteMapItem(); String relPath = PathUtils.normalizePath(resolvedSiteMapItem.getRelativeContentPath()); return getFacetNavigationBean(relPath, query); }
/** * Execute the search given a facet navigation scope. * * @param request current HST request * @param paramInfo component parameters * @param scope bean representing search scope * @param <T> type of component info interface * @return pageable search results, or null if search failed. */ protected <T extends EssentialsListComponentInfo> Pageable<HippoBean> doFacetedSearch(final HstRequest request, final T paramInfo, final HippoBean scope) { Pageable<HippoBean> pageable = DefaultPagination.emptyCollection(); final String relPath = SiteUtils.relativePathFrom(scope, request.getRequestContext()); final HippoFacetNavigationBean facetBean = ContentBeanUtils.getFacetNavigationBean(relPath, getSearchQuery(request)); if (facetBean != null) { final HippoResultSetBean resultSet = facetBean.getResultSet(); if (resultSet != null) { final HippoDocumentIterator<HippoBean> iterator = resultSet.getDocumentIterator(HippoBean.class); pageable = getPageableFactory().createPageable(iterator, resultSet.getCount().intValue(), paramInfo.getPageSize(), getCurrentPage(request)); } } return pageable; }