Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Looking to incorporate a date filter within a Solr Index View. Presently the only option is for the user to manually enter a text date to filter by date. It would be nice to be able to search by M/d/Y using the 'Between' function which is available in the Content View. I noticed that the Between operator is missing from handler_filter.inc within the Search API module:
public function operator_options() {
return array(
'<' => t('Is smaller than'),
'<=' => t('Is smaller than or equal to'),
'=' => t('Is equal to'),
'<>' => t('Is not equal to'),
'>=' => t('Is greater than or equal to'),
'>' => t('Is greater than'),
);
}
What other code would we need to modify in order to get a more user-friendly date filter available for the user to query?
Comment | File | Size | Author |
---|---|---|---|
#9 | search_api-1595230-9.patch | 3.24 KB | rudiedirkx |
|
Comments
Comment #1
dargente CreditAttribution: dargente commentedComment #2
marcoka CreditAttribution: marcoka commentedits not major if you need it fast. thats a normal feature request.
Comment #3
mgriebe CreditAttribution: mgriebe commentedDoes anyone know why the views filter options are different for indexed items in the first place?
The only filter options for numeric indexed fields are:
Is smaller than
Is smaller than or equal to
Is equal to
Is not equal to
Is greater than or equal to
Is greater than
What happened to:
Is between
Is not between
Is null
Is not null
Regular Expressions
Or for string fields you get NUMERIC options!
For Full Text you only get:
contains
does not contain
Why isn't there:
contains any word
contains all words
Length is shorter than
Length is longer than
Starts with
Does not start with
ends with
?
Comment #4
ronin17 CreditAttribution: ronin17 commentedJust curious if there was any updates to this? I'd really like to be able to use the usual exposed filter options that a date field would normally offer.
Thanks!
Comment #5
jbenezech CreditAttribution: jbenezech commentedany workaround ?
Comment #6
drunken monkeyYou can just create both a "greater than" and a "lower than" exposed filter, that should do the same thing.
As for the rest, some of the options from #3 have been added in the meantime. However, since "normal" views and Search API views use completely different backends, all filter options have to be implemented in the Search API again, simply re-using them isn't possible.
And some of these options (regular expressions and nearly all of the suggested fulltext options) are just not supported in the Search API, and can therefore also not be implemented in Views based on them.
A "between" filter option is currently also not supported by the Search API, but is worked on in #1783746: Add support for "between" operator. You can also expect it to be present in the module's D8 branch (#2044393: Changes in search query functionality), but I guess that is llittle consolation.
Comment #7
SpadXIII CreditAttribution: SpadXIII at ezCompany commentedAdded a patch to add support for the between-operator for date filters.
Just tested this together with the patch in https://www.drupal.org/node/1783746#comment-10685454 and https://www.drupal.org/node/2459457#comment-11854155 and it seems to work fine.
This one and the 2 linked patches are required for the between operator to work with date-filters.
I'll leave it as 'needs work' because the parent patch in #1783746 needs to get committed first. And also because 'not between' does not work yet.
Comment #8
SpadXIII CreditAttribution: SpadXIII at ezCompany commentedComment #9
rudiedirkx CreditAttribution: rudiedirkx at ezCompany commentedThis breaks the default operator for me. The operator else (none of empty, non-empty, between) checked:
but value is now always an array with 'value', so that doesn't work anymore. What does work is
because we only want
'value'
here, and sometimes it's in[0]
and sometimes it's not.Comment #10
rudiedirkx CreditAttribution: rudiedirkx at ezCompany commentedComment #11
drunken monkeyThanks, looks quite good!
Can others confirm this is working for them? Of course, we'll first need to commit the other patches. Also, this one (like the others) needs proper checks for the feature yet to be defined for the "between" operator.
However, is there any reason why you don't just add this to the patch in #1783746: Add support for "between" operator?
Comment #12
rudiedirkx CreditAttribution: rudiedirkx at ezCompany commentedI don't know... All I did was change the patch from #7 slightly.
Does this patch only work if #1783746: Add support for "between" operator is applied? Then this should probably be a part of that...
I'll put it on the list, but I'm not using Search API right now, so it could take a while. The other issue is 4.5 y old already =(
Comment #13
drunken monkeyYes, it does.
Comment #14
SpadXIII CreditAttribution: SpadXIII at ezCompany commentedI combined this patch with the one from #1783746. This issue can be closed now, I think?
I added a small fix for the min/max fields which did not use the correct date_format and year-range.
Comment #15
drunken monkeyThanks!
Yes, then let's close here.