@@ -, +, @@ --- C4/Search.pm | 1 + Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 1 + catalogue/search.pl | 93 +++++----- etc/zebradb/ccl.properties | 1 + .../prog/en/includes/subtype_limits.inc | 49 +++++ .../prog/en/modules/catalogue/advsearch.tt | 199 +++++++++++++++++---- .../prog/en/modules/catalogue/results.tt | 2 + 7 files changed, 269 insertions(+), 77 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/subtype_limits.inc --- a/C4/Search.pm +++ a/C4/Search.pm @@ -1225,6 +1225,7 @@ sub getIndexes{ 'lost', 'materials-specified', 'mc-ccode', + 'mc-homebranch', 'mc-itype', 'mc-loc', 'notforloan', --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -681,6 +681,7 @@ our %index_field_convert = ( 'inv' => 'number-local-acquisition', 'bc' => 'barcode', 'mc-itype' => 'itype', + 'mc-homebranch' => 'homebranch', 'aub' => 'author-personal-bibliography', 'auo' => 'author-in-order', 'ff8-22' => 'ta', --- a/catalogue/search.pl +++ a/catalogue/search.pl @@ -168,8 +168,15 @@ my $cgi = CGI->new; # decide which template to use my $template_name; my $template_type; -my @params = $cgi->multi_param("limit"); -if ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) ) { +# limits are use to limit to results to a pre-defined category such as branch or language +my @limits = map uri_unescape($_), $cgi->multi_param("limit"); +my @nolimits = map uri_unescape($_), $cgi->multi_param('nolimit'); +my %is_nolimit = map { $_ => 1 } @nolimits; +@limits = grep { not $is_nolimit{$_} } @limits; +if ( + !$cgi->param('edit_search') && + ( (@limits>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) ) + ) { $template_name = 'catalogue/results.tt'; $template_type = 'results'; } @@ -245,6 +252,32 @@ $template->param( searchid => scalar $cgi->param('searchid'), ); # The following should only be loaded if we're bringing up the advanced search template if ( $template_type eq 'advsearch' ) { + my $expanded = $cgi->param('expanded_options'); + if( $cgi->param('edit_search') ){ + my @operators = $cgi->multi_param('op'); + my @indexes = $cgi->multi_param('idx'); + my %limit_hash; + foreach my $limit (@limits){ + if ( $limit eq 'available' ){ + $template->param( limit_available => 1 ); + } else { + my ($index,$value) = split(':',$limit); + $value =~ s/"//g; + if ( $index =~ /mc-/ ){ + $limit_hash{$index . "_" . $value} = 1; + } else { + push @{$limit_hash{$index}}, $value; + } + } + }; + $expanded = 1 if scalar @operators || scalar @limits; + $template->param( operators => \@operators ); + $template->param( limits => \%limit_hash ); + $template->param( + indexes => \@indexes, + sort => \$cgi->param('sort_by'), + ); + } # load the servers (used for searching -- to do federated searching, etc.) my $primary_servers_loop;# = displayPrimaryServers(); $template->param(outer_servers_loop => $primary_servers_loop,); @@ -261,44 +294,21 @@ if ( $template_type eq 'advsearch' ) { $template->param( sort_by => $default_sort_by ); } - # determine what to display next to the search boxes (ie, boolean option - # shouldn't appear on the first one, scan indexes should, adding a new - # box should only appear on the last, etc. - my @search_boxes_array; - my $search_boxes_count = 3; # begin with 3 boxes - # FIXME: all this junk can be done in TMPL using __first__ and __last__ - for (my $i=1;$i<=$search_boxes_count;$i++) { - # if it's the first one, don't display boolean option, but show scan indexes - if ($i==1) { - push @search_boxes_array, {scan_index => 1}; - } - # if it's the last one, show the 'add field' box - elsif ($i==$search_boxes_count) { - push @search_boxes_array, - { - boolean => 1, - add_field => 1, - }; - } - else { - push @search_boxes_array, - { - boolean => 1, - }; - } - + # determine what to display next to the search boxes + my @queries = $cgi->multi_param('q'); + while( scalar @queries < 3 ){ + push @queries, ""; } - $template->param(uc(C4::Context->preference("marcflavour")) => 1, - search_boxes_loop => \@search_boxes_array); + $template->param(uc(C4::Context->preference("marcflavour")) =>1 ); # load the language limits (for search) my $languages_limit_loop = getLanguages($lang, 1); $template->param(search_languages_loop => $languages_limit_loop,); + $template->param( queries => \@queries ); # Expanded search options in advanced search: # use the global setting by default, but let the user override it { - my $expanded = $cgi->param('expanded_options'); $expanded = C4::Context->preference("expandedSearchOption") || 0 if !defined($expanded) || $expanded !~ /^0|1$/; $template->param( expanded_options => $expanded ); @@ -369,17 +379,10 @@ if ($operands[0] && !$operands[1]) { $template->param(ms_value => $ms_query); } -# limits are use to limit to results to a pre-defined category such as branch or language -my @limits = map uri_unescape($_), $cgi->multi_param('limit'); -my @nolimits = map uri_unescape($_), $cgi->multi_param('nolimit'); -my %is_nolimit = map { $_ => 1 } @nolimits; -@limits = grep { not $is_nolimit{$_} } @limits; - if($params->{'multibranchlimit'}) { my $search_group = Koha::Library::Groups->find( $params->{multibranchlimit} ); my @libraries = $search_group->all_libraries; - my $multibranch = '('.join( " OR ", map { '(homebranch: ' . $_->branchcode .')' } @libraries ) .')'; - push @limits, $multibranch if ($multibranch ne '()'); + push @limits, map { 'mc-homebranch:' . $_->branchcode } @libraries; } my $available; @@ -395,7 +398,7 @@ my $limit_yr; my $limit_yr_value; if ($params->{'limit-yr'}) { if ($params->{'limit-yr'} =~ /\d{4}/) { - $limit_yr = "yr,st-numeric=$params->{'limit-yr'}"; + $limit_yr = "yr,st-numeric:$params->{'limit-yr'}"; $limit_yr_value = $params->{'limit-yr'}; } push @limits,$limit_yr; @@ -571,6 +574,11 @@ for (my $i=0;$i<@servers;$i++) { # set up parameters if user wishes to re-run the search # as a Z39.50 search $template->param (z3950_search_params => C4::Search::z3950_search_args($z3950par || $query_desc)); + $template->param(limit_cgi => $limit_cgi); + $template->param(query_cgi => $query_cgi); + $template->param(query_desc => $query_desc); + $template->param(limit_desc => $limit_desc); + $template->param(offset => $offset); if ($hits) { $template->param(total => $hits); @@ -579,11 +587,6 @@ for (my $i=0;$i<@servers;$i++) { $limit_cgi_not_availablity =~ s/&limit=available//g; $template->param(limit_cgi_not_availablity => $limit_cgi_not_availablity); } - $template->param(limit_cgi => $limit_cgi); - $template->param(query_cgi => $query_cgi); - $template->param(query_desc => $query_desc); - $template->param(limit_desc => $limit_desc); - $template->param(offset => $offset); $template->param(DisplayMultiPlaceHold => $DisplayMultiPlaceHold); if ($query_desc || $limit_desc) { $template->param(searchdesc => 1); --- a/etc/zebradb/ccl.properties +++ a/etc/zebradb/ccl.properties @@ -1011,6 +1011,7 @@ mc-ccode ccode itemnumber 1=8010 4=109 # homebranch 1=8011 homebranch 1=homebranch +mc-homebranch homebranch branch homebranch holdingbranch 1=8012 location 1=8013 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/subtype_limits.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/subtype_limits.inc @@ -0,0 +1,49 @@ +[%- BLOCK subtype_limits_description -%] + [%- SWITCH subtype_limit -%] + [%- CASE 'aud:a' -%]Preschool + [%- CASE 'aud:b' -%]Primary + [%- CASE 'aud:c' -%]Pre-adolescent + [%- CASE 'aud:d' -%]Adolescent + [%- CASE 'aud:e' -%]Adult + [%- CASE 'aud:f' -%]Specialized + [%- CASE 'aud:g' -%]General + [%- CASE 'aud:j' -%]Juvenile + [%- CASE 'fic:1' -%]Fiction + [%- CASE 'fic:0' -%]Non-fiction + [%- CASE 'bio:b' -%]Biography + [%- CASE 'mus:j' -%]Musical recording + [%- CASE 'mus:i' -%]Non-musical recording + [%- CASE 'l-format:ta' -%]Regular print + [%- CASE 'l-format:tb' -%]Large print + [%- CASE 'l-format:tc or l-format:fb' -%]Braille + [%- CASE '' -%]----------- + [%- CASE 'l-format:sd' -%]CD audio + [%- CASE 'l-format:ss' -%]Cassette recording + [%- CASE 'l-format:vf' -%]VHS tape / Videocassette + [%- CASE 'l-format:vd' -%]DVD video / Videodisc + [%- CASE 'l-format:co' -%]CD software + [%- CASE 'l-format:cr' -%]Website + [%- CASE 'ctype:a' -%]Abstracts / Summaries + [%- CASE 'ctype:b' -%]Bibliographies + [%- CASE 'ctype:c' -%]Catalogs + [%- CASE 'ctype:d' -%]Dictionaries + [%- CASE 'ctype:e' -%]Encyclopedias + [%- CASE 'ctype:f' -%]Handbooks + [%- CASE 'ctype:g' -%]Legal articles + [%- CASE 'ctype:i' -%]Indexes + [%- CASE 'ctype:j' -%]Patent document + [%- CASE 'ctype:k' -%]Discographies + [%- CASE 'ctype:l' -%]Legislation + [%- CASE 'ctype:m' -%]Theses + [%- CASE 'ctype:n' -%]Surveys + [%- CASE 'ctype:o' -%]Reviews + [%- CASE 'ctype:p' -%]Programmed texts + [%- CASE 'ctype:q' -%]Filmographies + [%- CASE 'ctype:r' -%]Directories + [%- CASE 'ctype:s' -%]Statistics + [%- CASE 'ctype:t' -%]Technical reports + [%- CASE 'ctype:v' -%]Legal cases and case notes + [%- CASE 'ctype:w' -%]Law reports and digests + [%- CASE 'ctype:z' -%]Treaties + [%- END -%] +[%- END -%] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt @@ -2,6 +2,7 @@ [% USE Koha %] [% USE Asset %] [% USE Branches %] +[% USE Languages %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Catalog › Advanced search @@ -93,32 +94,44 @@
Search for - [% FOREACH search_box IN search_boxes_loop %] - [% IF ( search_boxes_label ) %] -
- [% ELSE %] -
- [% END %] - [% IF ( expanded_options ) %] - [% IF ( search_box.boolean ) %] + [% FOREACH query IN queries %] + [% IF ( expanded_options ) %] + [% IF ( loop.first ) %] +
+ [% ELSE %] +
+ [% SET opindex = loop.index - 1 %] - [% END %] - [% END %] - [% INCLUDE 'search_indexes.inc' %] - - [% IF ( expanded_options ) %] - [% IF ( search_box.add_field ) %] - [+] - [% END %] - [% IF ( search_box.scan_index ) %] + [% END %] + [% ELSE %] +
+ [% END %] + [% SET preselect = 'ms_' _ indexes.${loop.index}.replace(',','comma') %] + [% INCLUDE 'search_indexes.inc' $preselect=1 %] + + [% IF ( expanded_options ) %] + [% IF ( loop.last ) %] + [+] + [% END %] + [% IF ( loop.first ) %] - [% END %] [% END %] -
+ [% END %] +
[% END %] [% IF Koha.Preference('SearchEngine') == 'Elasticsearch' %] [% IF ( expanded_options ) %] @@ -129,7 +142,7 @@ -

+ [% ELSE %] [% END %] @@ -159,9 +172,32 @@ [% FOREACH itemtypeloo IN advsearchloo.code_loop %] - - [% IF ( loop.last ) %][% ELSE %][% UNLESS ( loop.count % 5 ) %][% END %][% END %] + + [% IF ( loop.last ) %] + + [% ELSE %] + [% UNLESS ( loop.count % 5 ) %] + + + [% END %] + [% END %] [% END %]
+ [% SET limit_key = 'mc-' _ itemtypeloo.ccl _ "_" _ itemtypeloo.code %] + [% IF limits.$limit_key.defined %] + [% limits.delete( limit_key ) %] + + [% ELSE %] + + [% END %] + +

@@ -174,12 +210,32 @@

-   (format: yyyy-yyyy)

+ [% SET year_limit_key = 'yr,st-numeric' %] +   (format: yyyy-yyyy)

+ [% IF limits.$year_limit_key.defined %] + [% limits.delete($year_limit_key) %] + [% END %]

+

Current language limits + [% FOREACH langtype IN ['ln,rtrn','language-original,rtrn'] %] + [% FOREACH limit IN limits.$langtype %] + + + + + + [% END %] + [% limits.delete( langtype ) %] + [% END %] +
+ [% PROCESS language_limit_select ln_loop=search_languages_loop ln_id='language-limit' ln_index='ln' %] @@ -195,9 +251,24 @@ [% IF ( UNIMARC ) %] [% INCLUDE 'subtypes_unimarc.inc' %] [% ELSE %] +[% PROCESS 'subtype_limits.inc' %]
Subtype limits

+ +

Current subtype limits + [% FOREACH subtype IN ['aud','fic','bio','ctype','l-format'] %] + [% FOREACH limit IN limits.$subtype %] + + + + + + [% END %] + [% limits.delete( subtype ) %] + [% END %] +
+

+ [% IF limit_available %] +

+ [% ELSE %] +

+ [% END %]
+
+ Individual branches +

If multiple branches are provided, only records with items from all of those branches will be returned

+ [% FOREACH branch IN limits.branch %] + + + + + + [% END %] + [% limits.delete('branch') %]

+
+

OR

+
+ Multiple branches +

If multiple branches are selected here records with items in any of these branches will be returned. Selecting a group when some libraries are already selected will add the group libraries to the list

+

Selecting a group will disable the option to select individual libraries

[% IF search_groups %] -

OR

+ [% FOREACH key IN limits.keys %] + [% IF ( multibranch = key.match('^mc-homebranch_(.*)') ) %] + + + + + + [% limits.delete(key) %] + [% END %] + [% END %]

@@ -292,16 +392,35 @@ [% END %]

+
[% END %]
+ +[% IF limits.size %] +
Other limits +

+ [% FOREACH key IN limits.keys %] + [% FOREACH limit IN limits.$key %] + + + + + + [% END %] + [% END %] +

+
+[% END %] + +
Sorting

@@ -342,6 +461,22 @@ document.getElementById("categoryloop").disabled=false; } }); + $(".toggle_limit").on('click',function(){ + $(this).siblings("[type='hidden']").prop('disabled', !this.checked); + }); + $("#categoryloop").on('change',function(){ + if( $(this).val() != "" ){ + $("#individual_branches select,#individual_branches input").prop('disabled',true); + } else { + $("#individual_branches select,#individual_branches input").prop('disabled',false); + } + }); + if( $("#current_language_limits input").length == 0 ){ + $("#current_language_limits").hide(); + } + if( $("#current_subtype_limits input").length == 0 ){ + $("#current_subtype_limits").hide(); + } [% IF searchid %] browser = KOHA.browser('[% searchid | html %]'); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -65,6 +65,7 @@

[% total | html %] result(s) found [% IF ( query_desc ) %]for '[% query_desc | html %]'[% END %][% IF limit_desc %] with limit(s): '[% limit_desc | html %]'[% END %][% IF ( LibraryName ) %] in [% LibraryName | html %] Catalog[% END %].

+ Edit this search
@@ -315,6 +316,7 @@

No results match your search [% IF ( query_desc ) %]for '[% query_desc | html %]'[% END %][% IF ( limit_desc ) %] with limit(s): '[% limit_desc | html %]'[% END %][% IF ( LibraryName ) %] in [% LibraryName | html %] Catalog[% END %].

+ Edit this search [% ELSE %]

You did not specify any search criteria.

[% END %] --