Forums de discussion

How to filter the web contents based on multiple structures?

thumbnail
Abhishek Jain, modifié il y a 6 années.

How to filter the web contents based on multiple structures?

Regular Member Publications: 226 Date d'inscription: 20/08/16 Publications récentes
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, modifié il y a 6 années.

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

Regular Member Publications: 226 Date d'inscription: 20/08/16 Publications récentes
Can anyone tell me how to add TermsFilter to the BooleanClause?
thumbnail
Ketan Savaliya, modifié il y a 6 années.

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

Regular Member Publications: 117 Date d'inscription: 03/03/11 Publications récentes
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, modifié il y a 6 années.

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

Regular Member Publications: 226 Date d'inscription: 20/08/16 Publications récentes
Thanks Ketan for ur reply...but can u be more specific on how to add termsfilter to the clause/query ...
thumbnail
Ketan Savaliya, modifié il y a 6 années.

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

Regular Member Publications: 117 Date d'inscription: 03/03/11 Publications récentes
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