Example usage for com.liferay.portal.kernel.search Field ASSET_PARENT_CATEGORY_ID

List of usage examples for com.liferay.portal.kernel.search Field ASSET_PARENT_CATEGORY_ID

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.search Field ASSET_PARENT_CATEGORY_ID.

Prototype

String ASSET_PARENT_CATEGORY_ID

To view the source code for com.liferay.portal.kernel.search Field ASSET_PARENT_CATEGORY_ID.

Click Source Link

Usage

From source file:com.liferay.asset.categories.internal.search.AssetCategoryIndexer.java

License:Open Source License

@Override
public void postProcessContextBooleanFilter(BooleanFilter contextBooleanFilter, SearchContext searchContext)
        throws Exception {

    long[] parentCategoryIds = (long[]) searchContext.getAttribute(Field.ASSET_PARENT_CATEGORY_IDS);

    if (!ArrayUtil.isEmpty(parentCategoryIds)) {
        TermsFilter parentCategoryTermsFilter = new TermsFilter(Field.ASSET_PARENT_CATEGORY_ID);

        parentCategoryTermsFilter.addValues(ArrayUtil.toStringArray(parentCategoryIds));

        contextBooleanFilter.add(parentCategoryTermsFilter, BooleanClauseOccur.MUST);
    }/*  w  w  w. j  a v  a  2s  .  c  o  m*/

    long[] vocabularyIds = (long[]) searchContext.getAttribute(Field.ASSET_VOCABULARY_IDS);

    if (!ArrayUtil.isEmpty(vocabularyIds)) {
        TermsFilter vocabularyTermsFilter = new TermsFilter(Field.ASSET_VOCABULARY_ID);

        vocabularyTermsFilter.addValues(ArrayUtil.toStringArray(vocabularyIds));

        contextBooleanFilter.add(vocabularyTermsFilter, BooleanClauseOccur.MUST);
    }
}

From source file:com.liferay.asset.categories.internal.search.AssetCategoryIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(AssetCategory assetCategory) throws Exception {

    if (_log.isDebugEnabled()) {
        _log.debug("Indexing asset category " + assetCategory);
    }/*www . j  a  va  2  s  .  co m*/

    Document document = getBaseModelDocument(CLASS_NAME, assetCategory);

    document.addKeyword(Field.ASSET_CATEGORY_ID, assetCategory.getCategoryId());

    List<AssetCategory> categories = new ArrayList<>(1);

    categories.add(assetCategory);

    addSearchAssetCategoryTitles(document, Field.ASSET_CATEGORY_TITLE, categories);

    document.addKeyword(Field.ASSET_PARENT_CATEGORY_ID, assetCategory.getParentCategoryId());
    document.addKeyword(Field.ASSET_VOCABULARY_ID, assetCategory.getVocabularyId());

    Locale siteDefaultLocale = _portal.getSiteDefaultLocale(assetCategory.getGroupId());

    addLocalizedField(document, Field.DESCRIPTION, siteDefaultLocale, assetCategory.getDescriptionMap());

    document.addText(Field.NAME, assetCategory.getName());
    addLocalizedField(document, Field.TITLE, siteDefaultLocale, assetCategory.getTitleMap());
    document.addKeyword("leftCategoryId", assetCategory.getLeftCategoryId());

    if (_log.isDebugEnabled()) {
        _log.debug("Document " + assetCategory + " indexed successfully");
    }

    return document;
}