silverstripeltd / silverstripe-discoverer

Service agnostic abstraction of search querying requirements
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Add support for query suggestions (aka "did you mean") #12

Closed chrispenny closed 2 months ago

chrispenny commented 3 months ago

Query

New Suggestion class (name is singular) provides the following options:

  1. Required: Query string that you want suggestions for
  2. Optional: Limit the number of suggestions that are returned
  3. Optional: Field that should be used for generating suggestions

Noting that not all services support "fields" for their suggestions, but this feels like a reasonable feature that could be silenctly ignored if plugins are created for those services.

Result

New Suggestions class (name is plural) which contains an array of string suggestions that were returned from your desired service.

forTemplate() and getIterator() provided so that you can loop through this object, which will give you one suggestion per iteration.

A couple of helper properties were added:

I've added a description of these fields to the class docblock, but TL;DR: they are there for developers to populate (if they want) so that when this object attempt to render, it knows where to link the query suggestion off to (EG: your search page).