Fórum

How to filter the web contents based on multiple structures?

thumbnail
Abhishek Jain, modificado 6 Anos atrás.

How to filter the web contents based on multiple structures?

Regular Member Postagens: 226 Data de Entrada: 20/08/16 Postagens Recentes
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, modificado 6 Anos atrás.

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

Regular Member Postagens: 226 Data de Entrada: 20/08/16 Postagens Recentes
Can anyone tell me how to add TermsFilter to the BooleanClause?
thumbnail
Ketan Savaliya, modificado 6 Anos atrás.

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

Regular Member Postagens: 117 Data de Entrada: 03/03/11 Postagens Recentes
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, modificado 6 Anos atrás.

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

Regular Member Postagens: 226 Data de Entrada: 20/08/16 Postagens Recentes
Thanks Ketan for ur reply...but can u be more specific on how to add termsfilter to the clause/query ...
thumbnail
Ketan Savaliya, modificado 6 Anos atrás.

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

Regular Member Postagens: 117 Data de Entrada: 03/03/11 Postagens Recentes
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