prepare_search_request ~search_query ~count_query ~filter_fragment ?sort_by_field type returns a prepared SQL statement 'a prepared_search_request by assembling the SQL query from the provided fragments.
search_query is the SELECT ... FROM table part of the query.
count_query is a query that is executed by Sihl after the search in order to obtain the total number of items in the table. For example SELECT COUNT(\*\) FROM table.
filter_fragment is the fragment that is appended to search_query for filtering. Usually you want ot OR fields that are often searched for. For example WHERE table.field1 LIKE $1 OR table.field2 $1 OR table.field3 LIKE $1.
sort_by_field is an optional field name that is used for sorting. By default, the field "id" is used. Note that in order to prepare the requests, the sort field has to be known beforehand. If you want to dynamically set the field, you need to write your own query at runtime.
format_filter is a function applied to the filter keyword before it is passed to the database. By default, a keyword "keyword" is formatted to "%skeyword%s". This might not be what you want performance-wise. If you need full control, pass in the identity function and format the keyword yourself.
type is the caqti type of an item of the collection.