From a2f1bf834f4d758a991266b577b85ed232218e0d Mon Sep 17 00:00:00 2001
From: tipaul
Date: Fri, 16 Apr 2004 07:28:22 +0000
Subject: [PATCH] improving Search : * adding "suggestion", that popup a
windows. The popup windows shows, for each word entered in the search form,
the 10 words that sounds like the word entered, and that are used most often.
* fixes some minor bugs
Still to do :
* good support of ' and ,
---
C4/SearchMarc.pm | 20 +-
.../default/en/search.marc/result.tmpl | 124 ++++-----
.../default/en/search.marc/search.tmpl | 249 ++++++++----------
.../default/en/search.marc/suggest.tmpl | 58 ++++
search.marc/search.pl | 45 +++-
search.marc/suggest.pl | 63 +++++
6 files changed, 350 insertions(+), 209 deletions(-)
create mode 100644 koha-tmpl/intranet-tmpl/default/en/search.marc/suggest.tmpl
create mode 100755 search.marc/suggest.pl
diff --git a/C4/SearchMarc.pm b/C4/SearchMarc.pm
index dcfa110fad..566f419466 100644
--- a/C4/SearchMarc.pm
+++ b/C4/SearchMarc.pm
@@ -52,10 +52,28 @@ on what is passed to it, it calls the appropriate search function.
=cut
@ISA = qw(Exporter);
-@EXPORT = qw(&catalogsearch &findseealso);
+@EXPORT = qw(&catalogsearch &findseealso &findsuggestion);
# make all your functions, whether exported or not;
+sub findsuggestion {
+ my ($dbh,$values) = @_;
+ my $sth = $dbh->prepare("SELECT count( * ) AS total, word FROM marc_word WHERE sndx_word = soundex( ? ) AND word <> ? GROUP BY word ORDER BY total DESC");
+ my @results;
+ for(my $i = 0 ; $i <= $#{$values} ; $i++) {
+ if (length(@$values[$i]) >=5) {
+ $sth->execute(@$values[$i],@$values[$i]);
+ my $resfound = 1;
+ my @resline;
+ while ((my ($count,$word) = $sth->fetchrow) and $resfound <=10) {
+ push @results, "@$values[$i]|$word|$count";
+# $results{@$values[$i]} = \@resline;
+ $resfound++;
+ }
+ }
+ }
+ return \@results;
+}
sub findseealso {
my ($dbh, $fields) = @_;
my $tagslib = MARCgettagslib ($dbh,1);
diff --git a/koha-tmpl/intranet-tmpl/default/en/search.marc/result.tmpl b/koha-tmpl/intranet-tmpl/default/en/search.marc/result.tmpl
index ea76f2e788..c3eb08ae09 100644
--- a/koha-tmpl/intranet-tmpl/default/en/search.marc/result.tmpl
+++ b/koha-tmpl/intranet-tmpl/default/en/search.marc/result.tmpl
@@ -4,86 +4,72 @@
+
+
+
+
+
+
+
+
diff --git a/search.marc/search.pl b/search.marc/search.pl
index ec8390b713..6ae359f403 100755
--- a/search.marc/search.pl
+++ b/search.marc/search.pl
@@ -30,6 +30,7 @@ use C4::Output;
use C4::Interface::CGI::Output;
use C4::Biblio;
use C4::SearchMarc;
+use C4::Catalogue;
use C4::Koha; # XXX subfield_is_koha_internal_p
# Creates the list of active tags using the active MARC configuration
@@ -182,7 +183,6 @@ if ($op eq "do_search") {
} else {
$to = (($startfrom+1)*$resultsperpage);
}
-
$template->param(result => $results,
startfrom=> $startfrom,
displaynext=> $displaynext,
@@ -194,7 +194,7 @@ if ($op eq "do_search") {
total=>$total,
from=>$from,
to=>$to,
- numbers=>\@numbers
+ numbers=>\@numbers,
);
} elsif ($op eq "AddStatement") {
@@ -297,8 +297,47 @@ else {
push @statements, { "marclist" => $marclist, "first" => 1 };
push @statements, { "marclist" => $marclist, "first" => 0 };
push @statements, { "marclist" => $marclist, "first" => 0 };
+ my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
+ $sth->execute;
+ my @itemtype;
+ my %itemtypes;
+ push @itemtype, "";
+ $itemtypes{''} = "";
+ while (my ($value,$lib) = $sth->fetchrow_array) {
+ push @itemtype, $value;
+ $itemtypes{$value}=$lib;
+ }
- $template->param("statements" => \@statements, "nbstatements" => 3);
+ my $CGIitemtype=CGI::scrolling_list( -name => 'value',
+ -values => \@itemtype,
+ -labels => \%itemtypes,
+ -size => 1,
+ -multiple => 0 );
+ $sth->finish;
+
+ my @branches;
+ my @select_branch;
+ my %select_branches;
+ my ($count2,@branches)=branches();
+ push @select_branch, "";
+ $select_branches{''} = "";
+ for (my $i=0;$i<$count2;$i++){
+ push @select_branch, $branches[$i]->{'branchcode'};#
+ $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
+ }
+ my $CGIbranch=CGI::scrolling_list( -name => 'value',
+ -values => \@select_branch,
+ -labels => \%select_branches,
+ -size => 1,
+ -multiple => 0 );
+ $sth->finish;
+
+
+ $template->param("statements" => \@statements,
+ "nbstatements" => 3,
+ CGIitemtype => $CGIitemtype,
+ CGIbranch => $CGIbranch,
+ );
}
diff --git a/search.marc/suggest.pl b/search.marc/suggest.pl
new file mode 100755
index 0000000000..0225863431
--- /dev/null
+++ b/search.marc/suggest.pl
@@ -0,0 +1,63 @@
+#!/usr/bin/perl
+# WARNING: 4-character tab stops here
+
+# Copyright 2000-2002 Katipo Communications
+#
+# 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 strict;
+require Exporter;
+use CGI;
+use C4::Auth;
+use HTML::Template;
+use C4::Context;
+use C4::Search;
+use C4::Auth;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Biblio;
+use C4::SearchMarc;
+use C4::Catalogue;
+use C4::Koha; # XXX subfield_is_koha_internal_p
+
+# Creates the list of active tags using the active MARC configuration
+my $query=new CGI;
+my $Q=$query->param('Q');
+my @words = split / /,$Q;
+my $dbh = C4::Context->dbh;
+
+my $suggestions = findsuggestion($dbh,\@words);
+my @loop_suggests;
+foreach my $line (@$suggestions) {
+ my ($word,$suggestion,$count) = split /\|/,$line;
+ push @loop_suggests, { word => $word, suggestion =>$suggestion, count => $count };
+}
+
+my ($template, $loggedinuser, $cookie)
+ = get_template_and_user({template_name => "search.marc/suggest.tmpl",
+ query => $query,
+ type => "intranet",
+ authnotrequired => 0,
+ flagsrequired => {editcatalogue => 1},
+ debug => 1,
+ });
+$template->param("loop" => \@loop_suggests);
+
+output_html_with_http_headers $query, $cookie, $template->output;
+1;
+# Local Variables:
+# tab-width: 4
+# End: