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
There are cases where you want to find all the content resources which contain some 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 the field filters. For cases like these full-text search is the perfect tool for the job. With it you can find all the content resources which match your search terms in any of their text and symbol fields.
Full-text search can be used to find entries, assets or content types. For the remainder of this section we will refer to entries but the same principles and restrictions 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 your environment 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 to explain how these terms are transformed before they are sent to the search engine. 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's constituent parts) and normalized (i.e. guarantee that the tokens satisfy certain constrains, e.g. removing XML tags). Then each of the remaining search tokens is suffixed with a wildcard operator, which implies that full-text search at contentful is left-anchored.
When checking if an entry satisfies the search criteria, the search engine tests if all of the search tokens (i.e. the transformed search terms) can be found in any field in any locale in the entry. This means that an entry can be included in the result set due to matches in different fields and different locales or due to a match in just one field in just one locale. There is also no guarantee about 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 those words 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 with my 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 town will 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 a bluejacket 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 with content like there is a cat will match.
Check below the phrase full-text search section if you are interested on those entries where the given search terms can only be found in one field and in the same order as in the search input.
Check the full-text search on a field section if you are interested only on those entries where the given search terms are in only one field.
Phrase full-text searchBy default full-text search queries will take the search tokens and find all those entries where the tokens can be found in any field, in any locale and in any order. There are however cases where you might need a more restrictive search strategy and only get those entries where the matches are in the same order as you specificed in the search and in only one field. To achieve this you can wrap the search terms in double quotes (") to enable phrase search.
When you for example search for "my cat is blue", the search engine will find all the entries where the words my, cat, is and blue are found in that 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 with content like there is a cat will not match.
If you wish you can combine phrase search with the default full-text search behaviour. This can be useful to refine even more the result set. For example a search like "my cat is blue" summer london will match all those entries where the term "my cat is blue" can be found in just one field in one locale and where the terms summer and london can be found in any field in any locale present in the entry (including the field where the phrase was matched).
Other considerations about full-text searchFull-text search is case insensitive and might return more results than expected.
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 the equality search operator when searching for slugs or text IDs.
For more tips on using full-text search, see our Help Center article.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4