We have a Component in which a Keyword is linked to one meta field and we were searching for the Component by its Key

 TcmUri[] retrieveComponentTcm(String code, int publicationId) throws StorageException {
    Criteria isHSchema = schemaCriteria(H_SCHEMA_ID);
    Criteria hasHKeyword = taxonomyCriteria(publicationId, H_CATEGORY_ID, PUBLICATION_TARGET, code);
    Query query = new Query(and(isHSchema, hasHKeyword));
    return executeQuery(query);
}

Now the same Category is linked also to a second field and the query is failing. For example in the following scenario:

COMPONENT 1
field 1 = X
field 2 = Y
COMPONENT 2
field 1 = Y
field 2 = X

when I search by the Key Y, I'm retrieving 2 Components, but we only want to retrieve COMPONENT2 (the Component with the field1 = Y).

Is there any solution? We only have the Key of the Keyword.

UPDATE We need to recover components based on a schema and that have linked a keyword in a specific metadata field. This category is used in two metadata fields in this component. The problem is that I want to recover only the components with this keyword linked in one specific field and I can't make a CustomMetaValueCriteria, because I don't have the value of the keyword, but the key. As we are using Web8 and this category is publishable, my question was if there's a way of doing that only knowing the key.

Your question is somewhat unclear/incomplete, for example, what do the methods schemaCriteria taxonomyCriteria do?

But to answer you question...

If multiple items have the same "properties" (whatever those properties are) and you do a Criteria Query over those exact same properties then all of those items will be returned. All of them fulfill the Criteria you have defined.

This applies to your case as well, if multiple Components are classified with the same Keyword then your Taxonomy Query will always return all of them because the same Keyword means the same Keyword Key for both of the Components. To return only one, you need to make a stricter Criteria Query which only one of them will fulfill. For example add a metadata field with some value and include a CustomMetaValueCriteria in the final Criteria.

  • Hi, We need to recover components based in a schema and that have linked a keyword in an specific metadata field. This category is used in two metadata fields in this component. The problem is that I want to recover only the components with this keyword linked in one specific field and I can't make a CustomMetaValueCriteria , because I don't have the value of the keyword, but the key. As we are using Web8 and this category is publishable, my question was if there's a way of doing that only knowing the key. Hope it's clearer now – tfinez Jul 11 at 10:58
  • Can you use the Taxonomy API too lookup the Keyword by Key and then use a CustomMetaValueCriteria? – Rick Pannekoek Jul 11 at 19:44

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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