Problem/Motivation

Sometimes it is needed to have user input for search filters and facets are not enough. For example when there is a filter by published date and it should be possible to find the items that were published in some period of time. For this exposed filters are needed as UI Element.

Proposed resolution

Create new search ui element plugin "Exposed Filter" with following settings:
- Field Name that is used as filter
- Operator (=, between, >, >=, <, =<) maybe more?
- default value of the filter?

Remaining tasks

Provide MR.

User interface changes

New widget in search UI client will be needed.

API changes

Search endpoint request needs to understand the range filter parameters (min/max or from/to)

Data model changes

No changes.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

a.dmitriiev created an issue. See original summary.

a.dmitriiev’s picture

Status: Active » Needs review

I have added new search_ui_element plugin "Exposed filter" (exposed_filter). This is only for UI settings so that the client knows that there are filters that user can use, it is not influencing in any way the result on the endpoint itself. It is still possible to filter by any field that is in the index.

Client needs to send the field_name from search ui element setting as query parameter to the search endpoint. In case of multivalue filter when IN operator should be used the query should look like ?<field_name>[]=1&<field_name>[]=2. In case of "between" operator the query should look like ?<field_name>[min]=1&<field_name>[max]=2 (min/max are not hardcoded, it can be also from/to or any other key, but for "Between" operator it is mandatory to have exactly 2 values and first value will be minimum value and second - maximum).

To be able also construct the query for complex filters easily the new operator query parameter was added. It is possible to set the operator explicitly (for "equal", "between" and "in" the operator is implied, not need to set it in the query, see explanation above). Operator query parameter should be an array with keys that represent the filter field names, that should also be passed as query parameter.

The allowed operators are:

[
      'equal' => t('Equal'),
      'between' => t('Between'),
      'gt' => t('Greater than'),
      'gte' => t('Greater than or equal'),
      'lt' => t('Less than'),
      'lte' => t('Less than or equal'),
      'not_equal' => t('Not equal'),
      'not_in' => t('Not in'),
    ]

Example query for all items that have created date greater than or equal to certain timestamp (e.g. 1638467243): ?created=1638467243&operator[created]=gte

a.dmitriiev’s picture

Status: Needs review » Fixed

Reviewed by client team, the new version of client 1.1.1 was released to support exposed filters.

a.dmitriiev’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.