Content Preview API (2024)

You have available two flavours of full-text search:

  • Global, described in this section

  • Field scoped, described in the section full-text search on a field

How does global full text search work

There are cases where you want to find all the content resources which containsome particular words (search terms) but you don't know from which content type(for entries) or on which field those terms can be, so you can't use any of thefield filters. For cases like these full-text search is the perfect tool forthe job. With it you can find all the content resources which match your searchterms in any of their text and symbol fields.

Full-text search can be used to find entries, assets or content types. For theremainder of this section we will refer to entries but the same principles andrestrictions will apply to the other types.

Which content is looked up during a global full-text search?

All text (both regular and rich text) and symbol fields in all the locales in yourenvironment will be looked up when doing a global full-text search.

How is an entry considered a match?

Before we explain how we identify matches to your search terms we have toexplain how these terms are transformed before they are sent to the searchengine. After the API has received your query, the input string is sanitized(i.e. some special characters are removed), tokenized (i.e. split into it'sconstituent parts) and normalized (i.e. guarantee that the tokens satisfycertain constrains, e.g. removing XML tags). Then each of the remaining search tokens is suffixed witha wildcard operator, which implies that full-text search at contentful isleft-anchored.

When checking if an entry satisfies the search criteria, the search engine testsif all of the search tokens (i.e. the transformed search terms) can be found inany field in any locale in the entry. This means that an entry can be includedin the result set due to matches in different fields and different locales ordue to a match in just one field in just one locale. There is also no guaranteeabout the order in which the search terms can appear in the matching entries.A search for modern red house can be matched with entries which have thosewords in any possible order (e.g. red ... house ... modern, red ... modern... house, etc.).

All this combined means that when you for example search for my cat is blue,the search engine will find all the entries where there are words starting withmy and cat and is and blue:

  • A field with content like my cat is blue will match.

  • A field with content like my cat is red will not match.

  • A field with content like there is a catastrophic blueberries accident in my townwill match.

  • A field with content like there is a caterpillar in my house will not match.

  • A field with content like this is a picture of a caterpillar and myself wearing abluejacket will match.

  • A field with content like my cat is <b>blue</b> will match.

  • A field with content like my cat is <b class="blue">great</b> will not match.

  • An entry with a field with content like my house was blue and another field withcontent like there is a cat will match.

Check below the phrase full-text search section if you are interested on thoseentries where the given search terms can only be found in one field and in thesame order as in the search input.

Check the full-text search on afield section if you areinterested only on those entries where the given search terms are in only onefield.

Phrase full-text search

By default full-text search queries will take the search tokens and find allthose entries where the tokens can be found in any field, in anylocale and in any order. There are however cases where you might need a morerestrictive search strategy and only get those entries where the matches arein the same order as you specificed in the search and in only one field. Toachieve this you can wrap the search terms in double quotes (") to enable phrasesearch.

When you for example search for "my cat is blue", the search engine will findall the entries where the words my, cat, is and blue are found inthat order in one field:

  • A field with content like my cat is blue will match.

  • A field with content like my cat is <b>blue</b> will match.

  • A field with content like blue is the color of my cat will not match.

  • A field with content like my caterpillar is blue will not match.

  • An entry with a field with content like my house was blue and another field withcontent like there is a cat will not match.

If you wish you can combine phrase search with the default full-text searchbehaviour. This can be useful to refine even more the result set. For example asearch like "my cat is blue" summer london will match all those entries wherethe term "my cat is blue" can be found in just one field in one locale andwhere the terms summer and london can be found in any field in any localepresent in the entry (including the field where the phrase was matched).

Other considerations about full-text search

  • Full-text search is case insensitive and might return more results thanexpected.

  • A query will ignore search tokens with less than 2 characters.

  • When using full text search, make your search terms as specific as possible.

  • The [match] operator might return better results.

  • Use phrase search when possible as it has better performance.

  • For performance reasons it is recommended to use theequality search operatorwhen searching for slugs or text IDs.

For more tips on using full-text search, see our Help Centerarticle.

Content Preview API (2024)
Top Articles
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 6089

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.