In my view, the filter: Node: Level Tweet is not being applied:
here the view:

$view = new view;
$view->name = 'search_tweets_hash';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'search_api_index_default_node_index';
$view->human_name = 'Search Tweets Hash';
$view->core = 7;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Search Tweets Hash';
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '13';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['inline'] = array(
  'field_arroba' => 'field_arroba',
  'field_hash' => 'field_hash',
);
$handler->display->display_options['row_options']['separator'] = '  ';
$handler->display->display_options['row_options']['hide_empty'] = 0;
$handler->display->display_options['row_options']['default_field_elements'] = 1;
/* Field: Node: Node ID */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'search_api_index_default_node_index';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['fields']['nid']['label'] = '';
$handler->display->display_options['fields']['nid']['exclude'] = TRUE;
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['nid']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['nid']['alter']['external'] = 0;
$handler->display->display_options['fields']['nid']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['nid']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nid']['alter']['html'] = 0;
$handler->display->display_options['fields']['nid']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['nid']['element_default_classes'] = 1;
$handler->display->display_options['fields']['nid']['hide_empty'] = 0;
$handler->display->display_options['fields']['nid']['empty_zero'] = 0;
$handler->display->display_options['fields']['nid']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['nid']['link_to_entity'] = 0;
/* Field: Node: Profile Image */
$handler->display->display_options['fields']['field_profile_image_url']['id'] = 'field_profile_image_url';
$handler->display->display_options['fields']['field_profile_image_url']['table'] = 'search_api_index_default_node_index';
$handler->display->display_options['fields']['field_profile_image_url']['field'] = 'field_profile_image_url';
$handler->display->display_options['fields']['field_profile_image_url']['label'] = '';
$handler->display->display_options['fields']['field_profile_image_url']['alter']['alter_text'] = 1;
$handler->display->display_options['fields']['field_profile_image_url']['alter']['text'] = '<img src=\'[field_profile_image_url]\' alt=\'[title]\' />';
$handler->display->display_options['fields']['field_profile_image_url']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_profile_image_url']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_profile_image_url']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_profile_image_url']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_profile_image_url']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_profile_image_url']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_profile_image_url']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_profile_image_url']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_profile_image_url']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_profile_image_url']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_profile_image_url']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_profile_image_url']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_profile_image_url']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_profile_image_url']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_profile_image_url']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_profile_image_url']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['field_profile_image_url']['link_to_entity'] = 0;
/* Field: Node: twitter arroba */
$handler->display->display_options['fields']['field_arroba']['id'] = 'field_arroba';
$handler->display->display_options['fields']['field_arroba']['table'] = 'search_api_index_default_node_index';
$handler->display->display_options['fields']['field_arroba']['field'] = 'field_arroba';
$handler->display->display_options['fields']['field_arroba']['label'] = 'From';
$handler->display->display_options['fields']['field_arroba']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_arroba']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_arroba']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_arroba']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_arroba']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_arroba']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_arroba']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_arroba']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_arroba']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_arroba']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_arroba']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_arroba']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_arroba']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_arroba']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_arroba']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_arroba']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_arroba']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['field_arroba']['link_to_entity'] = 0;
$handler->display->display_options['fields']['field_arroba']['format_name'] = 1;
/* Field: Node: twitter hash */
$handler->display->display_options['fields']['field_hash']['id'] = 'field_hash';
$handler->display->display_options['fields']['field_hash']['table'] = 'search_api_index_default_node_index';
$handler->display->display_options['fields']['field_hash']['field'] = 'field_hash';
$handler->display->display_options['fields']['field_hash']['label'] = 'In';
$handler->display->display_options['fields']['field_hash']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_hash']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_hash']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_hash']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_hash']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_hash']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_hash']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_hash']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_hash']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_hash']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_hash']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_hash']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_hash']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_hash']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_hash']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_hash']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_hash']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['field_hash']['link_to_entity'] = 0;
$handler->display->display_options['fields']['field_hash']['format_name'] = 1;
/* Field: Node: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'search_api_index_default_node_index';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['path'] = 'http://sport.peoplenews.me/node/[nid] ';
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['external'] = 0;
$handler->display->display_options['fields']['title']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['title']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['element_default_classes'] = 1;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['title']['link_to_entity'] = 1;
/* Field: Node: Level Tweet */
$handler->display->display_options['fields']['field_level_tweet']['id'] = 'field_level_tweet';
$handler->display->display_options['fields']['field_level_tweet']['table'] = 'search_api_index_default_node_index';
$handler->display->display_options['fields']['field_level_tweet']['field'] = 'field_level_tweet';
$handler->display->display_options['fields']['field_level_tweet']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_level_tweet']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_level_tweet']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_level_tweet']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_level_tweet']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_level_tweet']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_level_tweet']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_level_tweet']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_level_tweet']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_level_tweet']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_level_tweet']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_level_tweet']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_level_tweet']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_level_tweet']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_level_tweet']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_level_tweet']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_level_tweet']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['field_level_tweet']['link_to_entity'] = 0;
/* Sort criterion: Node: Date created */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'search_api_index_default_node_index';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Node: Sección */
$handler->display->display_options['arguments']['field_seccion']['id'] = 'field_seccion';
$handler->display->display_options['arguments']['field_seccion']['table'] = 'search_api_index_default_node_index';
$handler->display->display_options['arguments']['field_seccion']['field'] = 'field_seccion';
$handler->display->display_options['arguments']['field_seccion']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['field_seccion']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['field_seccion']['summary']['format'] = 'default_summary';
/* Filter criterion: Node: Content type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'search_api_index_default_node_index';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'tweet_articulo' => 'tweet_articulo',
);
/* Filter criterion: Node: Level Tweet */
$handler->display->display_options['filters']['field_level_tweet']['id'] = 'field_level_tweet';
$handler->display->display_options['filters']['field_level_tweet']['table'] = 'search_api_index_default_node_index';
$handler->display->display_options['filters']['field_level_tweet']['field'] = 'field_level_tweet';
$handler->display->display_options['filters']['field_level_tweet']['value'] = '0';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'search-tweets-hash';
$translatables['search_tweets_hash'] = array(
  t('Master'),
  t('Search Tweets Hash'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('<img src=\'[field_profile_image_url]\' alt=\'[title]\' />'),
  t('From'),
  t('In'),
  t('http://sport.peoplenews.me/node/[nid] '),
  t('Level Tweet'),
  t('All'),
  t('Page'),
);

I also atacch the screens of the view paraemters and the view preview

Files: 
CommentFileSizeAuthor
#27 1318904--views_null_value_handling-27.patch8.77 KBdrunken monkey
PASSED: [[SimpleTest]]: [MySQL] 269 pass(es).
[ View ]
#26 1318904-26-search_api-null_views_filter.patch8.33 KBorakili
PASSED: [[SimpleTest]]: [MySQL] 269 pass(es).
[ View ]
#24 1318904-24-search_api-null_views_filter.patch8.33 KBorakili
FAILED: [[SimpleTest]]: [MySQL] 5 pass(es), 8 fail(s), and 5 exception(s).
[ View ]
#18 1318904-18-search_api-null_views_filter.patch1.34 KBbecw
FAILED: [[SimpleTest]]: [MySQL] 271 pass(es), 1 fail(s), and 0 exception(s).
[ View ]
#6 search_api_views-filter-handler-fix-for-zeros.patch639 bytesdas-peter
FAILED: [[SimpleTest]]: [MySQL] 271 pass(es), 1 fail(s), and 0 exception(es).
[ View ]
Screenshot-2.png196.37 KBegarias
Screenshot-1.png219.35 KBegarias

Comments

dawehner’s picture

Does the sql version (not search_api) works for you? If yes please move it to search_api

Kars-T’s picture

Status:Active» Fixed

Closing this due to long inactivity. Feel free to reopen the issue and provide more information.

Kars-T’s picture

Issue tags:+dvcs11

Adding tag

egarias’s picture

Project:Views» Search API
Version:7.x-3.0-rc1» 7.x-1.0-rc1
Component:Code» Views integration
Status:Fixed» Active

the sql version (not search_api) works, so it should be a search-api issue

drunken monkey’s picture

Maybe the data hasn't been indexed in its latest version? Do the „Level Tweet“ values change (frequently)? Or are they maybe multi-valued?

das-peter’s picture

Status:Active» Needs review
StatusFileSize
new639 bytes
FAILED: [[SimpleTest]]: [MySQL] 271 pass(es), 1 fail(s), and 0 exception(es).
[ View ]

I'd say this has to do with the filter value being 0.
Currently SearchApiViewsHandlerFilter skips everything that's interpreted as FALSE by php.
This means "", 0, NULL are skipped.
But 0 should really be applied as filter.
Thus I'd suggest to change the check from
if ($this->value) {
to
if (strlen($this->value)) {

Attached patch does that.

Status:Needs review» Needs work
Issue tags:-dvcs11

The last submitted patch, search_api_views-filter-handler-fix-for-zeros.patch, failed testing.

das-peter’s picture

Status:Needs work» Needs review

Status:Needs review» Needs work
Issue tags:+dvcs11

The last submitted patch, search_api_views-filter-handler-fix-for-zeros.patch, failed testing.

das-peter’s picture

Seriously, I don't get it why the affected test should fail because of this patch :|

colle901’s picture

I have a similar problem, but with a text filter. I want to include all content where a text field is null or empty. When I set the filter to "=" (empty value) I get all records returned including those with the value set.

I'm sorry if this is not related to the original issue-- let me know and I can open a separate ticket.

das-peter’s picture

@colle901: Interesting point, my patch definitely won't work out for you, because strlen() will always be 0.

I'd say to solve this we need a special option, otherwise I see conflicts e.g. with the exposed filter, where empty fields are set as GET parameters too.

For the moment I'd suggest following:
A new option for the exposed filter "Allow empty values" which defaults to FALSE.
In situations where the filter isn't exposed the query accepts always all input. But if the filter is exposed its checked whether to allow an empty filter value or not based on the option.

@colle901: Would this work with your use case?

colle901’s picture

If I understand what you are describing correctly, it should work for what I need.

Just for comparison, I have a similar view that does not use Search API where I created a filter on a text field using two conditions with an OR: "=" (empty value) OR "is empty".

This lets through all records where that field is either an empty string or NULL. I am simply looking to duplicate that condition using an indexed string field with Search API.

das-peter’s picture

Ah, thanks for the hint - we could introduce an "is empty" operator to cover such cases.

colle901’s picture

An "is empty" operator would be great.

I was initially confused by the standard views version because I expected it to work more like PHP "empty" (which includes empty strings and zero in addition to NULL), but I was able to get around it by adding the empty string condition. I know I am biased by my particular use case, but I would prefer a PHP style "is empty" operator.

colle901’s picture

I am coming up against a deadline soon and was just wondering if this was going to be addressed. I don't have the time to put into it right now. If it helps, my client would be willing to pay for the patch to be completed if it could happen within the next week (as well as correcting this issue). Contact me directly if interested.

lucascaro’s picture

what if you use isset($this->value) instead of strlen?

becw’s picture

Title:Filter not applied» "is empty" views filter operator (patch)
Status:Needs work» Needs review
StatusFileSize
new1.34 KB
FAILED: [[SimpleTest]]: [MySQL] 271 pass(es), 1 fail(s), and 0 exception(s).
[ View ]

I think that it makes sense not to apply an "=" filter if the filter value is empty, but it there should be an empty/not empty filter.

Here's a patch that adds "is null" and "is not null" operators to the search_api_views filter handler. I've tested this with the Solr integration (and it works with no modifications to search_api_solr), but we may need to add support for this to other search backends' service classes.

Status:Needs review» Needs work

The last submitted patch, 1318904-18-search_api-null_views_filter.patch, failed testing.

rafaqz’s picture

#18 working well for me, thanks for the patch.

egarias’s picture

I am using db search
the filter node promoted = 0 doesn't work for me.

orakili’s picture

Status:Needs work» Needs review
Issue tags:-dvcs11

Status:Needs review» Needs work
Issue tags:+dvcs11

The last submitted patch, 1318904-18-search_api-null_views_filter.patch, failed testing.

orakili’s picture

Version:7.x-1.0-rc1» 7.x-1.2
Status:Needs work» Needs review
StatusFileSize
new8.33 KB
FAILED: [[SimpleTest]]: [MySQL] 5 pass(es), 8 fail(s), and 5 exception(s).
[ View ]

New patch that also adds the empty operator for the date and options filters.

Note that I used "empty" and "not empty" for the operators' name like in the views_handler_filter_in_operator etc.

Status:Needs review» Needs work

The last submitted patch, 1318904-24-search_api-null_views_filter.patch, failed testing.

orakili’s picture

Version:7.x-1.2» 7.x-1.x-dev
Category:bug» feature
Status:Needs work» Needs review
StatusFileSize
new8.33 KB
PASSED: [[SimpleTest]]: [MySQL] 269 pass(es).
[ View ]

Wrong version, it's for 7.x-1.x-dev

Re-attaching the same patch as in #24.

drunken monkey’s picture

Title:"is empty" views filter operator (patch)» Improved handling for NULL values in Views
StatusFileSize
new8.77 KB
PASSED: [[SimpleTest]]: [MySQL] 269 pass(es).
[ View ]

Great work, everyone, thanks! Seems to work great!
Also good catch, Peter! Didn't see that …

Attached is a patch combining both the bug fix and the feature (although this should have been done in a separate issue). Also, I improved the admin summaries.

Please test whether this still works as expected!

jonloh’s picture

I've applied the patch. which is showing the additional operators. However, when I tried to filter a field, it doesn't seem to take effect on the query.

For example, I would like to filter out indexed node with field_a that are not empty. When I update preview, it still shows both empty and not empty nodes.

orakili’s picture

It will only work if the Search API backend handles NULL values for filters. It should work fine with Search API Sphinx and Search API elascticsearch but I don't know for others. Patching those backends may be needed to have the intended effect.

drunken monkey’s picture

Status:Needs review» Fixed

Committed. Thanks everyone!

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