3

I'm doing a POC to send multiple Criteria through Taxonomy API to retrieve the item reference ID from the ITEM_CATEGORIES_AND_KEYWORDS table. If I've only one Criteria to send, then I am able to retrieve the item using the following Java code:

String strTaxURI = "tcm:396-65311-1024", strTaxKeywordURI = "tcm:396-223309-1024";
TaxonomyKeywordCriteria taxonomyKeywordCriteria = new 
TaxonomyKeywordCriteria(strTaxURI, strTaxKeywordURI, false);
Criteria myCriteria =null;
myCriteria = taxonomyKeywordCriteria;
myQuery.setCriteria(myCriteria);
SortParameter sortParameter = new SortParameter(SortParameter.ITEMS_TITLE, SortParameter.ASCENDING);

myQuery.addSorting(sortParameter);
myQuery.setResultFilter(new LimitFilter(20));
String[] itemURIs = myQuery.executeQuery();
String strOutput = "";
System.out.println("itemURIs.length???:::ttt"+itemURIs.length);
for (int i = 0; i < itemURIs.length; i++) {
    strOutput += itemURIs[i] + ", ";
}
%>
<body>
    <%=strOutput%>

</body>

Now if I've got multiple Keyword and Taxonomy IDs to send to the database, to retrieve the combination of items, I need to do an in clause and and clause to retrieve the items from the database.

 select * from ITEM_CATEGORIES_AND_KEYWORDS where KEYWORD_ID In( 222900,223309) and TAXONOMY_ID In(65311,65175) and PUBLICATION_ID=396;

But I'm facing a problem to create the same Criteria of In clause and And clause from Java. I've tried out a few options but I'm not able to retrieve the result of what I'm getting by executing a SQL query.

Can anyone help me with what needs to be done to do the setup for this Criteria from Java, or can someone tell me what needs to be configured, so that I can able to see the query being formed in the server console, to check how it is forming?

1

1 Answer 1

2

Usually, if you have to filter on more than one criteria, you use the AndCriteria or OrCriteria object. This allows you to combine two or more different criteria.

You can do something like this

TaxonomyKeywordCriteria taxonomyKeywordCriteria1 = new TaxonomyKeywordCriteria(strTaxURI1, strTaxKeywordURI1, false);
TaxonomyKeywordCriteria taxonomyKeywordCriteria2 = new TaxonomyKeywordCriteria(strTaxURI2, strTaxKeywordURI2, false);

AndCriteria andCriteria = new AndCriteria(taxonomyKeywordCriteria1, taxonomyKeywordCriteria2);
myQuery.setCriteria(andCriteria);

//etc...

You can also combine AndCriteria and OrCriteria objects to make complex queries.

Check the documentation for an overview of all different types of Criteria objects: http://docs.sdl.com/LiveContent/content/en-US/SDL%20Web-v1/GUID-AC27E3C1-9E21-4664-A85B-DFAB8CB63632

1
  • I think that if you use OrCriteria instead of AndCriteria, the requirement of the question is met.
    – Raimond
    Commented Jul 17, 2017 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.