GraphQL requests executing simple searches
Several samples illustrate how a simple search string entered by your visitor can be put in a GraphQL request.
The following simple search looks for the search string "interest rate" in any English-language content of any objects:
{
searchByField(field: "content+english", value: "interest rate", strict: false) {
edges {
node {
searchResult {
id
itemType
fields
mainContentField
rawLanguageTitle
}
}
}
}
}
The following search uses an OR operator to combine the previous search with a search for the search string in the English raw language title:
searchByCriteria(criteria: {field: "content+english", value: "interest rate", strict: false, or: {field: "rawLanguageTitle.english", value: "interest rate", strict: false}}) {
edges {
node {
searchResult {
id
itemType
fields
mainContentField
rawLanguageTitle
}
}
}
}
Both of the above samples return content published using data publishing. If you want to retrieve content published using the old template-based publishing framework (which produces Component Presentations, among others), you must also include a
brokerResult node. The following sample shows a query fetching fields from both results:
{
searchByField(field: "content+japanese", value: "吹きエア調整", first:2, after:"Mg==") {
edges {
cursor
node {
searchResult {
id
itemType
locale
rawLanguageTitle
publicationTitle
publicationId
mainContentField
}
brokerResult{
title
}
}
}
}
}
The following codeblock similarly performs a search in content that was published using templates, but it searches by Content Manager ID:
{
searchById(identifier: "tcm_5-342")
{
searchResult {
id
rawLanguageTitle
}
brokerResult {
title
itemType
}
}
}
Another search for template-rendered content, again using the
searchByField function:
{
searchByField(field: "content+english", value: "Sitemap", strict: false) {
edges {
cursor
node {
searchResult {
id
rawLanguageTitle
}
brokerResult {
title
itemType
}
}
}
}
}
Finally, an example of
searchByCriteria:
{
searchByCriteria(criteria: {strict:false, field: "locale", value: "en_GB", or:
{field: "content+english", value: "Lorem", strict: true}},
sortBy: {fields: "clientId", sortAsText: true, sortingDirection: ASCENDING})
{
edges {
cursor
node {
searchResult {
id
rawLanguageTitle
}
brokerResult {
title
itemType
}
}
}
}
}
For more information, consult the API documentation itself, available through a client such as GraphiQL or GraphQL PlayGround.