WebPAC cgi will now set it's own locale (using configuration directive in
[webpac] / index_DBI_filter.pm
index 566ec76..98ce339 100644 (file)
@@ -11,10 +11,9 @@ use strict qw(vars);
 use vars qw($Count);
 use HTML::Entities;
 use URI::Escape;
-use locale;
 use Carp;
-
 use DBI;
+use locale;
 
 # bench time
 my $bench_time = time();
@@ -103,7 +102,7 @@ sub insert {
 
        if (! $self->{c}->{$uc}->{$field}) {
 #print stderr "in index: $index_data\n";
-               $self->{c}->{$uc}->{$field}->{item} = $index_data;
+               $self->{c}->{$uc}->{$field}->{item} = lc($index_data);
                $self->{c}->{$uc}->{$field}->{display} = $display;
        }
 
@@ -121,7 +120,7 @@ sub count {
 
        my $tables_sql = 'data';
        my $where_sql = '';
-       my @sql_args = ( $field, $where );
+       my @sql_args = ( $field, lc($where) );
 
        if ($filter) {
                $tables_sql .= ",filters";
@@ -135,7 +134,7 @@ sub count {
        my $sql = qq{
                select count(*)
                from $tables_sql
-               where name = ? and upper(item) like upper(?)||'%'
+               where name = ? and item like ?||'%'
                $where_sql
        };
 
@@ -181,7 +180,7 @@ sub fetch {
        my $tables_sql = 'data';
        my $where_sql = '';
 
-       my @sql_args = ( $field, $where );
+       my @sql_args = ( $field, lc($where) );
 
        if ($filter) {
                $tables_sql .= ",filters";
@@ -196,29 +195,31 @@ sub fetch {
                my $sql2 = qq{
                        select data.ord as ord
                        from $tables_sql
-                       where name = ? and upper(item) like upper(?)||'%'
+                       where name = ? and item like ?||'%'
                        $where_sql
+                       order by data.ord
                };
                my $sth = $self->{dbh}->prepare($sql2) || confess "sql2: $sql2; ".$self->{dbh}->errstr();
 
                $sth->execute(@sql_args) || confess "sql2: $sql2; ".$self->{dbh}->errstr();
                if (my $row = $sth->fetchrow_hashref) {
-                       $from_ord += $row->{ord} - 1;
+                       $from_ord = $row->{ord} - 1;
                } else {
                        # if no match is found when searching from beginning
                        # of word in index, try substring match anywhere
                        $sql2 = qq{
                                select data.ord as ord
                                from $tables_sql
-                               where name = ? and upper(item) like '% '||upper(?)||'%'
+                               where name = ? and item like '%'||?||'%'
                                $where_sql
+                               order by data.ord
                        };
        
                        $sth = $self->{dbh}->prepare($sql2) || confess "sql2: $sql2; ".$self->{dbh}->errstr();
                        $sth->execute(@sql_args) || confess "sql2: $sql2; ".$self->{dbh}->errstr();
 
                        if (my $row = $sth->fetchrow_hashref) {
-                               $from_ord += $row->{ord} - 1;
+                               $from_ord = $row->{ord} - 1;
                        }
                }
        }