Example usage for com.liferay.portal.kernel.search.filter TermsFilter isEmpty

List of usage examples for com.liferay.portal.kernel.search.filter TermsFilter isEmpty

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.search.filter TermsFilter isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Usage

From source file:com.liferay.message.boards.internal.search.MBMessageIndexer.java

License:Open Source License

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

    addStatus(contextBooleanFilter, searchContext);

    boolean discussion = GetterUtil.getBoolean(searchContext.getAttribute("discussion"));

    contextBooleanFilter.addRequiredTerm("discussion", discussion);

    if (searchContext.isIncludeDiscussions()) {
        addRelatedClassNames(contextBooleanFilter, searchContext);
    }/* w ww  . ja  va  2 s  .  c o  m*/

    String classNameId = GetterUtil.getString(searchContext.getAttribute(Field.CLASS_NAME_ID));

    if (Validator.isNotNull(classNameId)) {
        contextBooleanFilter.addRequiredTerm(Field.CLASS_NAME_ID, classNameId);
    }

    long threadId = GetterUtil.getLong((String) searchContext.getAttribute("threadId"));

    if (threadId > 0) {
        contextBooleanFilter.addRequiredTerm("threadId", threadId);
    }

    long[] categoryIds = searchContext.getCategoryIds();

    if ((categoryIds != null) && (categoryIds.length > 0)
            && (categoryIds[0] != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)) {

        TermsFilter categoriesTermsFilter = new TermsFilter(Field.CATEGORY_ID);

        for (long categoryId : categoryIds) {
            try {
                mbCategoryService.getCategory(categoryId);
            } catch (PortalException pe) {
                if (_log.isDebugEnabled()) {
                    _log.debug("Unable to get message boards category " + categoryId, pe);
                }

                continue;
            }

            categoriesTermsFilter.addValue(String.valueOf(categoryId));
        }

        if (!categoriesTermsFilter.isEmpty()) {
            contextBooleanFilter.add(categoriesTermsFilter, BooleanClauseOccur.MUST);
        }
    }
}

From source file:com.liferay.wiki.search.WikiPageIndexer.java

License:Open Source License

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

    addStatus(contextBooleanFilter, searchContext);

    long[] nodeIds = searchContext.getNodeIds();

    if (ArrayUtil.isNotEmpty(nodeIds)) {
        TermsFilter nodesIdTermsFilter = new TermsFilter(Field.NODE_ID);

        for (long nodeId : nodeIds) {
            try {
                _wikiNodeService.getNode(nodeId);
            } catch (Exception e) {
                if (_log.isDebugEnabled()) {
                    _log.debug("Unable to get wiki node " + nodeId, e);
                }//from w w w  .j av  a  2 s  . co m

                continue;
            }

            nodesIdTermsFilter.addValue(String.valueOf(nodeId));
        }

        if (!nodesIdTermsFilter.isEmpty()) {
            contextBooleanFilter.add(nodesIdTermsFilter, BooleanClauseOccur.MUST);
        }
    }
}