adding search_fts and search_regex
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 1 Jul 2005 15:28:45 +0000 (15:28 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 1 Jul 2005 15:28:45 +0000 (15:28 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1021 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/cdbi.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm

index ab24c70..5345c2f 100644 (file)
@@ -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;
 }
index 1eb7fca..7cc0ba1 100644 (file)
                }
                $self->_do_search("@@"  => @args);
        }
+
+       sub search_regex {
+               my $self = shift;
+               my @args = @_;
+               $self->_do_search("~*"  => @args);
+       }
+
 }
 
 1;
index 39faec1..89bd0a2 100644 (file)
@@ -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,
+                               );
+                       }
+               }
        }