Problem/Motivation

Hi,

i think the name_handler_filter_name_fulltext has a bug. It does not match the surname.

Steps to reproduce

  • Attach a name field to a entity type
  • Create a entity. Use "John Doe" as value in your name field.
  • Create a view with a exposed fulltext filter.
  • Search for "Doe" in your exposed filter.
  • No results found.

It fails because the LIKE condition in name_handler_filter_name_fulltext::op_contains adds one additional space.

Without this patch: LIKE '% doe%'
With this patch: LIKE %doe%

Proposed resolution

Fix LIKE condition in name_handler_filter_name_fulltext::op_contains

Comments

webflo’s picture

Status: Active » Needs review
StatusFileSize
new823 bytes
alan d.’s picture

This came up in https://drupal.org/node/1369618#comment-5542738 to ensure that search for cd didn't match abcd, but matched cdef.

SELECT CONCAT('"', (LOWER(CONCAT(' ', COALESCE(field_data_field_name_test.field_name_test_title, ''), ' ', COALESCE(field_data_field_name_test.field_name_test_given, ''), ' ', COALESCE(field_data_field_name_test.field_name_test_middle, ''), ' ', COALESCE(field_data_field_name_test.field_name_test_family, ''), ' ', COALESCE(field_data_field_name_test.field_name_test_generational, ''), ' ', COALESCE(field_data_field_name_test.field_name_test_credentials, '')))), '"') FROM `field_data_field_name_test` 

produces " john doe ", so both '% doe%' and '%doe%' would match this string. Are you sure that you didn't have both first and second names in the search? ie: "%john doe%" != " john doe "

mparker17’s picture

This looks like a duplicate of #2536618: Extra space added when searching with CONTAINS in Views Exposed Filters., except the patch in #2536618-2: Extra space added when searching with CONTAINS in Views Exposed Filters. fixes the issue in both the "contains" and the "contains word" filters.

Is it worth closing this issue, or #2536618?

joelpittet’s picture

Priority: Normal » Major

I'll close this as a duplicate of #2536618: Extra space added when searching with CONTAINS in Views Exposed Filters. because the other has more details and fixes the problem more completely. But I'd suggest crediting @webflo on the other one.

That or @mparker17 could you post your patches here and update the IS?

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

This looks like a quick fix.

mparker17’s picture

@joelpittet, not sure I understand what you want me to do in #4... judging by your comments in #5 and your request for credit for @webflo in #2090789-5: Fulltext Filter does not match surname, is it safe for me to assume that there is nothing I need to do?

joelpittet’s picture

@mparker17 since you replied, could you move your code here and close your issue? That would be the easiest

mparker17’s picture

Sure thing!

mparker17’s picture

StatusFileSize
new1.62 KB

Uploading patch from #2536618-2: Extra space added when searching with CONTAINS in Views Exposed Filters..

To make things easier to understand, I will fix \name_handler_filter_name_fulltext::op_word() inside includes/name_handler_filter_name_fulltext.inc in a separate patch, with interdiff.

mparker17’s picture

Oh, turns out the change to op_word() was already done: I think the diff file didn't make that clear in the hunk headings. So this is ready to go.

joelpittet’s picture

Still RTBC, thank you @mparker17, that should make it easier to credit you both.

alan d.’s picture

Priority: Major » Normal
Status: Reviewed & tested by the community » Postponed (maintainer needs more info)
StatusFileSize
new68.26 KB

I just tried repeating again without issue. As per #4 above, the query generated is:

(LOWER(CONCAT(' ', COALESCE(field_data_field_multiple_names.field_multiple_names_title, ''), ' ', COALESCE(field_data_field_multiple_names.field_multiple_names_given, ''), ' ', COALESCE(field_data_field_multiple_names.field_multiple_names_middle, ''), ' ', COALESCE(field_data_field_multiple_names.field_multiple_names_family, ''), ' ', COALESCE(field_data_field_multiple_names.field_multiple_names_generational, ''), ' ', COALESCE(field_data_field_multiple_names.field_multiple_names_credentials, ''))) LIKE '% test%') ))

For John Doe, searching Doe, this is: '  john  doe ' LIKE '% doe%' which matches, as would John.

Am I missing something here?

joelpittet’s picture

Thanks for having a look @Alan D. We'll try again without the patch, if it always concatenates all the pieces and whitespace on both ends then there shouldn't be a problem.

joelpittet’s picture

I couldn't reproduce this with the patch removed so I think it has been fixed for us.

alan d.’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Thanks for checking. :)