From 4559e0e0e00d6fc0a2cbd4b840e8b78e11576126 Mon Sep 17 00:00:00 2001 From: Joshua Ferraro Date: Mon, 29 Oct 2007 17:42:26 -0500 Subject: [PATCH] Searching Patch 1: fixing searching in 3.0 Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Search.pm | 4 +- catalogue/search.pl | 103 ++-- changelanguage.pl | 26 + etc/zebradb/biblios/etc/bib1.att | 15 +- etc/zebradb/biblios/etc/record.abs | 2 - etc/zebradb/ccl.properties | 4 +- .../intranet-tmpl/prog/en/includes/header.inc | 2 +- .../prog/en/includes/intranet-bottom.inc | 13 +- .../prog/en/modules/catalogue/advsearch.tmpl | 326 +++------- .../modules/catalogue/advsearch_unimarc.tmpl | 571 ++++++++++++++++++ 10 files changed, 756 insertions(+), 310 deletions(-) create mode 100755 changelanguage.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch_unimarc.tmpl diff --git a/C4/Search.pm b/C4/Search.pm index 09b324d28f4..860b21666a0 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -572,8 +572,8 @@ sub buildQuery { # otherwise, a french word like "leçon" is splitted in "le" "çon", le is an empty word, we get "çon" # and don't find anything... my $stemmed_operand; - my $stemming = C4::Context->parameters("Stemming") || 0; - my $weight_fields = C4::Context->parameters("WeightFields") || 0; + my $stemming = C4::Context->preference("Stemming") || 0; + my $weight_fields = C4::Context->preference("WeightFields") || 0; # We Have to do this more carefully. #Since Phrase Search Is Phrase search. diff --git a/catalogue/search.pl b/catalogue/search.pl index 2f05649709c..f1e48bdf83f 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -23,14 +23,14 @@ =head1 NAME -search - a search script for finding records in a Koha system (Version 2.4) +search - a search script for finding records in a Koha system (Version 3.0) =head1 OVERVIEW -This script contains a demonstration of a new search API for Koha 2.4. It is -designed to be simple to use and configure, yet capable of performing feats -like stemming, field weighting, relevance ranking, support for multiple -query language formats (CCL, CQL, PQF), full or nearly full support for the +This script contains a new search API for Koha 3.0. It is designed to be +simple to use and configure, yet capable of performing feats like stemming, +field weighting, relevance ranking, support for multiple query language +formats (CCL, CQL, PQF), full or nearly full support for the bib1 attribute set, extended attribute sets defined in Zebra profiles, access to the full range of Z39.50 query options, federated searches on Z39.50 targets, etc. @@ -68,9 +68,13 @@ =head2 THE ADVANCED SEARCH PAGE =over -=item 1. Efficiency - we have more control over objects inside the script, and it's possible to not duplicate things like indexes (if the search indexes were stored in the template they would need to be repeated) +=item 1. Efficiency - we have more control over objects inside the script, +and it's possible to not duplicate things like indexes (if the search indexes +were stored in the template they would need to be repeated) -=item 2. Customization - if these elements were moved to the sql database it would allow a simple librarian to determine which fields to display on the page without editing any html (also how the fields should behave when being searched). +=item 2. Customization - if these elements were moved to the sql database it +would allow a simple librarian to determine which fields to display on the page +without editing any html (also how the fields should behave when being searched). =back @@ -103,34 +107,46 @@ =head3 1. Building Query Strings =item 1 Koha query - the query that is passed to Zebra -This is the most complex query that needs to be built.The original design goal was to use a custom CCL2PQF query parser to translate an incoming CCL query into a multi-leaf query to pass to Zebra. It needs to be multi-leaf to allow field weighting, koha-specific relevance ranking, and stemming. When I have a chance I'll try to flesh out this section to better explain. +This is the most complex query that needs to be built. The original design goal +was to use a custom CCL2PQF query parser to translate an incoming CCL query into +a multi-leaf query to pass to Zebra. It needs to be multi-leaf to allow field +weighting, koha-specific relevance ranking, and stemming. When I have a chance +I'll try to flesh out this section to better explain. -This query incorporates query profiles that aren't compatible with non-Zebra Z39.50 targets to acomplish the field weighting and relevance ranking. +This query incorporates query profiles that aren't compatible with non-Zebra +Z39.50 targets to acomplish the field weighting and relevance ranking. =item 2 Federated query - the query that is passed to other Z39.50 targets -This query is just the user's query expressed in CCL CQL, or PQF for passing to a non-zebra Z39.50 target (one that doesn't support the extended profile that Zebra does). +This query is just the user's query expressed in CCL CQL, or PQF for passing to a +non-zebra Z39.50 target (one that doesn't support the extended profile that Zebra does). -=item 3 Search description - passed to the template / saved for future refinements of the query (by user) +=item 3 Search description - passed to the template / saved for future refinements of +the query (by user) -This is a simple string that completely expresses the query in a way that can be parsed by Koha for future refinements of the query or as a part of a history feature. It differs from the human search description in several ways: +This is a simple string that completely expresses the query in a way that can be parsed +by Koha for future refinements of the query or as a part of a history feature. It differs +from the human search description: 1. it does not contain commas or = signs -2. =item 4 Human search description - what the user sees in the search_desc area -This is a simple string nearly identical to the Search description, but more human readable. It will contain = signs or commas, etc. +This is a simple string nearly identical to the Search description, but more human +readable. It will contain = signs or commas, etc. =back =head3 2. Perform the Search -This section takes the query strings and performs searches on the named servers, including the Koha Zebra server, stores the results in a deeply nested object, builds 'faceted results', and returns these objects. +This section takes the query strings and performs searches on the named servers, including +the Koha Zebra server, stores the results in a deeply nested object, builds 'faceted results', +and returns these objects. =head3 3. Build HTML -The final major section of this script takes the objects collected thusfar and builds the HTML for output to the template and user. +The final major section of this script takes the objects collected thusfar and builds the +HTML for output to the template and user. =head3 Additional Notes @@ -161,12 +177,20 @@ =head3 Additional Notes # decide which template to use my $template_name; +my $template_type; my @params = $cgi->param("limit"); if ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) ) { $template_name = 'catalogue/results.tmpl'; } else { + # use a UNIMARC-specific template if UNIMARC + if (C4::Context->preference("marcflavour") eq "UNIMARC" ) { + $template_name = 'catalogue/advsearch_unimarc.tmpl'; + } + else { $template_name = 'catalogue/advsearch.tmpl'; + } + $template_type = 'advsearch'; } # load the template ($template, $borrowernumber, $cookie) = get_template_and_user({ @@ -187,10 +211,7 @@ =head1 BUGS and FIXMEs =cut ## URI Re-Writing -# FIXME: URI re-writing should be tested more carefully and may better -# handled by mod_rewrite or something else. The code below almost works, -# but doesn't quite handle limits correctly when they are the only -# param passed -- I'll work on this soon -- JF +# Deprecated, but preserved because it's interesting :-) #my $rewrite_flag; #my $uri = $cgi->url(-base => 1); #my $relative_url = $cgi->url(-relative=>1); @@ -198,7 +219,7 @@ =head1 BUGS and FIXMEs #warn "URI:$uri"; #my @cgi_params_list = $cgi->param(); #my $url_params = $cgi->Vars; - +# #for my $each_param_set (@cgi_params_list) { # $uri.= join "", map "\&$each_param_set=".$_, split("\0",$url_params->{$each_param_set}) if $url_params->{$each_param_set}; #} @@ -222,7 +243,7 @@ =head1 BUGS and FIXMEs $template->param(branchloop => \@branch_loop, searchdomainloop => $categories); -# load the itemtypes (Called Collection Codes in the template -- used for circ rules ) +# load the itemtypes my $itemtypes = GetItemTypes; my @itemtypesloop; my $selected=1; @@ -246,14 +267,10 @@ =head1 BUGS and FIXMEs # $template->param(itypeloop=>\@itype_loop,); # load the languages ( for switching from one template to another ) -# my @languages_options = displayLanguages($cgi); -# my $languages_count = @languages_options; -# if($languages_count > 1){ -# $template->param(languages => \@languages_options); -# } +$template->param(languages_loop => getTranslatedLanguages('intranet','prog')); # The following should only be loaded if we're bringing up the advanced search template -if ( $template_name eq "catalogue/advsearch.tmpl" ) { +if ( $template_type eq 'advsearch' ) { # load the servers (used for searching -- to do federated searching, etc.) my $primary_servers_loop;# = displayPrimaryServers(); $template->param(outer_servers_loop => $primary_servers_loop,); @@ -264,24 +281,31 @@ =head1 BUGS and FIXMEs # 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. - # FIXME: this stuff should be cleaned up a bit and the html should be turned - # into flags for the template -- I'll work on that soon -- JF my @search_boxes_array; - my $search_boxes_count = 1; # should be a syspref - for (my $i=0;$i<=$search_boxes_count;$i++) { - if ($i==0) { + my $search_boxes_count = C4::Context->preference("OPACAdvSearchInputCount") | 3; # FIXME: should be a syspref + 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, { - search_boxes_label => 1, scan_index => 1, }; } + # if it's the last one, show the 'add field' box elsif ($i==$search_boxes_count) { push @search_boxes_array, { - add_field => "1",}; + boolean => 1, + add_field => 1, + }; } + else { + push @search_boxes_array, + { + boolean => 1, + }; + } } $template->param(uc(C4::Context->preference("marcflavour")) => 1, @@ -291,14 +315,7 @@ =head1 BUGS and FIXMEs my $languages_limit_loop = getAllLanguages(); $template->param(search_languages_loop => $languages_limit_loop,); - my $expanded_options; - if (not defined $cgi->param('expanded_options')){ - $expanded_options = C4::Context->preference("expandedSearchOption"); - } - else { - $expanded_options = $cgi->param('expanded_options'); - } - $template->param(expanded_options => $expanded_options); + $template->param(expanded_options => $cgi->param('expanded_options') | C4::Context->preference("expandedSearchOption")); # load the sort_by options for the template my $sort_by = $cgi->param('sort_by'); diff --git a/changelanguage.pl b/changelanguage.pl new file mode 100755 index 00000000000..9a470aef646 --- /dev/null +++ b/changelanguage.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +use C4::Output; +use CGI; + +my $query = new CGI; +my $language = $query->param('language'); +my $url = $query->referer(); + +warn "Language : $query // $language // $url"; +setlanguagecookie( $query, $language, $url ); diff --git a/etc/zebradb/biblios/etc/bib1.att b/etc/zebradb/biblios/etc/bib1.att index 1bebbb3d5a4..201561e8ce0 100644 --- a/etc/zebradb/biblios/etc/bib1.att +++ b/etc/zebradb/biblios/etc/bib1.att @@ -148,12 +148,13 @@ att 8028 uri att 8029 replacementprice att 8030 replacementpricedate -# att 8001 Extent -# att 8910 Koha-Auth-Number +## Fixed Fields and other special indexes +att 9901 Extent +att 9910 Koha-Auth-Number # record length according to the leader -# att 8005 llength -#att 8002 Summary -#att 8900 Call-Number +att 9905 llength +att 9902 Summary +att 9990 Call-Number # Usually Target Audience 008/22 att 8822 ta # Usually Form of item 008/23 @@ -173,6 +174,6 @@ att 8701 ff7-01 att 8702 ff7-02 att 8703 ff7-01-02 # Author-personal-bibliography - lastname,firstname in 100$a -#att 8900 Author-personal-bibliography +att 9900 Author-personal-bibliography # Author-in-order - firstname lastname in 245$c statement of responsibility -#att 8901 Author-in-order +att 9902 Author-in-order diff --git a/etc/zebradb/biblios/etc/record.abs b/etc/zebradb/biblios/etc/record.abs index efb436aa211..9806ed10b89 100644 --- a/etc/zebradb/biblios/etc/record.abs +++ b/etc/zebradb/biblios/etc/record.abs @@ -1,5 +1,3 @@ -# $Id: record.abs,v 1.1.2.1 2006/05/08 14:42:49 tgarip1957 Exp $ - # This is a fairly simple example of a set of MARC21 indexing rules. It # results in a server which provides a passable Bath level 0 and 1 service # (author, title, subject, keyword and exact services). Feel free to diff --git a/etc/zebradb/ccl.properties b/etc/zebradb/ccl.properties index 034f2208649..54b8ae97e94 100644 --- a/etc/zebradb/ccl.properties +++ b/etc/zebradb/ccl.properties @@ -7,7 +7,7 @@ # q q1 q2 q3 # # 3. comments -# comments begin with +# comments begin with # # # 4. directives # @ directive value @@ -56,7 +56,7 @@ ab Abstract # of records selected is the union of the sets of records # selected by each of the (appropriate) Use attributes that # the target supports. -Any 4=6 1=1016 +Any 1=1016 kw Any #Anywhere 1035 The record is selected if the diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc index 3e4a4e8a886..5dadd7798a2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc @@ -1,5 +1,5 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch_unimarc.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch_unimarc.tmpl new file mode 100644 index 00000000000..7be5ff9cd1b --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch_unimarc.tmpl @@ -0,0 +1,571 @@ + +Koha › Catalogue › Advanced Search + + + + + + + +
+
+ +
+ +
+ + + + + + +
+ + +