[Koha-patches] [PATCH 2/2] Bug 12788: facets calculation should skip 100 if ind1=z

Tomas Cohen Arazi tomascohen at gmail.com
Wed Aug 20 06:06:42 CEST 2014


This patch adds a test for field 100, to skip it on facet calculation
if ind1=z.

To test:
- Have IncludeSeeFromInSearches set.
- Create a biblio record, when adding an author, create a new authority record
  that contains a 400$a field (see from).
- Rebuild zebra db.
- Search for the record making sure the search returns more than one record.
=> FAIL: the facets contain the 'see from' field.
- Run
  $ prove -v t/db_dependent/Search.t
=> FAIL: it fails
- Apply the patch
- Run
  $ prove -v t/db_dependent/Search.t
=> SUCCESS: it passes
- Re-run the search, notice the 'see from' doesn't show anymore on the facets.
- Sign off :-D

Regards
To+

Sponsored-by: Universidad Nacional de Cordoba
---
 C4/Search.pm | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/C4/Search.pm b/C4/Search.pm
index 9587f7d..43ab179 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -656,7 +656,7 @@ sub getRecords {
     C4::Search::_get_facets_data_from_record( $marc_record, $facets, $facets_counter );
 
 Internal function that extracts facets information from a MARC::Record object
-and populates $facets_counter for using in getRecords.
+and populates $facets_counter and $facets_info for using in getRecords.
 
 $facets is expected to be filled with C4::Koha::getFacets output (i.e. the configured
 facets for Zebra).
@@ -673,19 +673,24 @@ sub _get_facets_data_from_record {
 
         foreach my $tag ( @{ $facet->{ tags } } ) {
 
-            # avoid first line
+            # tag number is the first three digits
             my $tag_num          = substr( $tag, 0, 3 );
+            # subfields are the remainder
             my $subfield_letters = substr( $tag, 3 );
-            # Removed when as_string fixed
-            my @subfields = $subfield_letters =~ /./sg;
 
             my @fields = $marc_record->field( $tag_num );
             foreach my $field (@fields) {
-                my $data = $field->as_string( $subfield_letters, $facet->{ sep } );
+                if ( $field->indicator(1) eq 'z' ) {
+                    # If $field->indicator(1) eq 'z', it means it is a 'see from'
+                    # field introduced because of IncludeSeeFromInSearches, so skip it
+                    next;
+                } else {
+                    my $data = $field->as_string( $subfield_letters, $facet->{ sep } );
 
-                unless ( grep { /^\Q$data\E$/ } @used_datas ) {
-                    push @used_datas, $data;
-                    $facets_counter->{ $facet->{ idx } }->{ $data }++;
+                    unless ( grep { /^\Q$data\E$/ } @used_datas ) {
+                        push @used_datas, $data;
+                        $facets_counter->{ $facet->{ idx } }->{ $data }++;
+                    }
                 }
             }
         }
-- 
1.9.1



More information about the Koha-patches mailing list