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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dargente’s picture

Category: support » task
Priority: Normal » Major
marcoka’s picture

Priority: Major » Normal

its not major if you need it fast. thats a normal feature request.

mgriebe’s picture

Does 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
?

ronin17’s picture

Just 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!

jbenezech’s picture

any workaround ?

drunken monkey’s picture

You 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.

SpadXIII’s picture

Issue summary: View changes
Status: Active » Needs work
FileSize
2.17 KB

Added 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.

SpadXIII’s picture

Title: Search API - Views - Solr Index - Date Filter » Search API - Date Filter between-operator
rudiedirkx’s picture

FileSize
3.24 KB

This breaks the default operator for me. The operator else (none of empty, non-empty, between) checked:

      while (is_array($this->value)) {
        $this->value = $this->value ? reset($this->value) : NULL;
      }

but value is now always an array with 'value', so that doesn't work anymore. What does work is

      $this->value = isset($this->value[0]) ? $this->value[0]['value'] : $this->value['value'];

because we only want 'value' here, and sometimes it's in [0] and sometimes it's not.

rudiedirkx’s picture

Status: Needs work » Needs review
drunken monkey’s picture

Status: Needs review » Needs work
Parent issue: » #1783746: Add support for "between" operator

Thanks, 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?

rudiedirkx’s picture

I 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 =(

drunken monkey’s picture

Does this patch only work if #1783746: Add support for "between" operator is applied? Then this should probably be a part of that...

Yes, it does.

SpadXIII’s picture

I 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.

drunken monkey’s picture

Status: Needs work » Closed (duplicate)

Thanks!
Yes, then let's close here.