Example usage for com.liferay.portal.kernel.search BooleanClauseOccur MUST

List of usage examples for com.liferay.portal.kernel.search BooleanClauseOccur MUST

Introduction

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

Prototype

BooleanClauseOccur MUST

To view the source code for com.liferay.portal.kernel.search BooleanClauseOccur MUST.

Click Source Link

Usage

From source file:com.liferay.portlet.documentlibrary.util.DLFileEntryIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    addStatus(contextQuery, searchContext);

    if (searchContext.isIncludeAttachments()) {
        addRelatedClassNames(contextQuery, searchContext);
    }/*  w w w .j  a v  a 2  s . c  o m*/

    contextQuery.addRequiredTerm(Field.HIDDEN, searchContext.isIncludeAttachments());

    addSearchClassTypeIds(contextQuery, searchContext);

    String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

        String[] ddmStructureFieldNameParts = StringUtil.split(ddmStructureFieldName, StringPool.SLASH);

        DDMStructure structure = DDMStructureLocalServiceUtil
                .getStructure(GetterUtil.getLong(ddmStructureFieldNameParts[1]));

        String fieldName = StringUtil.replaceLast(ddmStructureFieldNameParts[2],
                StringPool.UNDERLINE.concat(LocaleUtil.toLanguageId(searchContext.getLocale())),
                StringPool.BLANK);

        try {
            ddmStructureFieldValue = DDMUtil.getIndexedFieldValue(ddmStructureFieldValue,
                    structure.getFieldType(fieldName));
        } catch (StructureFieldException sfe) {
        }

        contextQuery.addRequiredTerm(ddmStructureFieldName,
                StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE);
    }

    String[] mimeTypes = (String[]) searchContext.getAttribute("mimeTypes");

    if (ArrayUtil.isNotEmpty(mimeTypes)) {
        BooleanQuery mimeTypesQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (String mimeType : mimeTypes) {
            mimeTypesQuery.addTerm("mimeType",
                    StringUtil.replace(mimeType, CharPool.FORWARD_SLASH, CharPool.UNDERLINE));
        }

        contextQuery.add(mimeTypesQuery, BooleanClauseOccur.MUST);
    }
}

From source file:com.liferay.portlet.documentlibrary.util.DLIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS),
            WorkflowConstants.STATUS_APPROVED);

    if (status != WorkflowConstants.STATUS_ANY) {
        contextQuery.addRequiredTerm(Field.STATUS, status);
    }/*from ww w  .  ja  v  a 2 s. co m*/

    long[] folderIds = searchContext.getFolderIds();

    if ((folderIds != null) && (folderIds.length > 0)) {
        if (folderIds[0] == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
            return;
        }

        BooleanQuery folderIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (long folderId : folderIds) {
            try {
                DLFolderServiceUtil.getFolder(folderId);
            } catch (Exception e) {
                continue;
            }

            folderIdsQuery.addTerm(Field.FOLDER_ID, folderId);
        }

        contextQuery.add(folderIdsQuery, BooleanClauseOccur.MUST);
    }
}

From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java

License:Open Source License

@Override
protected void addSearchLocalizedTerm(BooleanQuery searchQuery, SearchContext searchContext, String field,
        boolean like) throws Exception {

    if (Validator.isNull(field)) {
        return;//from w w  w  .  j a  va 2 s .c om
    }

    String value = String.valueOf(searchContext.getAttribute(field));

    if (Validator.isNull(value)) {
        value = searchContext.getKeywords();
    }

    if (Validator.isNull(value)) {
        return;
    }

    String localizedField = DocumentImpl.getLocalizedName(searchContext.getLocale(), field);

    if (Validator.isNull(searchContext.getKeywords())) {
        BooleanQuery localizedQuery = BooleanQueryFactoryUtil.create(searchContext);

        localizedQuery.addTerm(field, value, like);
        localizedQuery.addTerm(localizedField, value, like);

        BooleanClauseOccur booleanClauseOccur = BooleanClauseOccur.SHOULD;

        if (searchContext.isAndSearch()) {
            booleanClauseOccur = BooleanClauseOccur.MUST;
        }

        searchQuery.add(localizedQuery, booleanClauseOccur);
    } else {
        searchQuery.addTerm(localizedField, value, like);
    }
}

