本文整理汇总了Java中com.liferay.portal.kernel.search.SearchContext.getFacets方法的典型用法代码示例。如果您正苦于以下问题:Java SearchContext.getFacets方法的具体用法?Java SearchContext.getFacets怎么用?Java SearchContext.getFacets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.liferay.portal.kernel.search.SearchContext
的用法示例。
在下文中一共展示了SearchContext.getFacets方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addFacetCollectorsToSearch
import com.liferay.portal.kernel.search.SearchContext; //导入方法依赖的package包/类
private void addFacetCollectorsToSearch(SearchContext searchContext, SearchRequestBuilder searchRequestBuilder) {
Map<String, Facet> facets = searchContext.getFacets();
for (Facet facet : facets.values()) {
AggregationBuilder facetBuilder = null;
if (facet instanceof MultiValueFacet) {
facetBuilder = LiferayFacetParser.getFacetBuilder((MultiValueFacet) facet);
} else if (facet instanceof RangeFacet) {
facetBuilder = LiferayFacetParser.getFacetBuilder((RangeFacet) facet);
}
if (facetBuilder != null) {
searchRequestBuilder.addAggregation(facetBuilder);
}
}
}
示例2: handleFacetQueries
import com.liferay.portal.kernel.search.SearchContext; //导入方法依赖的package包/类
/**
* This method adds multiple facets to Elastic search query builder.
*
* @param searchContext the search context
* @param searchRequestBuilder the search request builder
*/
private void handleFacetQueries(SearchContext searchContext, SearchRequestBuilder searchRequestBuilder) {
Map<String, Facet> facets = searchContext.getFacets();
for (Facet facet : facets.values()) {
if (!facet.isStatic()) {
FacetConfiguration liferayFacetConfiguration = facet.getFacetConfiguration();
JSONObject liferayFacetDataJSONObject = liferayFacetConfiguration.getData();
if (facet instanceof MultiValueFacet) {
TermsFacetBuilder termsFacetBuilder = FacetBuilders.termsFacet(liferayFacetConfiguration.getFieldName());
termsFacetBuilder.field(liferayFacetConfiguration.getFieldName());
if (liferayFacetDataJSONObject.has(ElasticsearchIndexerConstants.ELASTIC_SEARCH_MAXTERMS)) {
termsFacetBuilder.size(liferayFacetDataJSONObject.getInt(ElasticsearchIndexerConstants.ELASTIC_SEARCH_MAXTERMS));
}
searchRequestBuilder.addFacet(termsFacetBuilder);
} else if (facet instanceof RangeFacet) {
RangeFacetBuilder rangeFacetBuilder = FacetBuilders.rangeFacet(liferayFacetConfiguration.getFieldName());
/**
*A typical ranges array looks like below.
*[{"range":"[20140603200000 TO 20140603220000]","label":"past-hour"},{"range":"[20140602210000 TO 20140603220000]","label":"past-24-hours"},...]
*
*/
JSONArray rangesJSONArray = liferayFacetDataJSONObject.getJSONArray(ElasticsearchIndexerConstants.ELASTIC_SEARCH_RANGES);
rangeFacetBuilder.field(ElasticsearchIndexerConstants.ELASTIC_SEARCH_INNERFIELD_MDATE);
if (rangesJSONArray != null) {
for (int i = 0; i < rangesJSONArray.length(); i++) {
JSONObject rangeJSONObject = rangesJSONArray.getJSONObject(i);
String[] fromTovalues = fetchFromToValuesInRage(rangeJSONObject);
if(fromTovalues != null){
rangeFacetBuilder.addRange(fromTovalues[0].trim(), fromTovalues[1].trim());
}
}
}
searchRequestBuilder.addFacet(rangeFacetBuilder);
}
}
}
}
示例3: updateFacetCollectors
import com.liferay.portal.kernel.search.SearchContext; //导入方法依赖的package包/类
protected void updateFacetCollectors(
SearchContext searchContext, SearchResponse searchResponse) {
Map<String, Facet> facetsMap = searchContext.getFacets();
for (Facet facet : facetsMap.values()) {
if (facet.isStatic()) {
continue;
}
Aggregations facets = searchResponse.getAggregations();
Aggregation elasticsearchFacet =
facets.get(facet.getFieldName());
FacetCollector facetCollector =
new ElasticsearchFacetFieldCollector(elasticsearchFacet);
facet.setFacetCollector(facetCollector);
}
}