FullText search

Prismic no longer recommends the gatsby-source-prismic-graphql plugin

With recent changes to Gatsby, Prismic no longer recommends the gatsby-source-prismic-graphql plugin that this documentation uses. Read more about the future of Prismic and Gatsby. We highly recommend using the gatsby-source-prismic instead. The documentation for this plugin can be found in the plugin's github README.

We will leave this documentation here for now, but will change it in the future when we determine the best approach for Prismic & Gatsby.

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

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.

NOTE: The fulltext search is not case sensitive.

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 documents of the type Video that mention the term "Tutorial" in all the fields that support FullText search. We will be searching the documents in the "en-us" locale. Then we retrieve a Title field with the API ID of "topic" and the metadata with the lang:

Copy
{
  prismic {
    allVideos(fulltext: "Tutorial", lang: "en-us") {
      edges {
        node {
          topic
          _meta {
            lang
          }
        }
      }
    }
  }
}

Search on a specific field

To perform a fulltext search on a specific field, you will need to use the where argument and append _fulltext after the field's API ID that you want to search on.

In this example we will query all documents of the type Post that mention the term "Art" in a Title field that has the API ID of "topic". We will be searching the documents in the "en-us" locale. Then we retrieve the same Title field of "topic" and the metadata with the lang:

Copy
{
  prismic {
    allPosts(where: {topic_fulltext: "Art"}, lang: "en-us") {
      edges {
        node {
          topic
          _meta {
            lang
          }
        }
      }
    }
  }
}

Example with multiple search terms

You can also do a FullText search for multiple terms.

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.

In this example we will query all documents of the type Article that mention the terms "science" and "music" in a Key Text field that has the API ID of "category". We will be searching the documents in the "en-us" locale. Then we retrieve the same Key Text field of "category" and the metadata with the lang:

Copy
{
  prismic {
    allArticles(where: {category_fulltext: "science music"}, lang: "en-us") {
      edges {
        node {
          category
          _meta {
            lang
          }
        }
      }
    }
  }
}

If you need to implement a dynamic search for your project we recommend you to use a third party service that works with Gatsby. You can follow Gatsby's team's documentation for Adding search with Algolia.