use of com.liferay.portal.kernel.search.BooleanQuery 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());
}
use of com.liferay.portal.kernel.search.BooleanQuery in project liferay-ide by liferay.
the class SearchPermissionCheckerImpl method doGetPermissionQuery_6.
protected Query doGetPermissionQuery_6(long companyId, long[] groupIds, long userId, String className, Query query, SearchContext searchContext, AdvancedPermissionChecker advancedPermissionChecker, List<Group> groups, List<Role> roles, List<UserGroupRole> userGroupRoles, Map<Long, List<Role>> groupIdsToRoles) throws Exception {
BooleanQuery permissionQuery = BooleanQueryFactoryUtil.create(searchContext);
if (userId > 0) {
permissionQuery.addTerm(Field.USER_ID, userId);
}
BooleanQuery groupsQuery = BooleanQueryFactoryUtil.create(searchContext);
BooleanQuery rolesQuery = BooleanQueryFactoryUtil.create(searchContext);
for (Role role : roles) {
String roleName = role.getName();
if (roleName.equals(RoleConstants.ADMINISTRATOR)) {
return query;
}
if (ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, className, ResourceConstants.SCOPE_COMPANY, String.valueOf(companyId), role.getRoleId(), ActionKeys.VIEW)) {
return query;
}
if ((role.getType() == RoleConstants.TYPE_REGULAR) && ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, className, ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID), role.getRoleId(), ActionKeys.VIEW)) {
return query;
}
for (Group group : groups) {
if (ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, className, ResourceConstants.SCOPE_GROUP, String.valueOf(group.getGroupId()), role.getRoleId(), ActionKeys.VIEW)) {
groupsQuery.addTerm(Field.GROUP_ID, group.getGroupId());
}
if ((role.getType() != RoleConstants.TYPE_REGULAR) && ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, className, ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID), role.getRoleId(), ActionKeys.VIEW)) {
List<Role> groupRoles = groupIdsToRoles.get(group.getGroupId());
if (groupRoles.contains(role)) {
groupsQuery.addTerm(Field.GROUP_ID, group.getGroupId());
}
}
if (group.isSite() && !roleName.equals(RoleConstants.SITE_MEMBER) && (role.getType() == RoleConstants.TYPE_SITE)) {
rolesQuery.addTerm(Field.GROUP_ROLE_ID, group.getGroupId() + StringPool.DASH + role.getRoleId());
}
}
rolesQuery.addTerm(Field.ROLE_ID, role.getRoleId());
}
for (Group group : groups) {
addRequiredMemberRole(group, rolesQuery);
}
for (UserGroupRole userGroupRole : userGroupRoles) {
rolesQuery.addTerm(Field.GROUP_ROLE_ID, userGroupRole.getGroupId() + StringPool.DASH + userGroupRole.getRoleId());
}
if (groupsQuery.hasClauses()) {
permissionQuery.add(groupsQuery, BooleanClauseOccur.SHOULD);
}
if (rolesQuery.hasClauses()) {
permissionQuery.add(rolesQuery, BooleanClauseOccur.SHOULD);
}
BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
fullQuery.add(query, BooleanClauseOccur.MUST);
fullQuery.add(permissionQuery, BooleanClauseOccur.MUST);
return fullQuery;
}
Aggregations