Search in sources :

Example 1 with IndexerPostProcessor

use of com.liferay.portal.kernel.search.IndexerPostProcessor in project liferay-ide by liferay.

the class AssetEntriesFacet method doGetFacetClause.

@Override
protected BooleanClause doGetFacetClause() {
    SearchContext searchContext = getSearchContext();
    String[] entryClassNames = searchContext.getEntryClassNames();
    BooleanQuery facetQuery = BooleanQueryFactoryUtil.create(searchContext);
    for (String entryClassName : entryClassNames) {
        Indexer indexer = IndexerRegistryUtil.getIndexer(entryClassName);
        if (indexer == null) {
            continue;
        }
        String searchEngineId = searchContext.getSearchEngineId();
        if (!searchEngineId.equals(indexer.getSearchEngineId())) {
            continue;
        }
        try {
            BooleanQuery indexerBooleanQuery = indexer.getFacetQuery(entryClassName, searchContext);
            if ((indexerBooleanQuery == null) || !indexerBooleanQuery.hasClauses()) {
                continue;
            }
            BooleanQuery entityQuery = BooleanQueryFactoryUtil.create(searchContext);
            entityQuery.add(indexerBooleanQuery, BooleanClauseOccur.MUST);
            indexer.postProcessContextQuery(entityQuery, searchContext);
            for (IndexerPostProcessor indexerPostProcessor : indexer.getIndexerPostProcessors()) {
                indexerPostProcessor.postProcessContextQuery(entityQuery, searchContext);
            }
            if (indexer.isStagingAware()) {
                if (!searchContext.isIncludeLiveGroups() && searchContext.isIncludeStagingGroups()) {
                    entityQuery.addRequiredTerm(Field.STAGING_GROUP, true);
                } else if (searchContext.isIncludeLiveGroups() && !searchContext.isIncludeStagingGroups()) {
                    entityQuery.addRequiredTerm(Field.STAGING_GROUP, false);
                }
            }
            if (entityQuery.hasClauses()) {
                facetQuery.add(entityQuery, BooleanClauseOccur.SHOULD);
            }
        } catch (Exception e) {
            _log.error(e, e);
        }
    }
    if (!facetQuery.hasClauses()) {
        return null;
    }
    return BooleanClauseFactoryUtil.create(searchContext, facetQuery, BooleanClauseOccur.MUST.getName());
}
Also used : BooleanQuery(com.liferay.portal.kernel.search.BooleanQuery) Indexer(com.liferay.portal.kernel.search.Indexer) SearchContext(com.liferay.portal.kernel.search.SearchContext) IndexerPostProcessor(com.liferay.portal.kernel.search.IndexerPostProcessor)

Aggregations

BooleanQuery (com.liferay.portal.kernel.search.BooleanQuery)1 Indexer (com.liferay.portal.kernel.search.Indexer)1 IndexerPostProcessor (com.liferay.portal.kernel.search.IndexerPostProcessor)1 SearchContext (com.liferay.portal.kernel.search.SearchContext)1