Download & Extend

Advanced text comparison

Project:Finder
Version:7.x-2.x-dev
Component:Miscellaneous
Category:task
Priority:normal
Assigned:Unassigned
Status:postponed

Issue Summary

A few issues have popped up regarding matching strings with various advanced functionality. I believe a solution should be found that would work for all these cases. My expectation is to find some way to allow users to assign database functions to the matching process, and perhaps some sort of ranking system for results.

#850896: Diacritics not ingoren in Finder Views + Autocomplete
#723978: Ignore punctuation in node titles
#994412: Autocomplete transform special characters to simple letters

Comments

#1

Status:active» postponed

#2

A possible solution for accents/diacritics/especial characters (it works for me but it needs work to be a real patch). I discovered that results where found by finder_find() but later eliminated by finder_find_choices() .

in finder.module add a funtion to replace especial chars with the normal ones:

function normalize ($string){
    $a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿŔŕ';
    $b = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr';
    $string = utf8_decode($string);   
    $string = strtr($string, utf8_decode($a), $b);
    $string = strtolower($string);
    return utf8_encode($string);
}

It's easy to add as many chars as needed.

After this, go to this code in finder.module

        if (strpos($expression, 'LIKE') !== FALSE) {
              $expression = str_replace(' LIKE ', '', $expression);
              // Added strtolower() because some people were reporting
              // case-sensitivity even with the i modifier.
              $like_matches = preg_grep(
                "/^"
                . str_replace(
                    '%', '(.*?)',
                    preg_quote(strtolower($expression))
                  )
                ."$/si",
                array(strtolower($option->$field_name))
              );
              if (!empty($like_matches)) {
                $matching_names[] = $field_name;
              }
            }

And replace strtolower calls with normalize

        if (strpos($expression, 'LIKE') !== FALSE) {
              $expression = str_replace(' LIKE ', '', $expression);
              // Added strtolower() because some people were reporting
              // case-sensitivity even with the i modifier.
              $like_matches = preg_grep(
                "/^"
                . str_replace(
                    '%', '(.*?)',
                    preg_quote(normalize($expression))
                  )
                ."$/si",
                array(normalize($option->$field_name))
              );
              if (!empty($like_matches)) {
                $matching_names[] = $field_name;
              }
            }

With this code, autocomplete textfield finds nodes with CCK fields containing text as query with diferences of accents. For example it will find "Alta tensión" node with query "tension". For Spanish people (my case) this is a useful behaviour. Maybe it could be useful to add a configuration option on module.

Hope this helps.

Jordi

#3

Version:6.x-1.x-dev» 7.x-2.x-dev

#4

Some of this stuff can be done through 'custom matching' which has been added since this issue was created. The exact specifics of that still need to be considered.

#5

I think the custom matching needs to be changed to allow controlling the whole matching string, rather than parts. This would require changing how matching is used as well.

nobody click here