Contentful logo

Contentful Community

Example of how to search for a fuzzy match across multiple text fields at once?

Hi,

I have a collection of entries with content type ‘Article’

Each article has the following fields:

  • authorName (short text)
  • title (short text)
  • shortSummary (long text)
  • shortEssay (reference to a single entry of ‘Short Essay’ content type)
  • longEssay (reference to a single entry of ‘Long Essay’ content type)

The ‘Short Essay’ content type has a field called:

  • body (rich text)

The ‘Long Essay’ content type has a field called:

  • body (rich text)

Given a search string (for example, “aaa”) – I would like to find all entries with content type ‘Article’ where:

  • “aaa” is a fuzzy match on the ‘title’ field of the ‘Article’ entry
    OR
  • “aaa” is a fuzzy match on the ‘authorName’ field of the ‘Article’ entry
    OR
  • “aaa” is a fuzzy match on the ‘shortSummary’ field of the ‘Article’ entry
    OR
  • “aaa” is a fuzzy match on the ‘body’ field of the ‘Short Essay’ entry referenced from the ‘body’ field of the ‘Article’ entry
    OR
  • “aaa” is a fuzzy match on the ‘body’ field of the ‘Long Essay’ entry referenced from the ‘body’ field of the ‘Article’ entry

by fuzzy match, I mean the behavior exhibited by the [matches] operator documented here


how can I accomplish the above search with either the raw content delivery API, or preferably the Javascript SDK?

To summarize the search characteristics:

  • I want to search only against the fields mentioned above, and no others
  • I want to return entries where at least one of the fields matches the search string. that is, an OR clause of matches, not an AND clause of matches.
  • I want to search against text fields nested within references.