11 |
use vars qw($Count); |
use vars qw($Count); |
12 |
use HTML::Entities; |
use HTML::Entities; |
13 |
use URI::Escape; |
use URI::Escape; |
|
use locale; |
|
14 |
use Carp; |
use Carp; |
|
|
|
15 |
use DBI; |
use DBI; |
16 |
|
use locale; |
17 |
|
|
18 |
# bench time |
# bench time |
19 |
my $bench_time = time(); |
my $bench_time = time(); |
102 |
|
|
103 |
if (! $self->{c}->{$uc}->{$field}) { |
if (! $self->{c}->{$uc}->{$field}) { |
104 |
#print stderr "in index: $index_data\n"; |
#print stderr "in index: $index_data\n"; |
105 |
$self->{c}->{$uc}->{$field}->{item} = $index_data; |
$self->{c}->{$uc}->{$field}->{item} = lc($index_data); |
106 |
$self->{c}->{$uc}->{$field}->{display} = $display; |
$self->{c}->{$uc}->{$field}->{display} = $display; |
107 |
} |
} |
108 |
|
|
120 |
|
|
121 |
my $tables_sql = 'data'; |
my $tables_sql = 'data'; |
122 |
my $where_sql = ''; |
my $where_sql = ''; |
123 |
my @sql_args = ( $field, $where ); |
my @sql_args = ( $field, lc($where) ); |
124 |
|
|
125 |
if ($filter) { |
if ($filter) { |
126 |
$tables_sql .= ",filters"; |
$tables_sql .= ",filters"; |
134 |
my $sql = qq{ |
my $sql = qq{ |
135 |
select count(*) |
select count(*) |
136 |
from $tables_sql |
from $tables_sql |
137 |
where name = ? and upper(item) like upper(?)||'%' |
where name = ? and item like ?||'%' |
138 |
$where_sql |
$where_sql |
139 |
}; |
}; |
140 |
|
|
180 |
my $tables_sql = 'data'; |
my $tables_sql = 'data'; |
181 |
my $where_sql = ''; |
my $where_sql = ''; |
182 |
|
|
183 |
my @sql_args = ( $field, $where ); |
my @sql_args = ( $field, lc($where) ); |
184 |
|
|
185 |
if ($filter) { |
if ($filter) { |
186 |
$tables_sql .= ",filters"; |
$tables_sql .= ",filters"; |
195 |
my $sql2 = qq{ |
my $sql2 = qq{ |
196 |
select data.ord as ord |
select data.ord as ord |
197 |
from $tables_sql |
from $tables_sql |
198 |
where name = ? and upper(item) like upper(?)||'%' |
where name = ? and item like ?||'%' |
199 |
$where_sql |
$where_sql |
200 |
|
order by data.ord |
201 |
}; |
}; |
202 |
my $sth = $self->{dbh}->prepare($sql2) || confess "sql2: $sql2; ".$self->{dbh}->errstr(); |
my $sth = $self->{dbh}->prepare($sql2) || confess "sql2: $sql2; ".$self->{dbh}->errstr(); |
203 |
|
|
204 |
$sth->execute(@sql_args) || confess "sql2: $sql2; ".$self->{dbh}->errstr(); |
$sth->execute(@sql_args) || confess "sql2: $sql2; ".$self->{dbh}->errstr(); |
205 |
if (my $row = $sth->fetchrow_hashref) { |
if (my $row = $sth->fetchrow_hashref) { |
206 |
$from_ord += $row->{ord} - 1; |
$from_ord = $row->{ord} - 1; |
207 |
} else { |
} else { |
208 |
# if no match is found when searching from beginning |
# if no match is found when searching from beginning |
209 |
# of word in index, try substring match anywhere |
# of word in index, try substring match anywhere |
210 |
$sql2 = qq{ |
$sql2 = qq{ |
211 |
select data.ord as ord |
select data.ord as ord |
212 |
from $tables_sql |
from $tables_sql |
213 |
where name = ? and upper(item) like '% '||upper(?)||'%' |
where name = ? and item like '%'||?||'%' |
214 |
$where_sql |
$where_sql |
215 |
|
order by data.ord |
216 |
}; |
}; |
217 |
|
|
218 |
$sth = $self->{dbh}->prepare($sql2) || confess "sql2: $sql2; ".$self->{dbh}->errstr(); |
$sth = $self->{dbh}->prepare($sql2) || confess "sql2: $sql2; ".$self->{dbh}->errstr(); |
219 |
$sth->execute(@sql_args) || confess "sql2: $sql2; ".$self->{dbh}->errstr(); |
$sth->execute(@sql_args) || confess "sql2: $sql2; ".$self->{dbh}->errstr(); |
220 |
|
|
221 |
if (my $row = $sth->fetchrow_hashref) { |
if (my $row = $sth->fetchrow_hashref) { |
222 |
$from_ord += $row->{ord} - 1; |
$from_ord = $row->{ord} - 1; |
223 |
} |
} |
224 |
} |
} |
225 |
} |
} |