Skip to content

Instantly share code, notes, and snippets.

@topolik
Created July 19, 2012 21:51
Show Gist options
  • Save topolik/3147100 to your computer and use it in GitHub Desktop.
Save topolik/3147100 to your computer and use it in GitHub Desktop.
Filtering faceted search
<%@ page import="com.liferay.portal.kernel.search.*" %>
<%
// should add something like: (+(entryClassName:com.liferay.portlet.documentlibrary.model.DLFileEntry) -(extension:png))
BooleanQuery q1 = BooleanQueryFactoryUtil.create(searchContext);
BooleanQuery subQ = BooleanQueryFactoryUtil.create(searchContext);
subQ.addTerm("entryClassName", "com.liferay.portlet.documentlibrary.model.DLFileEntry");
q1.add(subQ, BooleanClauseOccur.MUST);
BooleanQuery subQ2 = BooleanQueryFactoryUtil.create(searchContext);
subQ2.addTerm("extension", "png");
q1.add(subQ2, BooleanClauseOccur.MUST_NOT);
BooleanClause bClause = BooleanClauseFactoryUtil.create(searchContext, q1, BooleanClauseOccur.MUST.getName());
searchContext.setBooleanClauses(new BooleanClause[]{bClause});
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment