Foren

How to filter the web contents based on multiple structures?

thumbnail
Abhishek Jain, geändert vor 6 Jahren.

How to filter the web contents based on multiple structures?

Regular Member Beiträge: 226 Beitrittsdatum: 20.08.16 Neueste Beiträge
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
Abhishek Jain, geändert vor 6 Jahren.

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

Regular Member Beiträge: 226 Beitrittsdatum: 20.08.16 Neueste Beiträge
Can anyone tell me how to add TermsFilter to the BooleanClause?
thumbnail
Ketan Savaliya, geändert vor 6 Jahren.

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

Regular Member Beiträge: 117 Beitrittsdatum: 03.03.11 Neueste Beiträge
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
Abhishek Jain, geändert vor 6 Jahren.

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

Regular Member Beiträge: 226 Beitrittsdatum: 20.08.16 Neueste Beiträge
Thanks Ketan for ur reply...but can u be more specific on how to add termsfilter to the clause/query ...
thumbnail
Ketan Savaliya, geändert vor 6 Jahren.

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

Regular Member Beiträge: 117 Beitrittsdatum: 03.03.11 Neueste Beiträge
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