From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java

License:Open Source License

@Override
protected void addStatus(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    boolean includeScheduledArticles = false;

    if (params != null) {
        includeScheduledArticles = GetterUtil.getBoolean(params.get("includeScheduledArticles"));
    }//  ww  w.  j  a  va  2s.co m

    if (includeScheduledArticles) {
        BooleanQuery statusQuery = BooleanQueryFactoryUtil.create(searchContext);

        BooleanQuery statusHeadQuery = BooleanQueryFactoryUtil.create(searchContext);

        statusHeadQuery.addRequiredTerm("head", Boolean.TRUE);
        statusHeadQuery.addRequiredTerm(Field.STATUS, WorkflowConstants.STATUS_APPROVED);

        statusQuery.add(statusHeadQuery, BooleanClauseOccur.SHOULD);

        BooleanQuery statusScheduledHeadQuery = BooleanQueryFactoryUtil.create(searchContext);

        statusScheduledHeadQuery.addRequiredTerm("scheduledHead", Boolean.TRUE);
        statusScheduledHeadQuery.addRequiredTerm(Field.STATUS, WorkflowConstants.STATUS_SCHEDULED);

        statusQuery.add(statusScheduledHeadQuery, BooleanClauseOccur.SHOULD);

        contextQuery.add(statusQuery, BooleanClauseOccur.MUST);
    } else {
        super.addStatus(contextQuery, searchContext);

        boolean head = GetterUtil.getBoolean(searchContext.getAttribute("head"), Boolean.TRUE);
        boolean relatedClassName = GetterUtil.getBoolean(searchContext.getAttribute("relatedClassName"));

        if (head && !relatedClassName) {
            contextQuery.addRequiredTerm("head", Boolean.TRUE);
        }
    }
}

From source file:com.liferay.portlet.messageboards.util.MBIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_ANY);

    if (status != WorkflowConstants.STATUS_ANY) {
        contextQuery.addRequiredTerm(Field.STATUS, status);
    }//from  w  w w. j  a  v  a  2 s . com

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

    contextQuery.addRequiredTerm("discussion", discussion);

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

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

    long[] categoryIds = searchContext.getCategoryIds();

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

            return;
        }

        BooleanQuery categoriesQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (long categoryId : categoryIds) {
            try {
                MBCategoryServiceUtil.getCategory(categoryId);
            } catch (Exception e) {
                continue;
            }

            categoriesQuery.addTerm(Field.CATEGORY_ID, categoryId);
        }

        contextQuery.add(categoriesQuery, BooleanClauseOccur.MUST);
    }
}

From source file:com.liferay.portlet.softwarecatalog.util.SCIndexer.java

License:Open Source License

@Override
protected void postProcessFullQuery(BooleanQuery fullQuery, SearchContext searchContext) throws Exception {

    String type = (String) searchContext.getAttribute("type");

    if (Validator.isNotNull(type)) {
        BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);

        searchQuery.addRequiredTerm("type", type);

        fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
    }/*  www  .  j av  a2s  .  c  o m*/
}

From source file:com.liferay.portlet.tags.service.impl.TagsAssetLocalServiceImpl.java

License:Open Source License

