掲示板

How to filter the web contents based on multiple structures?

thumbnail
6年前 に Abhishek Jain によって更新されました。

How to filter the web contents based on multiple structures?

Regular Member 投稿: 226 参加年月日: 16/08/20 最新の投稿
I just want to add the functionality to my custom portlet to show web contents based on multiple structures selected in liferay DXP. I have found the following code:-
searchContext.setAttribute("ddmStructureKey","61606")
This code is filtering the content based on structure Id 61606. What if I want to get the web contents based on multiple structure Ids. Do I need to create booleanclauses ? Please tell me how to achieve the same with some example.. any help would be appreciated..
thumbnail
6年前 に Abhishek Jain によって更新されました。

RE: How to filter the web contents based on multiple structures?

Regular Member 投稿: 226 参加年月日: 16/08/20 最新の投稿
Can anyone tell me how to add TermsFilter to the BooleanClause?
thumbnail
6年前 に Ketan Savaliya によって更新されました。

RE: How to filter the web contents based on multiple structures?

Regular Member 投稿: 117 参加年月日: 11/03/03 最新の投稿
Abhishek Jain:
Can anyone tell me how to add TermsFilter to the BooleanClause?


Your can try like below piece of code. here they have multiple userId, you can try with your required field instead of userId.

SearchContext context = new SearchContext();
context.setCompanyId(ColabConstants.COLAB_COMPANY_ID);
BooleanQuery query = BooleanQueryFactoryUtil.create(context);
query.addRequiredTerm(Field.ENTRY_CLASS_NAME, SocialActivity.class.getName());

BooleanQuery excludeQuery = BooleanQueryFactoryUtil.create(context);
for (Long excludedUserId : excludedUserIds) {
excludeQuery.addExactTerm("userId", excludedUserId);
}

try {
query.add(excludeQuery, BooleanClauseOccurImpl.MUST_NOT);
} catch (ParseException e) {
_log.error(e);
}

HTH!!

Regards,
Ketan Savaliya
thumbnail
6年前 に Abhishek Jain によって更新されました。

RE: How to filter the web contents based on multiple structures?

Regular Member 投稿: 226 参加年月日: 16/08/20 最新の投稿
Thanks Ketan for ur reply...but can u be more specific on how to add termsfilter to the clause/query ...
thumbnail
6年前 に Ketan Savaliya によって更新されました。

RE: How to filter the web contents based on multiple structures?

Regular Member 投稿: 117 参加年月日: 11/03/03 最新の投稿
Abhishek Jain:
Thanks Ketan for ur reply...but can u be more specific on how to add termsfilter to the clause/query ...


Hi Abhishek,

below piece of code help you to add termFilter to the query.

BooleanQuery excludeQuery = BooleanQueryFactoryUtil.create(context);
for (Long structureId : structureIds) {
excludeQuery.addExactTerm("structureId", structureId );
}

Regards,
Ketan Savaliya