From 903b22b3da3e3ee493bb322854c6bc0b0085e0dd Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 23 Feb 2002 11:56:55 +0000 Subject: [PATCH] case-insensitive and substring searching --- CREDITS | 2 +- FS/FS/Record.pm | 12 ++++++-- httemplate/docs/index.html | 1 - httemplate/search/cust_main.cgi | 63 ++++++++++++++++++++++++++++------------ httemplate/search/cust_main.html | 10 +++++-- 5 files changed, 64 insertions(+), 24 deletions(-) diff --git a/CREDITS b/CREDITS index 2fd407853..f3396284a 100644 --- a/CREDITS +++ b/CREDITS @@ -59,7 +59,7 @@ export, cancel-unaudited.cgi), patches to support billing date modification, and probably other things too (sorry if I forgot them). And yet even more bug squashing, thanks! *and* he single-handedly implemented all the necessary work to get rid of svc_acct_sm and the "default domain" thanks!! and rewrote -the financials! wow, thanks jeff! +the financials! wow, thanks jeff! and contributed financial reports! Kenny Elliott contributed ICRADIUS radreply table support, allowing attributes with ICRADIUS, helped fix many bugs, and some diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 020d14d8f..f30223351 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -180,7 +180,7 @@ sub create { } } -=item qsearch TABLE, HASHREF, SELECT, EXTRA_SQL +=item qsearch TABLE, HASHREF, SELECT, EXTRA_SQL, CACHE_OBJ Searches the database for all records matching (at least) the key/value pairs in HASHREF. Returns all the records found as `FS::TABLE' objects if that @@ -214,6 +214,14 @@ sub qsearch { my $statement = "SELECT $select FROM $stable"; if ( @fields ) { $statement .= ' WHERE '. join(' AND ', map { + + my $op = '='; + if ( ref($record->{$_}) ) { + $op = $record->{$_}{'op'} if $record->{$_}{'op'}; + $op = 'LIKE' if $op =~ /^ILIKE$/i && driver_name !~ /^Pg$/i; + $record->{$_} = $record->{$_}{'value'} + } + if ( ! defined( $record->{$_} ) || $record->{$_} eq '' ) { if ( driver_name =~ /^Pg$/i ) { qq-( $_ IS NULL OR $_ = '' )-; @@ -221,7 +229,7 @@ sub qsearch { qq-( $_ IS NULL OR $_ = "" )-; } } else { - "$_ = ?"; + "$_ $op ?"; } } @fields ); } diff --git a/httemplate/docs/index.html b/httemplate/docs/index.html index 9e61d4f08..00c863b0c 100644 --- a/httemplate/docs/index.html +++ b/httemplate/docs/index.html @@ -24,7 +24,6 @@
  • Signup server
  • Session monitor
  • Billing -
  • Troubleshooting
  • Schema reference
  • Perl API diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi index 1e28ad57d..f153f02d4 100755 --- a/httemplate/search/cust_main.cgi +++ b/httemplate/search/cust_main.cgi @@ -398,24 +398,37 @@ sub lastsearch { or eidiot "Illegal last name"; my($last)=$1; -# if ( $last_type{'Exact'} -# && ! $last_type{'Fuzzy'} -# # && ! $last_type{'Sound-alike'} -# ) { + if ( $last_type{'Exact'} || $last_type{'Fuzzy'} ) { + push @cust_main, qsearch( 'cust_main', + { 'last' => { 'op' => 'ILIKE', + 'value' => $last } } ); + + push @cust_main, qsearch( 'cust_main', + { 'ship_last' => { 'op' => 'ILIKE', + 'value' => $last } } ) + if defined dbdef->table('cust_main')->column('ship_last'); + } + + if ( $last_type{'Substring'} || $last_type{'All'} ) { - push @cust_main, qsearch('cust_main',{'last'=>$last}); + push @cust_main, qsearch( 'cust_main', + { 'last' => { 'op' => 'ILIKE', + 'value' => "%$last%" } } ); - push @cust_main, qsearch('cust_main',{'ship_last'=>$last}) + push @cust_main, qsearch( 'cust_main', + { 'ship_last' => { 'op' => 'ILIKE', + 'value' => "%$last%" } } ) if defined dbdef->table('cust_main')->column('ship_last'); -# } else { - if ( $last_type{'Fuzzy'} ) { + } + + if ( $last_type{'Fuzzy'} || $last_type{'All'} ) { &FS::cust_main::check_and_rebuild_fuzzyfiles; my $all_last = &FS::cust_main::all_last; my %last; - if ($last_type{'Fuzzy'}) { + if ( $last_type{'Fuzzy'} || $last_type{'All'} ) { foreach ( amatch($last, [ qw(i) ], @$all_last) ) { $last{$_}++; } @@ -431,6 +444,7 @@ sub lastsearch { } } + \@cust_main; } @@ -446,24 +460,37 @@ sub companysearch { or eidiot "Illegal company"; my($company)=$1; -# if ( $company_type{'Exact'} -# && ! $company_type{'Fuzzy'} -# # && ! $company_type{'Sound-alike'} -# ) { + if ( $company_type{'Exact'} || $company_type{'Fuzzy'} ) { + push @cust_main, qsearch( 'cust_main', + { 'company' => { 'op' => 'ILIKE', + 'value' => $company } } ); - push @cust_main, qsearch('cust_main',{'company'=>$company}); + push @cust_main, qsearch( 'cust_main', + { 'ship_company' => { 'op' => 'ILIKE', + 'value' => $company } } ) + if defined dbdef->table('cust_main')->column('ship_last'); + } + + if ( $company_type{'Substring'} || $company_type{'All'} ) { - push @cust_main, qsearch('cust_main',{'ship_company'=>$company}) + push @cust_main, qsearch( 'cust_main', + { 'company' => { 'op' => 'ILIKE', + 'value' => "%$company%" } } ); + + push @cust_main, qsearch( 'cust_main', + { 'ship_company' => { 'op' => 'ILIKE', + 'value' => "%$company%" } }) if defined dbdef->table('cust_main')->column('ship_last'); -# } else { - if ( $company_type{'Fuzzy'} ) { + } + + if ( $company_type{'Fuzzy'} || $company_type{'All'} ) { &FS::cust_main::check_and_rebuild_fuzzyfiles; my $all_company = &FS::cust_main::all_company; my %company; - if ($company_type{'Fuzzy'}) { + if ( $company_type{'Fuzzy'} || $company_type{'All'} ) { foreach ( amatch($company, [ qw(i) ], @$all_company ) ) { $company{$_}++; } diff --git a/httemplate/search/cust_main.html b/httemplate/search/cust_main.html index 1e91adee9..5a066e453 100755 --- a/httemplate/search/cust_main.html +++ b/httemplate/search/cust_main.html @@ -11,14 +11,18 @@ Search for last name: using search method:

    Search for company: using search methods: @@ -28,7 +32,9 @@


    Explanation of search methods:
      +
    • All - Try all search methods.
    • Fuzzy - Searches for matches that are close to your text. +
    • Substring - Searches for matches that contain your text.
    • Exact - Finds exact matches only, but much faster than the other search methods.
    -- 2.11.0