AEM 6.5: GraphQL FullText Search (like) in content fragments. [QueryBuilder has its own limitations stated below] | Community
Skip to main content
Level 4
September 19, 2022
Solved

AEM 6.5: GraphQL FullText Search (like) in content fragments. [QueryBuilder has its own limitations stated below]

  • September 19, 2022
  • 1 reply
  • 1144 views

I wanted to know if its possible to perform a full text search in AEM GraphQL API within content fragments?

 

For example I have a content fragment model which have 3 fields:

1. title

2. Body

3. date

 

I want to get all the content fragment where title contains `abc` and body contains `def`. I saw queryBuilder API and assets API. Assets API doesn't seem to support Searching and queryBuilder API does have limitations when querying nested content fragments. To give you an example:

 

I have a content fragment model User like this:

 

name: TextField

age: Number

address: Address (Another Content Fragment Model)

 

And here's how Adress looks like:

 

pinCode: Number

Street1: TextField

Street2: TextField

City: TextField

Country: TextField

 

When I query for `User` using queryBuilder API, I don't get complete `Address` fields instead I only get reference of `Address`. However when I query the same using GQL, I get all the fields and that's why I need the search functionality to happen in GQL. Is it possible as of AEM 6.5?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Saravanan_Dharmaraj

Yes you can do "Contains" query in GQL, Please check this example out in this page.

https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-api/sample-queries.html?lang=en#sample-all-persons-jobs-smith

Example section: Sample Query - All cities with SAN in the name, irrespective of case

query {
  cityList(filter: {
    name: {
      _expressions: [
        {
          value: "SAN"
          _operator: CONTAINS
          _ignoreCase: true
        }
      ]
    }
  }) {
    items {
      name
      population
      country
    }
  }
}

 

Sample Results

{
  "data": {
    "cityList": {
      "items": [
        {
          "name": "San Francisco",
          "population": 883306,
          "country": "USA"
        },
        {
          "name": "San Jose",
          "population": 1026350,
          "country": "USA"
        }
      ]
    }
  }
}

 

1 reply

Saravanan_Dharmaraj
Community Advisor
Saravanan_DharmarajCommunity AdvisorAccepted solution
Community Advisor
September 19, 2022

Yes you can do "Contains" query in GQL, Please check this example out in this page.

https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-api/sample-queries.html?lang=en#sample-all-persons-jobs-smith

Example section: Sample Query - All cities with SAN in the name, irrespective of case

query {
  cityList(filter: {
    name: {
      _expressions: [
        {
          value: "SAN"
          _operator: CONTAINS
          _ignoreCase: true
        }
      ]
    }
  }) {
    items {
      name
      population
      country
    }
  }
}

 

Sample Results

{
  "data": {
    "cityList": {
      "items": [
        {
          "name": "San Francisco",
          "population": 883306,
          "country": "USA"
        },
        {
          "name": "San Jose",
          "population": 1026350,
          "country": "USA"
        }
      ]
    }
  }
}