Skip to content

Commit

Permalink
Searching Patch 1: fixing searching in 3.0
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Cormack <[email protected]>
Signed-off-by: Joshua Ferraro <[email protected]>
  • Loading branch information
Joshua Ferraro committed Oct 29, 2007
1 parent 30e6a55 commit 4559e0e
Show file tree
Hide file tree
Showing 10 changed files with 756 additions and 310 deletions.
4 changes: 2 additions & 2 deletions C4/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
103 changes: 60 additions & 43 deletions catalogue/search.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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({
Expand All @@ -187,18 +211,15 @@ =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);
#$uri.="/".$relative_url."?";
#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};
#}
Expand All @@ -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;
Expand All @@ -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,);
Expand All @@ -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,
Expand All @@ -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');
Expand Down
26 changes: 26 additions & 0 deletions changelanguage.pl
Original file line number Diff line number Diff line change
@@ -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 );
15 changes: 8 additions & 7 deletions etc/zebradb/biblios/etc/bib1.att
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 0 additions & 2 deletions etc/zebradb/biblios/etc/record.abs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions etc/zebradb/ccl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# q q1 q2 q3
#
# 3. comments
# comments begin with
# comments begin with #
#
# 4. directives
# @ directive value
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="header">

<div id="toplevelnav">
<ul id="toplevelmenu">
<!-- TMPL_IF NAME="CAN_user_circulate" --><li><a href="/cgi-bin/koha/circ/circulation-home.pl">Circulation</a></li><!-- /TMPL_IF -->
Expand Down
13 changes: 12 additions & 1 deletion koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
</div>

<!-- TMPL_IF NAME="languages_loop" -->
<div id="changelanguage">
<ul>
<!-- TMPL_LOOP NAME="languages_loop" -->
<li><a href="/cgi-bin/koha/changelanguage.pl?language=<!-- TMPL_VAR NAME="language_code" -->"><!-- TMPL_VAR NAME="language_name" --></a></li>
<!-- /TMPL_LOOP -->
</ul>
</div>
<!-- /TMPL_IF -->

</body>
</html>
</html>
Loading

0 comments on commit 4559e0e

Please sign in to comment.