6

On the Content Delivery side we appear to have two very similar criterias for pulling content based on Keywords:

  • KeywordCriteria
  • TaxonomyKeywordNameCriteria

They both take a Category and Keyword as parameters. The only difference I can see is that KeywordCriteria takes a Category name, whereas TaxonomyKeywordNameCriteria takes the Cateogory ID (taxonomyID). However, this subtle difference doesn't seem to justify having completely separate classes. So I am inclined to think that there is more to it.

Would you please help me understand what the purpose of each class is and what is the difference? In what scenarios do I use one over the other?

0

2 Answers 2

10

Functionally there are some differences:

  • KeywordCriteria allows string arrays (several keywords to be queried at once). So in one query, you can retrieve all items that are tagged with any of those keywords;

  • TaxonomyKeywordNameCriteria allows query on branches of a keyword. So in one query, you can retrieve all items that are tagged with the keyword you specified or with any child keyword of it;

Technically, some differences:

  • they query different tables in the CD DB (not sure exactly which ones, but I suspect TAXYFACETS - TaxonomyKeywordNameCriteria and ITEMS_CATEGORIES_AND_KEYWORDS - KeywordCriteria;

  • TaxonomyKeywordNameCriteria requires the taxonomy to be published. KeywordCriteria does not;

1
  • Key point is that for TaxonomyNameCriteria the Category must be published. Feb 4, 2014 at 0:06
7

From the API Documentation:

TaxonomyKeywordNameCriteriaThis is the criteria which can be used to retrieve all content related to any keyword with the given name.

KeywordCriteriaThis restricts the results of a query to all the content which is directly related to a specific keyword with the specified URI. This keyword could occur in multiple taxonomies/locations and is not context specific. For this use the TaxonomyFacetCriteria and BranchedTaxonomyFacetCriteria.

So I think you are right,one obvious difference is the ability to retrieve the category name. However I think that the biggest difference is the class they inherit from, they both inherit from a common com.tridion.broker.querying.criteria.Criteria class, but the TaxonomyKeywordNameCriteria inherits from com.tridion.broker.querying.criteria.taxonomy.AbstractTaxonomyKeywordCriteria which allows you to specify whether to allow branches or not (another slight difference).

After doing a "where used" in eclipse I couldn't find much more. I think it is an abstaction layer added to the API, so it can be extended/overwritten for future functionality.

1
  • 1
    The other difference is that apparently you can use a LIKE type query with KeywordCriteria and presumably not with the TaxonomyKeywordName class. I suspect that both are in the API for historic reasons (KeywordCriteria being present earlier than TaxonomyKeywordNameCriteria). If you look into the Broker DB table layout, you see a similar mingle of where Category / Keyword relations related to Tridion items are stored.
    – Raimond
    Oct 3, 2013 at 17:15

Your Answer

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

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