Problem/Motivation
While debugging an issue in the elasticsearch_connector queue (#3551591: Filter does not work with date range fields), I set up a date filter on a test view, and noticed a Negated regular expression (not_regular_expression) operator as an option.
I also notice that in \Drupal\search_api\Plugin\views\filter\SearchApiDate::operators(), we unset($operators['regular_expression']);, i.e.: removing regular_expression as an option.
We dropped support for regular_expression in #2601224: Add Views filters (and kept in #2695627: Add support for (NOT) IN and BETWEEN operators to Views when support for between and not between were added).
Given that regular_expression filtering for dates sounds like a non-trivial problem (i.e.: because dates can be expressed/stored/matched in various formats), I think it makes sense to also drop support for not_regular_expression.
Steps to reproduce
- Download the latest version of Drupal core (I got 11.3.6) and search_api (I cloned 8.x-1.x branch and got commit e96a1c88)
- Install Drupal with the
minimalinstall profile. - Log in as an administrator
- Go to
/admin/modules, enablefield_ui,views_ui,datetime,search_api, and search_api_db (other search backends will work too; I first noticed this issue with elasticsearch_connector). - Go to
/admin/structure/types/addand create a content type. I happened to give mine the machine nameevent. - Go to
/admin/structure/types/manage/event/fields/add-field, click Date and time. In the popup, enter Label =Event date(machine namefield_event_date), Choose a field type =Date, click theContinuebutton, then click theSavebutton to accept the defaults on the second page. - Go to
/node/add/event, set Title =Sprints, Event date =2026-04-10 09:45:00, then click theSavebutton. - Go to
/admin/config/search/search-api/add-serverand add a Search API Server. I happened to give mine the machine nameexample_db_backend. - Go to
/admin/config/search/search-api/add-index, set Index name =Events, Datasources =Content, Server =example_db_backend, then click theSavebutton. - Go to
/admin/config/search/search-api/index/events/fields/add/nojs; and click theAddbutton next to the Event date (field_event_date) field. Then click theDonebutton. On theManage fields for search index Events, in thefield_event_daterow, set Type =Date. Click theSave changesbutton. - Go to
/admin/config/search/search-api/index/events, and click theIndex nowbutton. 1 item is indexed. - Go to
/admin/structure/views/add. Set View name =Event search. Under View settings, "ShowIndex eventssorted byUnsorted. Click theSave and editbutton. - You are taken to the view-edit page. Next to Filter critera, click the
Addbutton. CheckEvent datein the Content datasource category. Click theAdd and configure filter criteriabutton. On the second page, click the Operator select list.
Expected behavior: You do not see a Regular expression option, nor a Negated regular expression option.
Actual behavior: You do not see a Regular expression option; but you do see a Negated regular expression option.
Proposed resolution
Remove support for the Negated regular expression (not_regular_expression) operator in \Drupal\search_api\Plugin\views\filter\SearchApiDate::operators()
Remaining tasks
Write a merge request with tests- merge request !321 created by @mparker17 in #6- Community review
- Maintainer review
- Commit
- Release
| Comment | File | Size | Author |
|---|
Issue fork search_api-3577065
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
Comment #2
mparker17Note that I was using Drupal core 11.3.3, search_api-8.x-1.40, and elasticsearch_connector-8.0.0-alpha6 when I noticed this (although the version of elasticsearch_connector should be irrelevant in this case).
Marking as Needs Review so I can get someone else's opinion on this.
Comment #3
mparker17Also here's a Screenshot of the Negated regular expression option appearing in a Views filter configuration modal for a SearchApiDate filter plugin...
Comment #4
mparker17(link to code where we unset the option)
Comment #5
mparker17After thinking about it for a bit, I think we should just simply drop support for not_regular_expression for search_api_date filters, so I've re-written the issue title and summary a bit, and I'll submit a merge request shortly.
Comment #7
mparker17Added merge request !321, reviews welcome!