Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

Avatar

Level 3

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?

1 Accepted Solution

Avatar

Correct answer by
Level 4

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-ap...

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"
        }
      ]
    }
  }
}

 

View solution in original post

1 Reply

Avatar

Correct answer by
Level 4

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-ap...

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"
        }
      ]
    }
  }
}