Fulltext Search
You can use the fulltext argument to search for documents that contain a given term or terms.
It searches the term(s) in any of the following field types:
- Rich Text
- Title
- Key Text
- UID
- Select
Note that the fulltext search is not case sensitive.
You can either perform a fulltext search on all the fields that support the fulltext search or perform a fulltext search on a specific field.
If you want to perform a global search based on all the fields that support fulltext search, you will use the fulltext argument at the first level of your query.
Note about languages
To perform a fulltext search, the lang argument is mandatory even if there is only one language in the repository.
Here is an example to get all the blog posts (using the allBlog_posts query field) that mention the term "Slice" in all the fields that support fulltext search. In this case we are specifying the blogs in the "en-us" locale.
query{
allBlog_posts(lang:"en-us", fulltext:"Slice"){
edges{
node{
title
description
}
}
}
}
To perform a fulltext search on a specific field, you need to use the where argument and specify the field that you want to search on. In order to do this, you just need to append _fulltext to the field's API ID.
In this example we will query the blog posts that mention the term "Slice" in the title. In this case, the title field has the API ID of "title", so we will use title_fulltext to do this. We will be searching the documents in the "en-us" locale.
query{
allBlog_posts(lang:"en-us", where:{title_fulltext:"Slice"}){
edges{
node{
title
description
}
}
}
}
When searching for multiple terms, the document must contain all the search terms. To enter multiple terms, simply put a space between the words as shown below.
The following example will return all the "blog_post" documents in the "en-us" locale that contain the terms "apple" and "banana" in the blog's "title" field.
query{
allBlog_posts(lang:"en-us", where:{title_fulltext:"apple banana"}){
edges{
node{
title
description
}
}
}
}