Measurable Success «10 Checkpoints for Future-Proof Enterprise CMS» White Paper
Measurable Success - White Paper

suggest(prefix, options)

Suggests search terms that start with the provided prefix.

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:

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

Limit suggestions to specific attributes:

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

Limit the number of suggestions to 10:

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:

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

Boost suggestions in “Product” objects:

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