New in 1.11.0

suggest(prefix, options)

Suggests search terms that start with the provided prefix.

Copy
Scrivito.Obj.all().suggest('Ham');
// ["hamburger", "hammer", "hamper", "hamster", "hamburg"]

suggest works case insensitive, and all results are converted to lower case.

Preceding calls to and or andNot may limit the amount of documents that are searched for suggestions.

Preceding calls to boost may adjust the ranking of the documents from which suggestions are taken.

Params

  • prefix (String) – The prefix string for which suggestions should be determined.
  • options (optional) (Object)
    • limit (number) – The maximum number of suggestions to return. Defaults to 5. Maximum: 100.
    • attributes (Array<String>) – The list of attributes that serve as input for suggestions. The special value ["*"], which is the default, causes all html, string and stringlist attributes to be taken account of.

Returns

Array<String> – A list of words the user could search for.

Throws

  • ArgumentError if an invalid option has been provided.

Examples

List suggestions that start with sc:

Copy
Scrivito.Obj.all().suggest('sc');
// ["scrivito", "science", "screen"]

Limit suggestions to specific attributes:

Copy
Scrivito.Obj.all().suggest('ham', { attributes: ['title'] })
// ["hammer"]

Limit the number of suggestions to 10:

Copy
Scrivito.Obj.all().suggest('sc', { limit: 10 });
// ["scrivito", "science"]

Limit suggestions for the prefix Kin to objects for which the “de” language flag is set:

Copy
Scrivito.Obj.where('language', 'equals', 'de').suggest('Kin');
// ["kindergarten", "kind", "kinder"]

Boost suggestions in “Product” objects:

Copy
Scrivito.Obj.all().boost('_objClass', 'equals', 'Product', 10).suggest('Ham');
// ["hammer", "hamburger", "hamper", "hamster"]