Using Criteria
In this sample we are searching for Components in a given Publication. Therefore we define two search criteria:
We then perform a logical AND between these criteria and feed that into the Query.
<%
In this sample we are searching for Components in a given Publication. Therefore we define two search criteria:
- PublicationCriteria - to limit result to the given Publication ID;
- ItemTypeCriteria - to limit results to only type Component;
We then perform a logical AND between these criteria and feed that into the Query.
<%
Query query = new Query();
String items[] = query.executeQuery();
out.println("<p><b>Simple Query: </b>" + list(items) +
"</p>");
PublicationCriteria publicationCriteria = new
PublicationCriteria(83);
query.setCriteria(publicationCriteria);
items = query.executeQuery();
out.println("<p><b>Publication=83 Query: </b>" + list(items) +
"</p>");
ItemTypeCriteria itemTypeCriteria = new
ItemTypeCriteria(ItemTypes.COMPONENT);
AndCriteria andCriteria = new AndCriteria(publicationCriteria,
itemTypeCriteria);
query.setCriteria(andCriteria);
items = query.executeQuery();
out.println("<p><b>Publication=83 AND ItemType=16 Query:
</b>" + list(items) + "</p>");
%>
<%!public String list(String[]
items) {
StringBuilder sb = new StringBuilder();
for (String item : items) {
sb.append(item + " ");
}
return sb.toString();
}%>
Comments