3

I'm using TaxonomyKeywordKeyCriteria to find Components that have a related Keyword. I only have the Keyword key and not the TCM URI.

My code:

Criteria criteria = new TaxonomyKeywordKeyCriteria(taxonomyURI, keyword, true);
Query myQuery = new Query();

PublicationCriteria publicationCriteria = new PublicationCriteria(pubId);
criteria = new AndCriteria(publicationCriteria, criteria);

myQuery.setCriteria(criteria);

String[] itemURIs = null;
itemURIs = myQuery.executeQuery();

This code generate the next query:

12:16:34,715 DEBUG [org.hibernate.hql.internal.ast.QueryTranslatorImpl] (http-/127.0.0.1:8080-3) SQL: select distinct itemmeta0_.PUBLICATION_ID as col_0_0_, itemmeta0_.ITEM_REFERENCE_ID as col_1_0_, itemmeta0_.ITEM_TYPE as col_2_0_, itemmeta0_.ITEM_REFERENCE_ID as col_3_0_ from ITEMS itemmeta0_, TAXFACETS taxonomyit1_, TAXFACETS taxonomyit2_, ITEM_CATEGORIES_AND_KEYWORDS relatedkey3_ where itemmeta0_.PUBLICATION_ID=? and taxonomyit1_.PUBLICATION_ID=itemmeta0_.PUBLICATION_ID and taxonomyit2_.TAXONOMY_ID=taxonomyit1_.TAXONOMY_ID and taxonomyit2_.PUBLICATION_ID=taxonomyit1_.PUBLICATION_ID and itemmeta0_.ITEM_REFERENCE_ID=relatedkey3_.ITEM_REFERENCE_ID and relatedkey3_.KEYWORD_ID=taxonomyit2_.FACET_ID and taxonomyit1_.FACET_KEY=? and taxonomyit1_.TAXONOMY_ID=? and taxonomyit1_.PUBLICATION_ID=? and taxonomyit2_.FACET_LEFT>=taxonomyit1_.FACET_LEFT and taxonomyit2_.FACET_RIGHT<=taxonomyit1_.FACET_RIGHT order by itemmeta0_.ITEM_REFERENCE_ID ASC

Then, I published:

  • Publication 1, Component A without related Keyword.
  • Publication 2, Component A with related Keyword X.

If I try to find Components that have related the Keyword X in Publication 1 is finding the Component A, although it doesn't have the Keyword related in this Publication.

Executing the query directly to the database I found that the problem is when is trying to query ITEM_CATEGORIES_AND_KEYWORDS relatedkey3_. It isn't using Publication ID.

Could I modify my code to force the use of Publication ID in this case?

  • 2
    It looks like you're overriding the variable criteria which starts out as a TaxonomyKeywordCriteria and becomes AndCriteria. Theoretically that should be fine, but try using another variable for it and see if there is a difference. – Nickoli Roussakov Jun 8 '17 at 11:47
  • I checked it without overriding the variable at I have the same results. Thanks. – Guskermitt Jun 9 '17 at 9:13
  • 1
    Have you published/republished the taxonomy (Category)? – Nickoli Roussakov Jun 9 '17 at 13:02
  • Yes, I checked the database and all is published correctly. The problem is in the query that generates the api. ITEM_CATEGORIES_AND_KEYWORDS isn't limited by pubId and is mixing data from different publications. – Guskermitt Jun 12 '17 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.