From 8863872d69354d25086b10d6eaf4bb3619d5c710 Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 1 Jul 2005 15:28:45 +0000 Subject: [PATCH] adding search_fts and search_regex git-svn-id: svn://svn.open-ils.org/ILS/trunk@1021 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Storage/CDBI.pm | 25 +++++-- .../Application/Storage/Driver/Pg/cdbi.pm | 7 ++ .../OpenILS/Application/Storage/Publisher.pm | 71 ++++++++++++++++++- 3 files changed, 94 insertions(+), 9 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm index ab24c701b4..5345c2f613 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm @@ -30,7 +30,7 @@ sub child_init { __PACKAGE__->set_sql( 'OILSFastOrderedSearchLike', <<" SQL", 'Main'); SELECT %s FROM %s - WHERE %s ~ ? + WHERE %s LIKE ? ORDER BY %s SQL @@ -105,12 +105,25 @@ sub fast_fieldmapper { 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; } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/cdbi.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/cdbi.pm index 1eb7fcab67..7cc0ba19a6 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/cdbi.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/cdbi.pm @@ -14,6 +14,13 @@ } $self->_do_search("@@" => @args); } + + sub search_regex { + my $self = shift; + my @args = @_; + $self->_do_search("~*" => @args); + } + } 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm index 39faec1f7d..89bd0a296e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm @@ -132,9 +132,13 @@ sub search { 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; @@ -151,6 +155,8 @@ sub search_one_field { 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); @@ -296,7 +302,7 @@ for my $fmclass ( (Fieldmapper->classes) ) { 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', @@ -308,6 +314,43 @@ for my $fmclass ( (Fieldmapper->classes) ) { ); } + 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( @@ -350,6 +393,28 @@ for my $fmclass ( (Fieldmapper->classes) ) { 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, + ); + } + } } -- 2.43.2