Hi there,

I have a computed field which concatinates 4 text fields into one long string. I now want to be able to use the 'contains' operator to filter these fields. I had a poke around in the code and found at line 136:

<?php
    case 'filters':
      return array(
        'default' => array(
          'name' => t('Default'),
          'operator' => 'views_handler_operator_gtlt',
        ),
      );
?>

I then changed it to this:

<?php
    case 'filters':
      return array(
        'default' => array(
          'name' => t('Default'),
          // Note the change to the operator function below
          'operator' => 'views_handler_operator_like',
        ),
      );
?>

After stopping and starting the module this gave me the option of using the contains operator. However when I use it I get a whole lot of error messages which look like this:

    * user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'contains 'Thai')' at line 1 query: SELECT count(node.nid) FROM node node LEFT JOIN node_content_profile node_data_field_langabstring ON node.vid = node_data_field_langabstring.vid LEFT JOIN node_content_profile node_data_field_native_language ON node.vid = node_data_field_native_language.vid LEFT JOIN node_content_profile node_data_field_language_to_learn_1 ON node.vid = node_data_field_language_to_learn_1.vid LEFT JOIN node_content_profile node_data_field_ability_of_languae_1 ON node.vid = node_data_field_ability_of_languae_1.vid LEFT JOIN node_content_profile node_data_field_language_to_learn_2 ON node.vid = node_data_field_language_to_learn_2.vid LEFT JOIN node_content_profile node_data_field_abillity_in_language_2 ON node.vid = node_data_field_abillity_in_language_2.vid LEFT JOIN users users ON node.uid = users.uid LEFT JOIN node_content_profile node_ in /home/huitkcom/public_html/includes/database.mysql.inc on line 120.
    * user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'contains 'Thai') LIMIT 0, 5' at line 1 query: SELECT node.nid, node.title AS node_title, node.changed AS node_changed, node_data_field_native_language.field_native_language_value AS node_data_field_native_language_field_native_language_value, node_data_field_language_to_learn_1.field_language_to_learn_1_value AS node_data_field_language_to_learn_1_field_language_to_learn_1_value, node_data_field_ability_of_languae_1.field_ability_of_languae_1_value AS node_data_field_ability_of_languae_1_field_ability_of_languae_1_value, node_data_field_language_to_learn_2.field_language_to_learn_2_value AS node_data_field_language_to_learn_2_field_language_to_learn_2_value, node_data_field_abillity_in_language_2.field_abillity_in_language_2_value AS node_data_field_abillity_in_language_2_field_abillity_in_language_2_value, users.uid AS users_uid, node_data_field_country in /home/huitkcom/public_html/includes/database.mysql.inc on line 120.

It might be worth noting that when I use the 'equal to' operator from the selection generated by 'views_handler_operator_like' It works without any problems

So my question is: how can I change the module so that I can use the 'contains' operator? Is there a less hackish way of doing this?

Thanks for your help,

Neil

Comments

ncameron’s picture

Status: Active » Fixed

After a bit prodding and poking I've got it working. The whole filter case should look like below:

case 'filters':
        return array(
          'default' => array(
		    'name' => t('Default'),
            'operator' => 'views_handler_operator_like',
            'handler' => 'views_handler_filter_like',
          ),
        );
		break;

For the record, I have no knowledge of PHP/drupal/views/etc/etc it works for me (well, it hasn't broken my site yet) but it might not work for you.

Cheers,
Neil

wrunt’s picture

Category: support » feature
Status: Fixed » Active

What handler should be used probably depends on the data type of your computed field. Ideally the module would be able to work this out from the field's settings.

I'm opening this again as a feature request so I (or someone else) can come back to it later if I get time.

appel’s picture

I'd like to see that feature as well, subscribing.

jp.stacey’s picture

Hi,

Thanks very much, Huitalk, for your fix. I'd got as far as your first step and did the usual trick of Googling for error message + "drupal", and this post came up! I put the rest of the fix in and it worked eventually: I spent ages not having switched the module on and off, wondering what was going on....

Thanks to wrunt too, as computed field v5.x-1.2 (which I'm using) is currently working like a charm. I'm using it to store the content-owner's role IDs in implode()d form (I want nodeprofile-created node views to be filterable based on their owner's roles).

The one bit missing from my picture was this feature discussed here, as I needed to do string matching on '%,roleID,%'. So I vote for it too, but if wrunt's happy that this temporary fiddle won't cause trouble then I'm happy to wait.

Cheers,
J-P

Moonshine’s picture

Status: Active » Closed (fixed)

Closing out old Drupal 4.7 issues, as it is no longer a supported release.

eliza411’s picture

Thanks. This was needed and worked in D5, and it saved me so much time!