From c0ce43cd1551aaf78b6e7c0a07d55cb22fe3b793 Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 10 Nov 2005 17:31:45 +0000 Subject: [PATCH] adding authority see-also and see-from lookup support git-svn-id: svn://svn.open-ils.org/ILS/trunk@1995 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Storage/FTS.pm | 2 +- .../OpenILS/Application/Storage/Publisher.pm | 1 + .../Storage/Publisher/authority.pm | 141 ++++++++++++++++++ 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/FTS.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/FTS.pm index 7f32cf3769..1081203e14 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/FTS.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/FTS.pm @@ -119,7 +119,7 @@ sub sql_exact_phrase_match { for my $phrase ( $self->phrases ) { $phrase =~ s/%/\\%/go; $phrase =~ s/_/\\_/go; - $phrase =~ s/'/\\_/go; + $phrase =~ s/'/\\'/go; $log->debug("Adding phrase [$phrase] to the match list", DEBUG); $output .= " AND $column ILIKE '\%$phrase\%'"; } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm index 691ff9de7a..e5a05f5d44 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm @@ -345,6 +345,7 @@ use OpenILS::Application::Storage::Publisher::asset; use OpenILS::Application::Storage::Publisher::biblio; use OpenILS::Application::Storage::Publisher::config; use OpenILS::Application::Storage::Publisher::metabib; +use OpenILS::Application::Storage::Publisher::authority; use OpenILS::Application::Storage::Publisher::money; use OpenILS::Application::Storage::Publisher::permission; '; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm new file mode 100644 index 0000000000..08351c61fb --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm @@ -0,0 +1,141 @@ +package OpenILS::Application::Storage::Publisher::authority; +use base qw/OpenILS::Application::Storage::Publisher/; +use vars qw/$VERSION/; +use OpenSRF::EX qw/:try/; +use OpenILS::Application::Storage::FTS; +use OpenILS::Utils::Fieldmapper; +use OpenSRF::Utils::Logger qw/:level/; +use OpenSRF::Utils::Cache; +use Data::Dumper; +use Digest::MD5 qw/md5_hex/; +use XML::LibXML; + +my $log = 'OpenSRF::Utils::Logger'; + +$VERSION = 1; + +my $parser = XML::LibXML->new; + +sub find_authority_marc { + my $self = shift; + my $client = shift; + my %args = @_; + + my $term = $args{term}; + my $tag = $args{tag}; + my $subfield = $args{subfield}; + + my $tag_where = "AND f.tag LIKE '$tag'"; + my $sf_where = "AND f.subfield = '$subfield'"; + + my $search_table = authority::full_rec->table; + my $marc_table = authority::record_entry->table; + + my ($index_col) = authority::full_rec->columns('FTS'); + $index_col ||= 'value'; + + my $fts = OpenILS::Application::Storage::FTS->compile($term, 'f.value', "f.$index_col"); + + my $fts_where = $fts->sql_where_clause; + my $fts_words = join '%', map { s/([\%\_'])/\\$1/go; }$fts->words; + my $fts_words_where = "f.value LIKE '$fts_words\%'"; + + + my $select = <<" SQL"; + SELECT DISTINCT a.marc + FROM $search_table f, + $marc_table a + WHERE $fts_where + AND $fts_words_where + $tag_where + $sf_where + AND a.id = f.record + SQL + + $log->debug("Authority Search SQL :: [$select]",DEBUG); + + my $recs = authority::full_rec->db_Main->selectcol_arrayref( $select ); + + $log->debug("Search yielded ".scalar(@$recs)." results.",DEBUG); + + $client->respond($_) for (@$recs); + return undef; +} +__PACKAGE__->register_method( + api_name => "open-ils.storage.authority.search.marc", + method => 'find_authority_marc', + api_level => 1, + stream => 1, + cachable => 1, +); + +sub _empty_check { + my $term = shift; + my $class = shift || 'metabib::full_rec'; + + my $table = $class->table; + + my ($index_col) = $class->columns('FTS'); + $index_col ||= 'value'; + + my $fts = OpenILS::Application::Storage::FTS->compile($term, 'm.value', "m.$index_col"); + my $fts_where = $fts->sql_where_clause; + + my $sql = <<" SQL"; + SELECT TRUE + FROM $table m + WHERE $fts_where + LIMIT 1 + SQL + + return $class->db_Main->selectcol_arrayref($sql)->[0]; +} + +sub find_see_from_controlled { + my $self = shift; + my $client = shift; + my $term = shift; + + my @marc = $self->method_lookup('open-ils.storage.authority.search.marc') + ->run( term => $term, tag => '4%', subfield => 'a' ); + for my $m ( @marc ) { + my $doc = $parser->parse_string($m); + my @nodes = $doc->documentElement->findnodes('//*[substring(@tag,1,1)="1"]/*'); + my $list = [ map { $_->textContent } @nodes ]; + $client->respond( $list ) if (_empty_check($$list[0], 'metabib::subject_field_entry')); + } + return undef; +} +__PACKAGE__->register_method( + api_name => "open-ils.storage.authority.see_from.controlled", + method => 'find_see_from_controlled', + api_level => 1, + stream => 1, + cachable => 1, +); + +sub find_see_also_from_controlled { + my $self = shift; + my $client = shift; + my $term = shift; + + my @marc = $self->method_lookup('open-ils.storage.authority.search.marc') + ->run( term => $term, tag => '5%', subfield => 'a' ); + for my $m ( @marc ) { + my $doc = $parser->parse_string($m); + my @nodes = $doc->documentElement->findnodes('//*[substring(@tag,1,1)="1"]/*'); + my $list = [ map { $_->textContent } @nodes ]; + $client->respond( $list ) if (_empty_check($$list[0], 'metabib::subject_field_entry')); + } + return undef; +} +__PACKAGE__->register_method( + api_name => "open-ils.storage.authority.see_also_from.controlled", + method => 'find_see_also_from_controlled', + api_level => 1, + stream => 1, + cachable => 1, +); + + +1; -- 2.43.2