Migrating discontinued searchBy* queries
As from Tridion Docs 15, the searchById, searchByField, searchByCriteria, and searchByRawQuery queries are discontinued in favor of a new search query, so you must migrate any such queries, if you have not already done so. This topic explains how.
Procedure
- Anywhere in your code where you call
searchById, migrate your code by making the following replacement:- Old code
-
searchById(identifier: "IDENTIFIER") - New code
-
search( criteria: { id: { values: ["IDENTIFIER"] } } )
where IDENTIFIER uniquely identifies the item you are searching for.
- Anywhere in your code where you call
searchByFieldto search by a metadata field, migrate your code by making the following replacement:- Old code
-
searchByField(field: "dynamic+KEY+SUBKEY", value: "VALUE") - New code
-
search( criteria:{ metadataField:{ keys: ["KEY", "SUBKEY"] value: "VALUE" } } )
where KEY and SUBKEY identify the metadata field whose value you're searching, and VALUE is the value.
Example of old query:
searchByField(field:"dynamic+nested+tcmmeta", value:"tcm")Example of new query:search( criteria:{ metadataField:{ keys: ["nested", "tcmmeta"] value: "tcm" } } )Example of old query:
searchByField(field:"dynamic+ish.meta", value:"ish")Example of new query:search( criteria:{ metadataField:{ keys: ["ish.meta"] value: "ish" } } ) - Anywhere in your code where you call
searchByFieldto search by a content field in a specific language, migrate your code by making the following replacement:- Old code
-
searchByField(field: "FIELDNAME+LANGUAGE", value: "VALUE") - New code
-
search( criteria:{ languageField:{ key: "FIELDNAME", value: "VALUE", language: "LANGUAGE" } } )
where FIELDNAME is the field whose value you're searching, LANGUAGE is the language in which you're searching, and VALUE is the value.
- Anywhere in your code where you call
searchByFieldto search by another type of field than content in a specific language, or metadata, migrate your code by making the following replacement:- Old code
-
searchByField(field: "FIELDNAME", value: "FIELDVALUE") - New code
-
search( criteria:{ field:{ key: "FIELDNAME" value: "FIELDVALUE" } } )
where FIELDNAME is the field whose value you're searching, and FIELDVALUE is the value.
- Anywhere in your code where you call
searchByCriteriato search using a complex query, migrate your code by making the following replacement:- Old code
-
searchByCriteria( criteria: { OLDCONDITION1 OPERATOR: { OLDCONDITION2 } } ) -
where OLDCONDITION1 and OLDCONDITION2 are (possibly deprecated) queries, and OPERATOR is a Boolean operator (
andoror). - New code
-
search( criteria:{ MIGRATEDCONDITION1 OPERATOR:{ MIGRATEDCONDITION2 } } ) -
where MIGRATEDCONDITION1 and MIGRATEDCONDITION2 are the same queries as in the old code, migrated if needed, and OPERATOR is the same Boolean operator as in the old code (
andoror).
- Anywhere in your code where you call
searchByRawCriteriato search by a raw query, migrate your code by making the following replacement:- Old code
-
searchByRawCriteria(rawQuery: "RAWQUERY") - New code
-
search(rawCriteria: "RAWQUERY")
where RAWQUERY is the raw query you are executing.