Remove code to return abstract with search, add separate storage method...
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 29 Dec 2011 17:01:27 +0000 (12:01 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 29 Dec 2011 17:04:04 +0000 (12:04 -0500)
...to convert search query string to abstract.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm

index 0d8e84f..d5ede0c 100644 (file)
@@ -772,8 +772,7 @@ __PACKAGE__->register_method(
         params => [
             {name => 'arghash', desc => 'Arg hash (see open-ils.search.biblio.multiclass)',         type => 'object'},
             {name => 'query',   desc => 'Raw human-readable query (see perldoc '. __PACKAGE__ .')', type => 'string'},
-            {name => 'docache', desc => 'Flag for caching (see open-ils.search.biblio.multiclass)', type => 'bool'},
-            {name => 'return_abstract', desc => "A flag to enable/disable returning an abstract represenation of the query itself, in addition to the result set (default OFF)", type => 'bool'}
+            {name => 'docache', desc => 'Flag for caching (see open-ils.search.biblio.multiclass)', type => 'bool'}
         ],
         return => {
             desc => 'Search results from query, like: { "count" : $count, "ids" : [ [ $id, $relevancy, $total ], ...] }',
@@ -784,7 +783,7 @@ __PACKAGE__->register_method(
 }
 
 sub multiclass_query {
-    my($self, $conn, $arghash, $query, $docache, $return_abstract) = @_;
+    my($self, $conn, $arghash, $query, $docache) = @_;
 
     $logger->debug("initial search query => $query");
     my $orig_query = $query;
@@ -900,7 +899,7 @@ sub multiclass_query {
     #    unless $arghash->{preferred_language};
 
        $method = $self->method_lookup($method);
-    my ($data) = $method->run($arghash, $docache, $return_abstract);
+    my ($data) = $method->run($arghash, $docache);
 
     $arghash->{searches} = $search if (!$data->{complex_query});
 
@@ -1167,10 +1166,6 @@ __PACKAGE__->register_method(
             {
                 desc => "A flag to enable/disable searching and saving results in cache, including facets (default OFF)",
                 type => 'bool'
-            },
-            {
-                desc => "A flag to enable/disable returning an abstract represenation of the query itself, in addition to the result set (default OFF)",
-                type => 'bool'
             }
         ],
         return => {
@@ -1197,7 +1192,7 @@ __PACKAGE__->register_method(
 );
 
 sub staged_search {
-       my($self, $conn, $search_hash, $docache, $return_abstract) = @_;
+       my($self, $conn, $search_hash, $docache) = @_;
 
     my $IAmMetabib = ($self->api_name =~ /metabib/) ? 1 : 0;
 
@@ -1250,7 +1245,6 @@ sub staged_search {
     my $page; # current superpage
     my $est_hit_count = 0;
     my $current_page_summary = {};
-    my $current_abstract = {};
     my $global_summary = {checked => 0, visible => 0, excluded => 0, deleted => 0, total => 0};
     my $is_real_hit_count = 0;
     my $new_ids = [];
@@ -1259,7 +1253,7 @@ sub staged_search {
 
         my $data = $cache_data->{$page};
         my $results;
-        my ($summary, $abstract);
+        my $summary;
 
         $logger->debug("staged search: analyzing superpage $page");
 
@@ -1268,14 +1262,12 @@ sub staged_search {
             $logger->debug("staged search: found cached results");
             $summary = $data->{summary};
             $results = $data->{results};
-            $abstract = pop @$results;
         } else {
             # retrieve the window of results from the database
             $logger->debug("staged search: fetching results from the database");
             $search_hash->{skip_check} = $page * $superpage_size;
             my $start = time;
             $results = $U->storagereq($method, %$search_hash);
-            $abstract = pop @$results;
             $search_duration = time - $start;
             $logger->info("staged search: DB call took $search_duration seconds and returned ".scalar(@$results)." rows, including summary");
             $summary = shift(@$results) if $results;
@@ -1308,7 +1300,6 @@ sub staged_search {
             if $search_hash->{tag_circulated_records} and $search_hash->{authtoken};
 
         $current_page_summary = $summary;
-        $current_abstract = $abstract;
 
         # add the new set of results to the set under construction
         push(@$all_results, @$results);
@@ -1370,8 +1361,7 @@ sub staged_search {
             superpage_size    => $search_hash->{check_limit},
             superpage_summary => $current_page_summary,
             facet_key         => $facet_key,
-            ids               => \@results,
-            ($return_abstract ? (abstract_query => $current_abstract) : ())
+            ids               => \@results
         }
     );
 
index c158c6c..03fdbca 100644 (file)
@@ -16,6 +16,49 @@ my $log = 'OpenSRF::Utils::Logger';
 
 $VERSION = 1;
 
+sub _initialize_parser {
+    my ($parser) = @_;
+
+    my $cstore = OpenSRF::AppSession->create( 'open-ils.cstore' );
+    $parser->initialize(
+        config_record_attr_index_norm_map =>
+            $cstore->request(
+                'open-ils.cstore.direct.config.record_attr_index_norm_map.search.atomic',
+                { id => { "!=" => undef } },
+                { flesh => 1, flesh_fields => { crainm => [qw/norm/] }, order_by => [{ class => "crainm", field => "pos" }] }
+            )->gather(1),
+        search_relevance_adjustment         =>
+            $cstore->request(
+                'open-ils.cstore.direct.search.relevance_adjustment.search.atomic',
+                { id => { "!=" => undef } }
+            )->gather(1),
+        config_metabib_field                =>
+            $cstore->request(
+                'open-ils.cstore.direct.config.metabib_field.search.atomic',
+                { id => { "!=" => undef } }
+            )->gather(1),
+        config_metabib_search_alias         =>
+            $cstore->request(
+                'open-ils.cstore.direct.config.metabib_search_alias.search.atomic',
+                { alias => { "!=" => undef } }
+            )->gather(1),
+        config_metabib_field_index_norm_map =>
+            $cstore->request(
+                'open-ils.cstore.direct.config.metabib_field_index_norm_map.search.atomic',
+                { id => { "!=" => undef } },
+                { flesh => 1, flesh_fields => { cmfinm => [qw/norm/] }, order_by => [{ class => "cmfinm", field => "pos" }] }
+            )->gather(1),
+        config_record_attr_definition       =>
+            $cstore->request(
+                'open-ils.cstore.direct.config.record_attr_definition.search.atomic',
+                { name => { "!=" => undef } }
+            )->gather(1),
+    );
+
+    $cstore->disconnect;
+    die("Cannot initialize $parser!") unless ($parser->initialization_complete);
+}
+
 sub ordered_records_from_metarecord {
        my $self = shift;
        my $client = shift;
@@ -2801,43 +2844,45 @@ flag set to true./,
     }
 );
 
-## XXX The following str2abstract_query stuff doesn't work, but do we need it
-## to? Is this the right place for it? for now, you *can* get an abstract query
-## back as part of the result if you call
-## open-ils.search.biblio.multiclass.query with appropriate args.
-## I suspect all we need to do (other than uncommenting the use statement
-## near the top) is OpenILS::...::QueryParser->TEST_SETUP;, but I'm not sure
-## that actually makes sense within the storage app.
-#
-#sub str2abstract_query {
-#    my ($self, $conn, $query, $opts) = @_;
-#
-#    my %use_opts = ( # reasonable defaults? should these even be hardcoded here?
-#        superpage => 1,
-#        superpage_size => 1000,
-#        core_limit => 25000,
-#        query => $query,
-#        (ref $opts eq 'HASH' ? %$opts : ())
-#    );
-#
-#    my $plan = new
-#        OpenILS::Application::Storage::Driver::Pg::QueryParser(%use_opts);
-#
-#    return $plan->parse_tree->to_abstract_query;
-#}
-#
-#__PACKAGE__->register_method(
-#      api_name        => "open-ils.storage.query_parser.abstract_query.from_string",
-#      method          => "str2abstract_query",
-#      api_level       => 1,
-#    signature   => {
-#        params  => [
-#            {desc => "Query", type => "string"},
-#            {desc => "arguments to QueryParser constructor (optional)", type => "object"}
-#        ],
-#        return => { type => "object", desc => "abstract representation of query parser query" }
-#    }
-#);
+sub str2abstract_query {
+    my ($self, $conn, $query, $qp_opts, $with_config) = @_;
+
+    my %use_opts = ( # reasonable defaults? should these even be hardcoded here?
+        superpage => 1,
+        superpage_size => 1000,
+        core_limit => 25000,
+        query => $query,
+        (ref $opts eq 'HASH' ? %$opts : ())
+    );
+
+    $with_config ||= 0;
+
+    # grab the query parser and initialize it
+    my $parser = $OpenILS::Application::Storage::QParser;
+    $parser->use;
+
+    _initialize_parser($parser) unless $parser->initialization_complete;
+
+    my $query = $parser->new(%use_opts)->parse;
+
+    return $query->parse_tree->to_abstract_query(with_config => $with_config);
+}
+
+__PACKAGE__->register_method(
+       api_name        => "open-ils.storage.query_parser.abstract_query.from_string",
+       method          => "str2abstract_query",
+       api_level       => 1,
+    signature   => {
+        params  => [
+            {desc => "Query", type => "string"},
+            {desc => q/Arguments for initializing QueryParser (optional)/,
+                type => "object"},
+            {desc => q/Flag enabling inclusion of QP config in returned object (optional, default false)/,
+                type => "bool"}
+        ],
+        return => { type => "object", desc => "abstract representation of query parser query" }
+    }
+);
 
 sub query_parser_fts {
     my $self = shift;
@@ -2849,47 +2894,7 @@ sub query_parser_fts {
     my $parser = $OpenILS::Application::Storage::QParser;
     $parser->use;
 
-    if (!$parser->initialization_complete) {
-        my $cstore = OpenSRF::AppSession->create( 'open-ils.cstore' );
-        $parser->initialize(
-            config_record_attr_index_norm_map =>
-                $cstore->request(
-                    'open-ils.cstore.direct.config.record_attr_index_norm_map.search.atomic',
-                    { id => { "!=" => undef } },
-                    { flesh => 1, flesh_fields => { crainm => [qw/norm/] }, order_by => [{ class => "crainm", field => "pos" }] }
-                )->gather(1),
-            search_relevance_adjustment         =>
-                $cstore->request(
-                    'open-ils.cstore.direct.search.relevance_adjustment.search.atomic',
-                    { id => { "!=" => undef } }
-                )->gather(1),
-            config_metabib_field                =>
-                $cstore->request(
-                    'open-ils.cstore.direct.config.metabib_field.search.atomic',
-                    { id => { "!=" => undef } }
-                )->gather(1),
-            config_metabib_search_alias         =>
-                $cstore->request(
-                    'open-ils.cstore.direct.config.metabib_search_alias.search.atomic',
-                    { alias => { "!=" => undef } }
-                )->gather(1),
-            config_metabib_field_index_norm_map =>
-                $cstore->request(
-                    'open-ils.cstore.direct.config.metabib_field_index_norm_map.search.atomic',
-                    { id => { "!=" => undef } },
-                    { flesh => 1, flesh_fields => { cmfinm => [qw/norm/] }, order_by => [{ class => "cmfinm", field => "pos" }] }
-                )->gather(1),
-            config_record_attr_definition       =>
-                $cstore->request(
-                    'open-ils.cstore.direct.config.record_attr_definition.search.atomic',
-                    { name => { "!=" => undef } }
-                )->gather(1),
-        );
-
-        $cstore->disconnect;
-        die("Cannot initialize $parser!") unless ($parser->initialization_complete);
-    }
-
+    _initialize_parser($parser) unless $parser->initialization_complete;
 
     # populate the locale/language map
     if (!$locale_map{COMPLETE}) {
@@ -3133,7 +3138,6 @@ sub query_parser_fts {
 
                $client->respond( $rec );
        }
-       $client->respond($query->parse_tree->to_abstract_query(with_config => 1));
        return undef;
 }
 __PACKAGE__->register_method(