Results 1 to 8 of 8

Thread: Fix for the Phone Number Search bug

  1. #1
    kbrill's Avatar
    kbrill is offline SugarCRM PS Engineer
    Join Date
    Jul 2004
    Location
    St Louis, MO
    Posts
    3,183

    Talking Fix for the Phone Number Search bug

    This module fixes a LONG standing bug in Sugar that if your users enter a phone number like this "314.968.9800" and you search for it like this "968-9800" you will not find it. This patch makes it so that you can enter phone numbers anyway you want and search for them any way you want. 968-9800 will match 968.9800 or (314)-968-9800 or 968 9800.....

    It also allows for my asterisk phone system to bring up a record by phone number no matter how it is formatted. Asterisk always formats it numbers like 3149689800 which under the old system matched nothing. Now it matches up with (314)-968-9800 or whatever is in the tables....

    It is available here.
    Kenneth Brill - Help Forum Moderator

    I do not respond to 'Private Messages'. Please email me directly instead

    When asking for help, PLEASE give us your Server Information and Version Numbers as asked for on the 'Post New Message' screen as well as any JavaScript errors shown at the bottom of the browser window.
    Help us Help You

  2. #2
    Proware's Avatar
    Proware is offline A Prolific Poster
    Join Date
    Mar 2006
    Location
    Sydney Australia
    Posts
    310

    Default Re: Fix for the Phone Number Search bug

    Wow - this is great!

    Why doesn't Sugar jump on patches like these and incorporate them into their product?
    Cheers

    David Younger
    TSM - The Service Manager
    http://www.theservicemanager.com


    Operating system type and version: Windows 2003 Server
    » Sugar Suite version 4.5.1e Professional
    » Webserver type and version Microsoft-IIS/6.0
    » PHP version 5.2.6
    » MySQL server version 5.0.51a

  3. #3
    Proware's Avatar
    Proware is offline A Prolific Poster
    Join Date
    Mar 2006
    Location
    Sydney Australia
    Posts
    310

    Default Re: Fix for the Phone Number Search bug

    Quote Originally Posted by kbrill
    This module fixes a LONG standing bug in Sugar that if your users enter a phone number like this "314.968.9800" and you search for it like this "968-9800" you will not find it. This patch makes it so that you can enter phone numbers anyway you want and search for them any way you want. 968-9800 will match 968.9800 or (314)-968-9800 or 968 9800.....

    It also allows for my asterisk phone system to bring up a record by phone number no matter how it is formatted. Asterisk always formats it numbers like 3149689800 which under the old system matched nothing. Now it matches up with (314)-968-9800 or whatever is in the tables....

    It is available here.
    Hi Ken,

    The fix works great for the general search but doesnot seem to impact the Contact / Account search. Do you have a patch for these?
    Cheers

    David Younger
    TSM - The Service Manager
    http://www.theservicemanager.com


    Operating system type and version: Windows 2003 Server
    » Sugar Suite version 4.5.1e Professional
    » Webserver type and version Microsoft-IIS/6.0
    » PHP version 5.2.6
    » MySQL server version 5.0.51a

  4. #4
    kbrill's Avatar
    kbrill is offline SugarCRM PS Engineer
    Join Date
    Jul 2004
    Location
    St Louis, MO
    Posts
    3,183

    Exclamation Re: Fix for the Phone Number Search bug

    Quote Originally Posted by Proware
    Hi Ken,

    The fix works great for the general search but doesnot seem to impact the Contact / Account search. Do you have a patch for these?
    I am working on a complete rewrite of all Sugar search routines. Date ranges, phone numbers, soundex, a google like unified search, the whole 9 yards. Not sure I can go all the way back to 4.2.0 though.
    Kenneth Brill - Help Forum Moderator

    I do not respond to 'Private Messages'. Please email me directly instead

    When asking for help, PLEASE give us your Server Information and Version Numbers as asked for on the 'Post New Message' screen as well as any JavaScript errors shown at the bottom of the browser window.
    Help us Help You

  5. #5
    alinoz is offline Junior Member
    Join Date
    Feb 2007
    Posts
    3

    Default Re: Fix for the Phone Number Search bug

    I sugest to search using regular expresions in state of 'LIKE', this is an example of how i'm doing this:

    PHP Code:
    if(strpos($field"phone") === false)
    {
        
    $clause .=  "LIKE '{$_REQUEST['query_string']}%'";
    }
    else
    {
       
    $temp_str $_REQUEST['query_string'];
       
    $temp_str ereg_replace'[^0-9]+'''$temp_str );
       
    $temp_clause '"';
       for(
    $i=0;$i strlen($temp_str)-1$i++)
       {
          
    $temp_clause .= $temp_str[$i] . "[- ./]?";
       }
       
    $temp_clause .= $temp_str[$i];
       
    $temp_clause .= '*"';
       
    $clause .="REGEXP " $temp_clause;

    this will return a more accurate result.
    In the way the search is implemented in your fix if you have this numbers: 314 233 6540 and 314 323 36540 in the database and if you search for 314 233 6540 then the both number will be returned as result.
    Last edited by alinoz; 2007-03-06 at 08:59 AM.

  6. #6
    DJuser is offline Sugar Community Member
    Join Date
    May 2007
    Posts
    16

    Default Re: Fix for the Phone Number Search bug

    this sounds like it'll cause very slow searches?

    Or have I missed something obvious here?

    Running regexp on the phone number for *every* record in the table? Slowwwww.. can't benefit form indexing on the phone field...

    Better would be to have an extra field in the table - to save a 'cleaned-up' version of the Phone number (all non-digits removed).

    Then the searching query would run against that field. (user never sees the new field, it's behind the scenes only)

    eg the table has 2 fields now:
    PhoneNo CleanPhone
    '314 233 6540' '3142336540'
    '314 2336 540' '3142336540'
    '314-233-6540 '3142336540'

    And when the user searches on
    '314-233'
    this would first be cleaned the same way, to
    '314233'
    and then the query would run.

    And like wise the new field is calculated and saved every time the record is created/edited.

    The new field can be indexed and give a *much* faster response than processing phone number in every record...

    Hope I'm not missing something stupid here...

    DJ

  7. #7
    kbrill's Avatar
    kbrill is offline SugarCRM PS Engineer
    Join Date
    Jul 2004
    Location
    St Louis, MO
    Posts
    3,183

    Default Re: Fix for the Phone Number Search bug

    Quote Originally Posted by alinoz
    this will return a more accurate result.
    In the way the search is implemented in your fix if you have this numbers: 314 233 6540 and 314 323 36540 in the database and if you search for 314 233 6540 then the both number will be returned as result.
    Not sure why you would have a number line 314 323 36540 and I would put forward that if you did then you might want to to come up.

    However that said I like your approach very much. It might not be perfect but it gets me thinking.
    Kenneth Brill - Help Forum Moderator

    I do not respond to 'Private Messages'. Please email me directly instead

    When asking for help, PLEASE give us your Server Information and Version Numbers as asked for on the 'Post New Message' screen as well as any JavaScript errors shown at the bottom of the browser window.
    Help us Help You

  8. #8
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: Fix for the Phone Number Search bug

    Ken,

    Another option is to replace every non-digit with a % wildcard and then just do a normal search:

    PHP Code:

    $phone 
    preg_replace('/\d/','%$0',preg_replace('/\D/','',$phone)); 
    Last edited by eggsurplus; 2007-06-27 at 05:46 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •