--- trunk/index_DBI_cache.pm 2003/09/04 13:47:36 126 +++ trunk/index_DBI_cache.pm 2003/09/04 14:56:41 127 @@ -138,12 +138,21 @@ my $sql = "select $what,ord from $field"; if ($where) { - my $sql2 = " select ord from $field where upper($what) like upper(?)||'%'"; + my $sql2 = "select ord from $field where upper($what) like upper(?)||'%'"; my $sth = $self->{dbh}->prepare($sql2) || die "sql2: $sql2; ".$self->{dbh}->errstr(); $sth->execute($where) || die "sql2: $sql2; ".$self->{dbh}->errstr(); if (my $row = $sth->fetchrow_hashref) { $from_ord += $row->{ord} - 1; + } else { + # if no match is found when searching from beginning + # of word in index, try substring match anywhere + $sql2 = "select ord from $field where upper($what) like '%'||upper(?)||'%'"; + $sth = $self->{dbh}->prepare($sql2) || die "sql2: $sql2; ".$self->{dbh}->errstr(); + $sth->execute($where) || die "sql2: $sql2; ".$self->{dbh}->errstr(); + if (my $row = $sth->fetchrow_hashref) { + $from_ord += $row->{ord} - 1; + } } } $sql .= " order by ord limit $rows offset $from_ord";