Bugzilla – Attachment 35693 Details for
Bug 13562
Item search: Not possible to add other search fields from 952?
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED OFF] Bug 13562: Fix item search on item MARC subfields
SIGNED-OFF-Bug-13562-Fix-item-search-on-item-MARC-.patch (text/plain), 5.78 KB, created by
Nick Clemens (kidclamp)
on 2015-02-06 05:28:53 UTC
(
hide
)
Description:
[SIGNED OFF] Bug 13562: Fix item search on item MARC subfields
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2015-02-06 05:28:53 UTC
Size:
5.78 KB
patch
obsolete
>From 7d3e02750b879ac37ff3e85f831a0f30e0fd52ea Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Wed, 14 Jan 2015 17:00:17 +0100 >Subject: [PATCH] [SIGNED OFF] Bug 13562: Fix item search on item MARC > subfields >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Test plan: >1. Add 4 item search fields (in Administration ΓΆΒΊ Items search fields): > a. 1 biblio field linked to a DB field > b. 1 biblio field not linked to a DB field > c. 1 item field linked to a DB field > d. 1 item field not linked to a DB field >2. Make sure you have some data in those fields to search on. >3. Go to item search page and do a search using these new fields, make > sure the result is correct. > >Signed-off-by: Nick <nick@quecheelibrary.org> >--- > C4/Items.pm | 32 +++++++++++++++++++++++++++----- > t/db_dependent/Items.t | 48 +++++++++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 74 insertions(+), 6 deletions(-) > >diff --git a/C4/Items.pm b/C4/Items.pm >index 33143a5..a225b49 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -2599,6 +2599,8 @@ sub SearchItemsByField { > sub _SearchItems_build_where_fragment { > my ($filter) = @_; > >+ my $dbh = C4::Context->dbh; >+ > my $where_fragment; > if (exists($filter->{conjunction})) { > my (@where_strs, @where_args); >@@ -2635,13 +2637,33 @@ sub _SearchItems_build_where_fragment { > if ($field =~ /^marc:(\d{3})(?:\$(\w))?$/) { > my $marcfield = $1; > my $marcsubfield = $2; >- my $xpath; >- if ($marcfield < 10) { >- $xpath = "//record/controlfield[\@tag=\"$marcfield\"]"; >+ my ($kohafield) = $dbh->selectrow_array(q| >+ SELECT kohafield FROM marc_subfield_structure >+ WHERE tagfield=? AND tagsubfield=? AND frameworkcode='' >+ |, undef, $marcfield, $marcsubfield); >+ >+ if ($kohafield) { >+ $column = $kohafield; > } else { >- $xpath = "//record/datafield[\@tag=\"$marcfield\"]/subfield[\@code=\"$marcsubfield\"]"; >+ # MARC field is not linked to a DB field so we need to use >+ # ExtractValue on biblioitems.marcxml or >+ # items.more_subfields_xml, depending on the MARC field. >+ my $xpath; >+ my $sqlfield; >+ my ($itemfield) = GetMarcFromKohaField('items.itemnumber'); >+ if ($marcfield eq $itemfield) { >+ $sqlfield = 'more_subfields_xml'; >+ $xpath = '//record/datafield/subfield[@code="' . $marcsubfield . '"]'; >+ } else { >+ $sqlfield = 'marcxml'; >+ if ($marcfield < 10) { >+ $xpath = "//record/controlfield[\@tag=\"$marcfield\"]"; >+ } else { >+ $xpath = "//record/datafield[\@tag=\"$marcfield\"]/subfield[\@code=\"$marcsubfield\"]"; >+ } >+ } >+ $column = "ExtractValue($sqlfield, '$xpath')"; > } >- $column = "ExtractValue(marcxml, '$xpath')"; > } else { > $column = $field; > } >diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t >index d94b7b7..dfb1654 100755 >--- a/t/db_dependent/Items.t >+++ b/t/db_dependent/Items.t >@@ -228,7 +228,7 @@ subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub { > }; > > subtest 'SearchItems test' => sub { >- plan tests => 10; >+ plan tests => 13; > > # Start transaction > $dbh->{AutoCommit} = 0; >@@ -337,6 +337,52 @@ subtest 'SearchItems test' => sub { > } > ok($found, "item1 found"); > >+ my ($itemfield) = GetMarcFromKohaField('items.itemnumber', ''); >+ >+ # Create item subfield 'z' without link >+ $dbh->do('DELETE FROM marc_subfield_structure WHERE tagfield=? AND tagsubfield="z" AND frameworkcode=""', undef, $itemfield); >+ $dbh->do('INSERT INTO marc_subfield_structure (tagfield, tagsubfield, frameworkcode) VALUES (?, "z", "")', undef, $itemfield); >+ >+ # Clear cache >+ $C4::Context::context->{marcfromkohafield} = undef; >+ $C4::Biblio::inverted_field_map = undef; >+ >+ my $item3_record = new MARC::Record; >+ $item3_record->append_fields( >+ new MARC::Field($itemfield, '', '', 'z' => 'foobar') >+ ); >+ my (undef, undef, $item3_itemnumber) = AddItemFromMarc($item3_record, >+ $biblionumber); >+ >+ # Search item where item subfield z is "foobar" >+ $filter = { >+ field => 'marc:' . $itemfield . '$z', >+ query => 'foobar', >+ operator => 'like', >+ }; >+ ($items, $total_results) = SearchItems($filter); >+ ok(scalar @$items == 1, 'found 1 item with $z = "foobar"'); >+ >+ # Link $z to items.itemnotes (and make sure there is no other subfields >+ # linked to it) >+ $dbh->do('DELETE FROM marc_subfield_structure WHERE kohafield="items.itemnotes" AND frameworkcode=""', undef, $itemfield); >+ $dbh->do('UPDATE marc_subfield_structure SET kohafield="items.itemnotes" WHERE tagfield=? AND tagsubfield="z" AND frameworkcode=""', undef, $itemfield); >+ >+ # Clear cache >+ $C4::Context::context->{marcfromkohafield} = undef; >+ $C4::Biblio::inverted_field_map = undef; >+ >+ ModItemFromMarc($item3_record, $biblionumber, $item3_itemnumber); >+ >+ # Make sure the link is used >+ my $item3 = GetItem($item3_itemnumber); >+ ok($item3->{itemnotes} eq 'foobar', 'itemnotes eq "foobar"'); >+ >+ # Do the same search again. >+ # This time it will search in items.itemnotes >+ ($items, $total_results) = SearchItems($filter); >+ ok(scalar @$items == 1, 'found 1 item with itemnotes = "foobar"'); >+ > $dbh->rollback; > }; > >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13562
:
35288
|
35693
|
35694