[Koha-patches] [PATCH] 3154 Preference for building facets

Marcel de Rooy M.de.Rooy at rijksmuseum.nl
Thu Feb 24 11:54:35 CET 2011


Thanks for responding.
Did not update the sql files and update script, because I hardcoded the default in the pref file and the Search module. Hoped to make that clear in the patch comments. So it is not really necessary. As soon as a user changes the pref, it will be saved in the db anyway. Lazy programmer ;)

Marcel

-----Oorspronkelijk bericht-----
Van: Fischer, Katrin [mailto:Katrin.Fischer at bsz-bw.de] 
Verzonden: donderdag 24 februari 2011 11:45
Aan: Marcel de Rooy
Onderwerp: RE: [Koha-patches] [PATCH] 3154 Preference for building facets

Hi Marcel, 

I was looking at your patch and I think the syspref is not correctly implemented. 

Chris Cormack (rangi) explained on IRC yesterday what needs to be done:
http://stats.workbuffer.org/irclog/koha/2011-02-23#i_605609

Hope this is helpful for you.

Katrin


> -----Original Message-----
> From: koha-patches-bounces at lists.koha-community.org [mailto:koha-
> patches-bounces at lists.koha-community.org] On Behalf Of Marcel de Rooy
> Sent: Thursday, February 24, 2011 11:36 AM
> To: koha-patches at lists.koha-community.org
> Cc: Frédéric DEMIANS; Fridolyn SOMERS
> Subject: [Koha-patches] [PATCH] 3154 Preference for building facets
> 
> Patch from Fridolyn Somers with input of Frederic Demians.
> I only added new Searching preference maxRecordsForFacets.
> This pref contains number of result records used in facet building.
> Pref not needed in update script; default 20 is used if it should not
> yet exist.
> ---
>  C4/Search.pm                                       |   72
> +++++++++++++-------
>  .../en/modules/admin/preferences/searching.pref    |    6 ++
>  2 files changed, 53 insertions(+), 25 deletions(-)
> 
> diff --git a/C4/Search.pm b/C4/Search.pm
> index a469948..a33e5e2 100644
> --- a/C4/Search.pm
> +++ b/C4/Search.pm
> @@ -309,6 +309,7 @@ sub getRecords {
>      my $facets_counter = ();
>      my $facets_info    = ();
>      my $facets         = getFacets();
> +    my $facets_maxrecs = C4::Context-
> >preference('maxRecordsForFacets')||20;
> 
>      my @facets_loop;    # stores the ref to array of hashes for
> template facets loop
> 
> @@ -418,7 +419,6 @@ sub getRecords {
>                  for ( my $j = $offset ; $j < $times ; $j++ ) {
>                      my $records_hash;
>                      my $record;
> -                    my $facet_record;
> 
>                      ## Check if it's an index scan
>                      if ($scan) {
> @@ -451,33 +451,55 @@ sub getRecords {
> 
>                          # warn "RECORD $j:".$record;
>                          $results_hash->{'RECORDS'}[$j] = $record;
> -
> -            # Fill the facets while we're looping, but only for the
> biblioserver
> -                        $facet_record = MARC::Record-
> >new_from_usmarc($record)
> -                          if $servers[ $i - 1 ] =~ /biblioserver/;
> -
> -                    #warn $servers[$i-1]."\n".$record;
> #.$facet_record->title();
> -                        if ($facet_record) {
> -                            for ( my $k = 0 ; $k <= @$facets ; $k++ )
> {
> -                                ($facets->[$k]) or next;
> -                                my @fields = map {$facet_record-
> >field($_)} @{$facets->[$k]->{'tags'}} ;
> -                                for my $field (@fields) {
> -                                    my @subfields = $field-
> >subfields();
> -                                    for my $subfield (@subfields) {
> -                                        my ( $code, $data ) =
> @$subfield;
> -                                        ($code eq $facets->[$k]-
> >{'subfield'}) or next;
> -                                        $facets_counter->{ $facets-
> >[$k]->{'link_value'} }->{$data}++;
> -                                    }
> -                                }
> -                                $facets_info->{ $facets->[$k]-
> >{'link_value'} }->{'label_value'} =
> -                                    $facets->[$k]->{'label_value'};
> -                                $facets_info->{ $facets->[$k]-
> >{'link_value'} }->{'expanded'} =
> -                                    $facets->[$k]->{'expanded'};
> -                            }
> -                        }
>                      }
> +
>                  }
>                  $results_hashref->{ $servers[ $i - 1 ] } =
> $results_hash;
> +
> +                # Fill the facets while we're looping, but only for
> the biblioserver and not for a scan
> +                if ( !$scan && $servers[ $i - 1 ] =~ /biblioserver/ )
> {
> +
> +                    my $jmax = $size>$facets_maxrecs? $facets_maxrecs:
> $size;
> +
> +                    for ( my $k = 0 ; $k <= @$facets ; $k++ ) {
> +                        ($facets->[$k]) or next;
> +                        my @fcodes = @{$facets->[$k]->{'tags'}};
> +                        my $sfcode = $facets->[$k]->{'subfield'};
> +
> +		                for ( my $j = 0 ; $j < $jmax ; $j++ ) {
> +		                    my $render_record = $results[ $i - 1 ]-
> >record($j)->render();
> +                            my @used_datas = ();
> +
> +                            foreach my $fcode (@fcodes) {
> +
> +                                # avoid first line
> +                                my $field_pattern = '\n'.$fcode.'
> ([^\n]+)';
> +                                my @field_tokens = ( $render_record =~
> /$field_pattern/g ) ;
> +
> +                                foreach my $field_token
> (@field_tokens) {
> +                                    my $subfield_pattern =
> '\$'.$sfcode.' ([^\$]+)';
> +                                    my @subfield_values = (
> $field_token =~ /$subfield_pattern/g );
> +
> +                                    foreach my $subfield_value
> (@subfield_values) {
> +
> +                                        my $data = $subfield_value;
> +                                        $data =~ s/^\s+//; # trim left
> +                                        $data =~ s/\s+$//; # trim
> right
> +
> +                                        unless ( $data ~~ @used_datas
> ) {
> +                                            $facets_counter->{
> $facets->[$k]->{'link_value'} }->{$data}++;
> +                                            push @used_datas, $data;
> +                                        }
> +                                    } # subfields
> +                                } # fields
> +                            } # field codes
> +                        } # records
> +
> +                        $facets_info->{ $facets->[$k]->{'link_value'}
> }->{'label_value'} = $facets->[$k]->{'label_value'};
> +                        $facets_info->{ $facets->[$k]->{'link_value'}
> }->{'expanded'} = $facets->[$k]->{'expanded'};
> +                    } # facets
> +                }
> +                # End PROGILONE
>              }
> 
>              # warn "connection ", $i-1, ": $size hits";
> diff --git a/koha-tmpl/intranet-
> tmpl/prog/en/modules/admin/preferences/searching.pref b/koha-
> tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref
> index cd924dc..ba969ae 100644
> --- a/koha-tmpl/intranet-
> tmpl/prog/en/modules/admin/preferences/searching.pref
> +++ b/koha-tmpl/intranet-
> tmpl/prog/en/modules/admin/preferences/searching.pref
> @@ -122,6 +122,12 @@ Searching:
>                class: integer
>              - items per biblio in the search results
>          -
> +            - Build facets based on
> +            - pref: maxRecordsForFacets
> +              class: integer
> +              default: 20
> +            - records from the search results.
> +        -
>              - By default, show
>              - pref: OPACnumSearchResults
>                class: integer
> --
> 1.6.0.6
> 
> _______________________________________________
> Koha-patches mailing list
> Koha-patches at lists.koha-community.org
> http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches
> website : http://www.koha-community.org/
> git : http://git.koha-community.org/
> bugs : http://bugs.koha-community.org/
> 



More information about the Koha-patches mailing list