From 7da698a3847756c0286784d5d5c38ff22ca9c2fc Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 16 Dec 2005 16:07:34 +0000 Subject: [PATCH] allowing "limit" (and "offset") to be passed into authority marc search and ordering them by rank git-svn-id: svn://svn.open-ils.org/ILS/trunk@2420 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../Storage/Publisher/authority.pm | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm index 2c38361e24..e2b9db8e93 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm @@ -24,6 +24,20 @@ sub find_authority_marc { my $term = $args{term}; my $tag = $args{tag}; my $subfield = $args{subfield}; + my $limit = $args{limit} || 100; + my $offset = $args{offset} || 0; + + if ($limit) { + $limit = "LIMIT $limit"; + } else { + $limit = ''; + } + + if ($offset) { + $offset = "OFFSET $offset"; + } else { + $offset = ''; + } my $tag_where = "AND f.tag LIKE '$tag'"; if (ref $tag) { @@ -43,13 +57,15 @@ sub find_authority_marc { my $fts = OpenILS::Application::Storage::FTS->compile($term, 'f.value', "f.$index_col"); + my $fts_where = $fts->sql_where_clause; my $fts_words = join '%', $fts->words; my $fts_words_where = "f.value LIKE '$fts_words\%'"; + my $fts_rank = join '+', $fts->fts_rank; my $select = <<" SQL"; - SELECT DISTINCT a.marc + SELECT a.marc, sum($fts_rank) FROM $search_table f, $marc_table a WHERE $fts_where @@ -57,6 +73,11 @@ sub find_authority_marc { $tag_where $sf_where AND a.id = f.record + GROUP BY 1 + ORDER BY 2 + $limit + $offset + SQL $log->debug("Authority Search SQL :: [$select]",DEBUG); @@ -102,13 +123,15 @@ sub find_see_from_controlled { my $self = shift; my $client = shift; my $term = shift; + my $limit = shift; + my $offset = shift; (my $class = $self->api_name) =~ s/^.+authority.([^\.]+)\.see.+$/$1/o; my $sf = 'a'; $sf = 't' if ($class eq 'title'); my @marc = $self->method_lookup('open-ils.storage.authority.search.marc') - ->run( term => $term, tag => '4%', subfield => $sf ); + ->run( term => $term, tag => '4%', subfield => $sf, limit => $limit, offset => $offset ); for my $m ( @marc ) { my $doc = $parser->parse_string($m); my @nodes = $doc->documentElement->findnodes('//*[substring(@tag,1,1)="1"]/*[@code="a" or @code="d" or @code="x"]'); @@ -131,13 +154,15 @@ sub find_see_also_from_controlled { my $self = shift; my $client = shift; my $term = shift; + my $limit = shift; + my $offset = shift; (my $class = $self->api_name) =~ s/^.+authority.([^\.]+)\.see.+$/$1/o; my $sf = 'a'; $sf = 't' if ($class eq 'title'); my @marc = $self->method_lookup('open-ils.storage.authority.search.marc') - ->run( term => $term, tag => '5%', subfield => $sf ); + ->run( term => $term, tag => '5%', subfield => $sf, limit => $limit, offset => $offset ); for my $m ( @marc ) { my $doc = $parser->parse_string($m); my @nodes = $doc->documentElement->findnodes('//*[substring(@tag,1,1)="1"]/*[@code="a" or @code="d" or @code="x"]'); -- 2.43.2