From 265ed53f12df70d0ef8a4f5af8add20507658a3a Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 16 Mar 2011 15:06:36 -0400 Subject: [PATCH 1/3] 3154 Preferences for building facets (functionality) Based on patch from Fridolyn Somers with input of Frederic Demians. Added new Searching preference maxRecordsForFacets. This pref contains number of result records used in facet building. Also added pref displayFacetCount (with thanks to Frederic). Follow up patch takes care of install issues; functionality can already be tested with this patch only. Updated on March 17 for changes in include files. Signed-off-by: Nicole C. Engard Signed-off-by: Chris Cormack --- C4/Search.pm | 72 ++++++++++++------- catalogue/search.pl | 1 + .../intranet-tmpl/prog/en/includes/facets.inc | 2 +- .../modules/admin/preferences/searching.pref | 14 ++++ .../prog/en/includes/opac-facets.inc | 2 +- opac/opac-search.pl | 1 + 6 files changed, 65 insertions(+), 27 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 53c83962c3..7c513913d9 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/catalogue/search.pl b/catalogue/search.pl index f920efe01d..b22837ad83 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -657,6 +657,7 @@ $template->param( total => $total, opacfacets => 1, facets_loop => $facets, + displayFacetCount=> C4::Context->preference('displayFacetCount')||0, scan => $scan, search_error => $error, ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc index b53bfb79eb..710dc23ddd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc @@ -17,7 +17,7 @@ Series Libraries 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 5ff267f6c7..d0a58e0e55 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 @@ -98,6 +98,14 @@ Searching: dsc: descending. az: from A to Z. za: from Z to A. + - + - pref: displayFacetCount + type: boolean + default: no + choices: + yes: Show + no: "Don't show" + - facet counts. The relevance of these numbers highly depends on the value of the maxRecordsForFacets preference. Applies to OPAC and staff interface. - - By default, show - pref: numSearchResults @@ -128,6 +136,12 @@ Searching: - pref: maxItemsInSearchResults 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 diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/opac-facets.inc b/koha-tmpl/opac-tmpl/prog/en/includes/opac-facets.inc index cc6d23578c..57f0518ed9 100644 --- a/koha-tmpl/opac-tmpl/prog/en/includes/opac-facets.inc +++ b/koha-tmpl/opac-tmpl/prog/en/includes/opac-facets.inc @@ -18,7 +18,7 @@ Libraries diff --git a/opac/opac-search.pl b/opac/opac-search.pl index bf4e0db980..d22049f3fe 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -628,6 +628,7 @@ $template->param( total => $total, opacfacets => 1, facets_loop => $facets, + displayFacetCount=> C4::Context->preference('displayFacetCount')||0, scan => $scan, search_error => $error, ); From 0aee8e95416970be05aa8a38e9a90facc5e85129 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 16 Mar 2011 15:06:55 -0400 Subject: [PATCH 2/3] 3154 Preferences for building facets (install) Adds prefs for facets in sql install files and updatedatabase script. Rebased on March 17. Signed-off-by: Nicole C. Engard Signed-off-by: Chris Cormack --- installer/data/mysql/de-DE/mandatory/sysprefs.sql | 3 ++- installer/data/mysql/en/mandatory/sysprefs.sql | 2 ++ .../fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql | 3 ++- installer/data/mysql/it-IT/necessari/sysprefs.sql | 3 ++- installer/data/mysql/pl-PL/mandatory/sysprefs.sql | 3 ++- .../system_preferences_full_optimal_for_install_only.sql | 2 ++ .../system_preferences_full_optimal_for_install_only.sql | 2 ++ installer/data/mysql/updatedatabase.pl | 8 ++++++++ 8 files changed, 22 insertions(+), 4 deletions(-) diff --git a/installer/data/mysql/de-DE/mandatory/sysprefs.sql b/installer/data/mysql/de-DE/mandatory/sysprefs.sql index a2018ed3ca..43e70197dd 100644 --- a/installer/data/mysql/de-DE/mandatory/sysprefs.sql +++ b/installer/data/mysql/de-DE/mandatory/sysprefs.sql @@ -291,4 +291,5 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('TraceCompleteSubfields','0','Force subject tracings to only match complete subfields.','0','YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('UseAuthoritiesForTracings','1','Use authority record numbers for subject tracings instead of heading strings.','0','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAllowUserToChooseBranch', 1, 'Allow the user to choose the branch they want to pickup their hold from','1','YesNo'); - +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('displayFacetCount', '0', NULL, NULL, 'YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxRecordsForFacets', '20', NULL, NULL, 'Integer'); diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql index 4a7ce9bc3b..9337fd1353 100644 --- a/installer/data/mysql/en/mandatory/sysprefs.sql +++ b/installer/data/mysql/en/mandatory/sysprefs.sql @@ -291,3 +291,5 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('TraceCompleteSubfields','0','Force subject tracings to only match complete subfields.','0','YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('UseAuthoritiesForTracings','1','Use authority record numbers for subject tracings instead of heading strings.','0','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAllowUserToChooseBranch', 1, 'Allow the user to choose the branch they want to pickup their hold from','1','YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('displayFacetCount', '0', NULL, NULL, 'YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxRecordsForFacets', '20', NULL, NULL, 'Integer'); diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql index cc1d954840..f29382819e 100644 --- a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql +++ b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql @@ -293,4 +293,5 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('TraceCompleteSubfields','0','Force subject tracings to only match complete subfields.','0','YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('UseAuthoritiesForTracings','1','Use authority record numbers for subject tracings instead of heading strings.','0','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAllowUserToChooseBranch', 1, 'Allow the user to choose the branch they want to pickup their hold from','1','YesNo'); - +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('displayFacetCount', '0', NULL, NULL, 'YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxRecordsForFacets', '20', NULL, NULL, 'Integer'); diff --git a/installer/data/mysql/it-IT/necessari/sysprefs.sql b/installer/data/mysql/it-IT/necessari/sysprefs.sql index 08abec5601..23a2bd256d 100644 --- a/installer/data/mysql/it-IT/necessari/sysprefs.sql +++ b/installer/data/mysql/it-IT/necessari/sysprefs.sql @@ -278,4 +278,5 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('TraceCompleteSubfields','0','Force subject tracings to only match complete subfields.','0','YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('UseAuthoritiesForTracings','1','Use authority record numbers for subject tracings instead of heading strings.','0','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAllowUserToChooseBranch', 1, 'Allow the user to choose the branch they want to pickup their hold from','1','YesNo'); - +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('displayFacetCount', '0', NULL, NULL, 'YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxRecordsForFacets', '20', NULL, NULL, 'Integer'); diff --git a/installer/data/mysql/pl-PL/mandatory/sysprefs.sql b/installer/data/mysql/pl-PL/mandatory/sysprefs.sql index cfbca167a1..f177a95984 100644 --- a/installer/data/mysql/pl-PL/mandatory/sysprefs.sql +++ b/installer/data/mysql/pl-PL/mandatory/sysprefs.sql @@ -290,4 +290,5 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('TraceCompleteSubfields','0','Force subject tracings to only match complete subfields.','0','YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('UseAuthoritiesForTracings','1','Use authority record numbers for subject tracings instead of heading strings.','0','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAllowUserToChooseBranch', 1, 'Allow the user to choose the branch they want to pickup their hold from','1','YesNo'); - +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('displayFacetCount', '0', NULL, NULL, 'YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxRecordsForFacets', '20', NULL, NULL, 'Integer'); diff --git a/installer/data/mysql/ru-RU/mandatory/system_preferences_full_optimal_for_install_only.sql b/installer/data/mysql/ru-RU/mandatory/system_preferences_full_optimal_for_install_only.sql index 5ffcd7b580..7576cb09cb 100644 --- a/installer/data/mysql/ru-RU/mandatory/system_preferences_full_optimal_for_install_only.sql +++ b/installer/data/mysql/ru-RU/mandatory/system_preferences_full_optimal_for_install_only.sql @@ -345,3 +345,5 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('TraceCompleteSubfields','0','Force subject tracings to only match complete subfields.','0','YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('UseAuthoritiesForTracings','1','Use authority record numbers for subject tracings instead of heading strings.','0','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAllowUserToChooseBranch', 1, 'Allow the user to choose the branch they want to pickup their hold from','1','YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('displayFacetCount', '0', NULL, NULL, 'YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxRecordsForFacets', '20', NULL, NULL, 'Integer'); diff --git a/installer/data/mysql/uk-UA/mandatory/system_preferences_full_optimal_for_install_only.sql b/installer/data/mysql/uk-UA/mandatory/system_preferences_full_optimal_for_install_only.sql index bceb62bfe3..79b0ff9e07 100644 --- a/installer/data/mysql/uk-UA/mandatory/system_preferences_full_optimal_for_install_only.sql +++ b/installer/data/mysql/uk-UA/mandatory/system_preferences_full_optimal_for_install_only.sql @@ -370,3 +370,5 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('TraceCompleteSubfields','0','Force subject tracings to only match complete subfields.','0','YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('UseAuthoritiesForTracings','1','Use authority record numbers for subject tracings instead of heading strings.','0','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAllowUserToChooseBranch', 1, 'Allow the user to choose the branch they want to pickup their hold from','1','YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('displayFacetCount', '0', NULL, NULL, 'YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxRecordsForFacets', '20', NULL, NULL, 'Integer'); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 66e9828abf..ad23bc5f1f 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4090,6 +4090,14 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = '3.03.00.XXX'; #FIXME +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('displayFacetCount', '0', NULL, NULL, 'YesNo')"); + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('maxRecordsForFacets', '20', NULL, NULL, 'Integer')"); + print "Upgrade to $DBversion done (Preferences for facet count)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) From 98d702e0344a66bf1e4c3e80ba150d0b65d1d3b4 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Tue, 22 Mar 2011 20:58:18 +1300 Subject: [PATCH 3/3] Bumping database version --- installer/data/mysql/updatedatabase.pl | 2 +- kohaversion.pl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index ad23bc5f1f..6f589ed42d 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4090,7 +4090,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } -$DBversion = '3.03.00.XXX'; #FIXME +$DBversion = '3.03.00.027'; #FIXME if (C4::Context->preference("Version") < TransformToNum($DBversion)) { $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('displayFacetCount', '0', NULL, NULL, 'YesNo')"); $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('maxRecordsForFacets', '20', NULL, NULL, 'Integer')"); diff --git a/kohaversion.pl b/kohaversion.pl index e3b9ad1033..81454c0d9f 100644 --- a/kohaversion.pl +++ b/kohaversion.pl @@ -16,7 +16,7 @@ the kohaversion is divided in 4 parts : use strict; sub kohaversion { - our $VERSION = '3.03.00.026'; + our $VERSION = '3.03.00.027'; # version needs to be set this way # so that it can be picked up by Makefile.PL # during install