Koha Top query summary: User query something via hiddin modthod. Keywords will recorded in databases.It will help user when he/ she query catalog. enviroments: koha 2.2.5 & koha 2.2.7 (templete for npl) modfied files: perl scripts - opac-search.pl、opac-main.pl tmpl - opac-main.tmpl database - create Cookie table 1. Cookie table CREATE TABLE `cookie` ( `id` int(255) NOT NULL auto_increment, `names` text NOT NULL, `counts` int(255) NOT NULL default '1', PRIMARY KEY (`id`), KEY `blbnoidx` (`id`) ) ENGINE=MyISAM ; 2. opac-search.pl if ($op eq "do_search") { ...... my @tags; ..... # put into cookie for my $count (@value) { my $dbh=C4::Context->dbh; $sth = $dbh->prepare("insert into cookie(names) values (?)"); $sth->execute($count) || die $sth->errstr; } 3. opac-main.pl my $dbh = C4::Context->dbh; my $top="Select names,SUM(counts) \"co\" from cookie group by names order by co desc limit 0 , 10"; my $sth=$dbh->prepare($top); $sth->execute; my @top; my $top; while (my ($names,$counts) = $sth->fetchrow_array) { my %rows = ( searchterm => $names, counts => $counts, ); push @top, \%rows; } $sth->finish; $template->param(top => \@top); 4. opac-main.tmpl <form action="/cgi-bin/koha/opac-search.pl"> ..... <input size="27" name="value" id="value" type="text"></p> # add <!-- //top // --> <p> Top query keywords: <!-- TMPL_LOOP name="top" --> <a href="/cgi-bin/koha/opac-search.pl?op=do_search&type=opac&marclist=&and_or=and&excluding=&operator=contains&value= <!-- TMPL_VAR name="searchterm" -->"><!-- TMPL_VAR name="searchterm" --></a> (<!-- TMPL_VAR name="counts" -->) <!-- /TMPL_LOOP --> 5. demo site http://lit145.lacc.fju.edu.tw http://koha.nkes.ntct.edu.tw http://koha.jente.edu.tw 6.chinese information http://koha.wikispaces.com/query ___________________________________________________ 您的生活即時通 - 溝通、娛樂、生活、工作一次搞定! http://messenger.yahoo.com.tw/
long_sam.tw a écrit :
Koha Top query
Hi long_sam,
summary: User query something via hiddin modthod. Keywords will recorded in databases.It will help user when he/ she query catalog.
enviroments: koha 2.2.5 & koha 2.2.7 (templete for npl)
modfied files: perl scripts - opac-search.pl、opac-main.pl tmpl - opac-main.tmpl database - create Cookie table
Nice feature, but I won't add it in official trunk for at least 2 reasons : - it does not use our coding guidelines that says "no SQL query in a .pl script, only in a .pm package". Thus, you should have done a C4/Queries.pm package. - it seems strange to me : you have a counts row in cookie table (I would have choosen another name for this table, but that's a little note), but only store 1 in the row. The best solution, would be to increment the counter row (update ... set counts=counts+1), while you create one every time. You'll get a huge query in the long term... however, I keep the feature in my mind, maybe i'll add it in 3.0 in the future (no promise ;-) ) -- Paul POULAIN et Henri Damien LAURENT Consultants indépendants en logiciels libres et bibliothéconomie (http://www.koha-fr.org) Tel : 04 91 31 45 19
participants (2)
-
long_sam.tw -
Paul POULAIN