__PACKAGE__->set_sql( 'OILSFastOrderedSearchLike', <<" SQL", 'Main');
SELECT %s
FROM %s
- WHERE %s ~ ?
+ WHERE %s LIKE ?
ORDER BY %s
SQL
my $fm_class = 'Fieldmapper::'.$class;
my @fms;
$log->debug("fast_fieldmapper() ==> Retrieving $fm_class", INTERNAL);
- for my $hash ($self->fast_flesh_sth( $col, "$id", { order_by => $col }, $like )->fetchall_hash) {
- my $fm = $fm_class->new;
- for my $field ( $fm_class->real_fields ) {
- $fm->$field( $$hash{$field} );
+ if ($like < 2) {
+ for my $hash ($self->fast_flesh_sth( $col, "$id", { order_by => $col }, $like )->fetchall_hash) {
+ my $fm = $fm_class->new;
+ for my $field ( $fm_class->real_fields ) {
+ $fm->$field( $$hash{$field} );
+ }
+ push @fms, $fm;
+ }
+ } else {
+ my $search_type = 'search';
+ if ($like == 2) {
+ $search_type = 'search_fts'
+ } elsif ($like == 3) {
+ $search_type = 'search_regex'
+ }
+
+ for my $obj ($cdbi->$search_type({ $col => $id})) {
+ push @fms, $obj->to_fieldmapper;
}
- push @fms, $fm;
}
return @fms;
}
my $cdbi = $self->{cdbi};
- $log->debug("Searching $cdbi for { ".join(',', map { "$_ => $$searches{$_}" } keys %$searches).' }',DEBUG);
+ (my $search_type = $self->api_name) =~ s/.*\.(search[^.]*).*/$1/o;
+
+ $log->debug("Searching $cdbi for { ".
+ join(',', map { "$_ => $$searches{$_}" } keys %$searches).
+ " } using $search_type",DEBUG);
- for my $obj ($cdbi->search($searches)) {
+ for my $obj ($cdbi->$search_type($searches)) {
$client->respond( $obj->to_fieldmapper );
}
return undef;
my $like = 0;
$like = 1 if ($search_type =~ /like$/o);
+ $like = 2 if ($search_type =~ /fts$/o);
+ $like = 3 if ($search_type =~ /regex$/o);
for my $term (@terms) {
$log->debug("Searching $cdbi for $col using type $search_type, value '$term'",DEBUG);
my $registration_class = __PACKAGE__ . "::$class";
my $api_prefix = 'open-ils.storage.direct.'.$api_class;
- # Create the search method
+ # Create the search methods
unless ( __PACKAGE__->is_registered( $api_prefix.'.search' ) ) {
__PACKAGE__->register_method(
api_name => $api_prefix.'.search',
);
}
+ unless ( __PACKAGE__->is_registered( $api_prefix.'.search_like' ) ) {
+ __PACKAGE__->register_method(
+ api_name => $api_prefix.'.search_like',
+ method => 'search',
+ api_level => 1,
+ stream => 1,
+ cdbi => $cdbi,
+ cachable => 1,
+ );
+ }
+
+ if (\&Class::DBI::search_fts) {
+ unless ( __PACKAGE__->is_registered( $api_prefix.'.search_fts' ) ) {
+ __PACKAGE__->register_method(
+ api_name => $api_prefix.'.search_fts',
+ method => 'search',
+ api_level => 1,
+ stream => 1,
+ cdbi => $cdbi,
+ cachable => 1,
+ );
+ }
+ }
+
+ if (\&Class::DBI::search_regex) {
+ unless ( __PACKAGE__->is_registered( $api_prefix.'.search_regex' ) ) {
+ __PACKAGE__->register_method(
+ api_name => $api_prefix.'.search_regex',
+ method => 'search',
+ api_level => 1,
+ stream => 1,
+ cdbi => $cdbi,
+ cachable => 1,
+ );
+ }
+ }
+
# Create the retrieve method
unless ( __PACKAGE__->is_registered( $api_prefix.'.retrieve' ) ) {
__PACKAGE__->register_method(
cachable => 1,
);
}
+ if (\&Class::DBI::search_fts) {
+ unless ( __PACKAGE__->is_registered( $api_prefix.'.search_fts.'.$field ) ) {
+ __PACKAGE__->register_method(
+ api_name => $api_prefix.'.search_fts.'.$field,
+ method => 'search_one_field',
+ api_level => 1,
+ cdbi => $cdbi,
+ cachable => 1,
+ );
+ }
+ }
+ if (\&Class::DBI::search_regex) {
+ unless ( __PACKAGE__->is_registered( $api_prefix.'.search_regex.'.$field ) ) {
+ __PACKAGE__->register_method(
+ api_name => $api_prefix.'.search_regex.'.$field,
+ method => 'search_one_field',
+ api_level => 1,
+ cdbi => $cdbi,
+ cachable => 1,
+ );
+ }
+ }
}