当前位置: 首页>>代码示例>>Java>>正文


Java SearchContext.getFacets方法代码示例

本文整理汇总了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);
        }
    }

}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:16,代码来源:ElasticsearchIndexSearcher.java

示例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);
            } 
        }
    }
}
 
开发者ID:rivetlogic,项目名称:liferay-elasticsearch-integration,代码行数:47,代码来源:ElasticsearchHelper.java

示例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);
    }

}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:24,代码来源:ElasticsearchIndexSearcher.java


注:本文中的com.liferay.portal.kernel.search.SearchContext.getFacets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。