public Hits search(long companyId, String portletId, String keywords, int start, int end)
        throws SystemException {

    try {//from   w  ww.j a va  2  s. c  o m
        BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();

        if (Validator.isNotNull(portletId)) {
            contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId);
        } else {
            BooleanQuery portletIdsQuery = BooleanQueryFactoryUtil.create();

            for (String assetTypePortletId : TagsUtil.ASSET_TYPE_PORTLET_IDS) {

                TermQuery termQuery = TermQueryFactoryUtil.create(Field.PORTLET_ID, assetTypePortletId);

                portletIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD);
            }

            contextQuery.add(portletIdsQuery, BooleanClauseOccur.MUST);
        }

        BooleanQuery searchQuery = BooleanQueryFactoryUtil.create();

        if (Validator.isNotNull(keywords)) {
            searchQuery.addTerm(Field.TITLE, keywords);
            searchQuery.addTerm(Field.CONTENT, keywords);
            searchQuery.addTerm(Field.DESCRIPTION, keywords);
            searchQuery.addTerm(Field.PROPERTIES, keywords);
            searchQuery.addTerm(Field.TAGS_ENTRIES, keywords);
        }

        BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();

        fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

        if (searchQuery.clauses().size() > 0) {
            fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
        }

        return SearchEngineUtil.search(companyId, fullQuery, start, end);
    } catch (Exception e) {
        throw new SystemException(e);
    }
}

From source file:com.liferay.portlet.usersadmin.util.OrganizationIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    if (params == null) {
        return;/*from  w  ww. ja  v  a2s.  c o m*/
    }

    List<Organization> organizationsTree = (List<Organization>) params.get("organizationsTree");

    if ((organizationsTree != null) && !organizationsTree.isEmpty()) {
        BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (Organization organization : organizationsTree) {
            String treePath = organization.buildTreePath();

            booleanQuery.addTerm("treePath", treePath, true);
        }

        contextQuery.add(booleanQuery, BooleanClauseOccur.MUST);
    }
}

From source file:com.liferay.portlet.usersadmin.util.UserIndexer.java

License:Open Source License

protected void addContextQueryParams(BooleanQuery contextQuery, SearchContext searchContext, String key,
        Object value) throws Exception {

    if (key.equals("usersOrgs")) {
        if (value instanceof Long[]) {
            Long[] values = (Long[]) value;

            BooleanQuery usersOrgsQuery = BooleanQueryFactoryUtil.create(searchContext);

            for (long organizationId : values) {
                usersOrgsQuery.addTerm("organizationIds", organizationId);
                usersOrgsQuery.addTerm("ancestorOrganizationIds", organizationId);
            }//from w  w w.j a  v  a 2 s.  c o m

            contextQuery.add(usersOrgsQuery, BooleanClauseOccur.MUST);
        } else {
            contextQuery.addRequiredTerm("organizationIds", String.valueOf(value));
        }
    } else if (key.equals("usersOrgsCount")) {
        contextQuery.addRequiredTerm("organizationCount", String.valueOf(value));
    } else if (key.equals("usersRoles")) {
        contextQuery.addRequiredTerm("roleIds", String.valueOf(value));
    } else if (key.equals("usersTeams")) {
        contextQuery.addRequiredTerm("teamIds", String.valueOf(value));
    } else if (key.equals("usersUserGroups")) {
        contextQuery.addRequiredTerm("userGroupIds", String.valueOf(value));
    }
}

From source file:com.liferay.portlet.wiki.util.WikiIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_ANY);

    if (status != WorkflowConstants.STATUS_ANY) {
        contextQuery.addRequiredTerm(Field.STATUS, status);
    }/*w w  w .j av a  2  s .c o m*/

    long[] nodeIds = searchContext.getNodeIds();

    if ((nodeIds != null) && (nodeIds.length > 0)) {
        BooleanQuery nodeIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (long nodeId : nodeIds) {
            try {
                WikiNodeServiceUtil.getNode(nodeId);
            } catch (Exception e) {
                continue;
            }

            nodeIdsQuery.addTerm(Field.NODE_ID, nodeId);
        }

        contextQuery.add(nodeIdsQuery, BooleanClauseOccur.MUST);
    }
}