[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-cvs] koha/C4 Search.pm [rel_3_0]
From: |
Antoine Farnault |
Subject: |
[Koha-cvs] koha/C4 Search.pm [rel_3_0] |
Date: |
Mon, 30 Oct 2006 11:23:07 +0000 |
CVSROOT: /sources/koha
Module name: koha
Branch: rel_3_0
Changes by: Antoine Farnault <toins> 06/10/30 11:23:06
Modified files:
C4 : Search.pm
Log message:
* new function : SimpleSearch.
($error,address@hidden) = SimpleSearch($query,@servers);
this function performs a simple search on the catalog using zoom.
* Sync with dev_week.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Search.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.120.2.17&r2=1.120.2.18
Patches:
Index: Search.pm
===================================================================
RCS file: /sources/koha/koha/C4/Search.pm,v
retrieving revision 1.120.2.17
retrieving revision 1.120.2.18
diff -u -b -r1.120.2.17 -r1.120.2.18
--- Search.pm 30 Oct 2006 09:52:01 -0000 1.120.2.17
+++ Search.pm 30 Oct 2006 11:23:06 -0000 1.120.2.18
@@ -39,7 +39,7 @@
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
# set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.120.2.17 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.120.2.18 $' =~ /\d+/g;
shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
=head1 NAME
@@ -66,6 +66,8 @@
&CatSearch
+&SimpleSearch
+
&BornameSearch &ItemInfo &KeywordSearch
&subsearch
@@ -2746,9 +2748,64 @@
# return(undef,$numresults,address@hidden,@results);
# }
+=item SimpleSearch
+
+($error,address@hidden) = SimpleSearch($query,@servers);
+
+this function performs a simple search on the catalog using zoom.
+
+C<input arg:>
+ * $query could be a simple keyword or a complete CCL query wich is
depending on your ccl file.
+ * @servers is optionnal. default one is read on koha.xml
+
+C<Output arg:>
+ * $error is a string which containt the description error if there is one.
Else it's empty.
+ * address@hidden is an array of marc record.
+
+=cut
+
+sub SimpleSearch {
+ my $query = shift;
+ my @servers = @_;
+ my @results;
+ my @tmpresults;
+ my @zconns;
+ return ("No query entered",undef) unless $query;
+
+ address@hidden = (C4::Context->config("biblioserver")) unless @servers;
+ @servers = ("biblioserver"); # FIXME hardcoded value. See
catalog/search.pl & opac-search.pl too.
+
+ # Connect & Search
+ for (my $i = 0; $i < @servers; $i++) {
+ $zconns[$i] = C4::Context->Zconn($servers[$i],1);
+ $tmpresults[$i] = $zconns[$i]->search(new
ZOOM::Query::CCL2RPN($query,$zconns[$i]));
+
+ # getting error message if one occured.
+ my $error = $zconns[$i]->errmsg()." (".$zconns[$i]->errcode().")
".$zconns[$i]->addinfo()." ".$zconns[$i]->diagset();
+
+ return ($error,undef) if $zconns[$i]->errcode();
+ }
+ my $hits;
+ my $ev;
+ while ((my $i = ZOOM::event(address@hidden)) != 0) {
+ $ev = $zconns[$i-1]->last_event();
+ if ($ev == ZOOM::Event::ZEND) {
+ $hits = $tmpresults[$i-1]->size();
+ }
+ if($hits > 0){
+ for(my $j=0;$j<$hits;$j++){
+ my $record = $tmpresults[$i-1]->record($j)->raw();
+ push @results, $record;
+ }
+ }
+ }
+ return (undef,address@hidden);
+}
+
# performs the search
sub getRecords {
my
($koha_query,$federated_query,$sort_by_ref,$servers_ref,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan)
= @_;
+
my @servers = @$servers_ref;
my @sort_by = @$sort_by_ref;
@@ -3030,8 +3087,11 @@
elsif ($index =~ /ti/) {
$weighted_query .= " Title-cover,ext,r1=$operand";
# index label as exact
$weighted_query .= " or Title-series,ext,r2=$operand";
+ #$weighted_query .= " or ti,ext,r2=$operand";
+ #$weighted_query .= " or ti,phr,r3=$operand";
+ #$weighted_query .= " or ti,wrd,r3=$operand";
$weighted_query .= " or (title-sort-az=0 or
Title-cover,startswithnt,st-word,r3=$operand #)";
- #$weighted_query .= " or (title-sort-az=0 or
Title-cover,phr,r4=$operand)";
+ $weighted_query .= " or (title-sort-az=0 or
Title-cover,phr,r6=$operand)";
#$weighted_query .= " or Title-cover,wrd,r5=$operand";
#$weighted_query .= " or ti,ext,r6=$operand";
#$weighted_query .= " or
ti,startswith,phr,r7=$operand";
@@ -3091,23 +3151,43 @@
my $limit_search_desc;
foreach my $limit (@limits) {
# FIXME: not quite right yet ... will work on this soon -- JF
+ my $type=$1 if $limit=~m/([^:]+):([^:]*)/;
if ($limit =~ /available/) {
- $limit_query.=" and (($query and datedue=0000-00-00) or ($query
and datedue=0000-00-00 not lost=1) or ($query and datedue=0000-00-00 not
lost=2))";
+ $limit_query.=" (($query and datedue=0000-00-00) or ($query and
datedue=0000-00-00 not lost=1) or ($query and datedue=0000-00-00 not lost=2))";
#$limit_search_desc.=" and available";
}
+ elsif (($limit_query) && (index($limit_query,$type,0)>0)) {
+ if ($limit_query!~/\(/){
+ $limit_query=
substr($limit_query,0,index($limit_query,$type,0))."(".substr($limit_query,index($limit_query,$type,0))."
or $limit )" if $limit;
+ $limit_search_desc=
substr($limit_search_desc,0,index($limit_search_desc,$type,0))."(".substr($limit_search_desc,index($limit_search_desc,$type,0))."
or $limit )" if $limit;
+ } else {
+ chop $limit_query;
+ chop $limit_search_desc;
+ $limit_query.=" or $limit )" if $limit;
+ $limit_search_desc.=" or $limit )" if $limit;
+ }
+ }
elsif (($limit_query) && ($limit =~/mc/)) {
$limit_query.=" or $limit" if $limit;
$limit_search_desc.=" or $limit" if $limit;
}
- elsif (($limit_query) || ($query)) {
+ # these are treated as AND
+ elsif ($limit_query) {
$limit_query.=" and $limit" if $limit;
$limit_search_desc.=" and $limit" if $limit;
}
+ # otherwise, there is nothing but the limit
else {
$limit_query.="$limit" if $limit;
$limit_search_desc.="$limit" if $limit;
}
}
+ # if there's also a query, we need to AND the limits to it
+ if (($limit_query) && ($query)) {
+ $limit_query=" and (".$limit_query.")";
+ $limit_search_desc=" and ($limit_search_desc)" if $limit_search_desc;
+
+ }
$query .= $limit_query;
$human_search_desc .= $limit_search_desc;
# now normalize the strings
@@ -3124,9 +3204,9 @@
$human_search_desc =~ s/ / /g;
$human_search_desc =~s/^ //g;
my $koha_query = $query;
-# warn "QUERY:".$koha_query;
-# warn "SEARCHDESC:".$human_search_desc;
-# warn "FEDERATED QUERY:".$federated_query;
+ #warn "QUERY:".$koha_query;
+ #warn "SEARCHDESC:".$human_search_desc;
+ #warn "FEDERATED QUERY:".$federated_query;
return (undef,$human_search_desc,$koha_query,$federated_query);
}
@@ -3148,7 +3228,7 @@
#find branchname
#get branch information.....
my %branches;
- my $bsth=$dbh->prepare("SELECT branchcode,branchname FROM branches");
+ my $bsth=$dbh->prepare("SELECT branchcode,branchname FROM branches"); #
FIXME : use C4::Koha::GetBranches
$bsth->execute();
while (my $bdata=$bsth->fetchrow_hashref){
$branches{$bdata->{'branchcode'}}= $bdata->{'branchname'};
- [Koha-cvs] koha/C4 Search.pm [rel_3_0], Antoine Farnault, 2006/10/16
- [Koha-cvs] koha/C4 Search.pm [rel_3_0], Antoine Farnault, 2006/10/16
- [Koha-cvs] koha/C4 Search.pm [rel_3_0], Antoine Farnault, 2006/10/20
- [Koha-cvs] koha/C4 Search.pm [rel_3_0], Antoine Farnault, 2006/10/23
- [Koha-cvs] koha/C4 Search.pm [rel_3_0], Antoine Farnault, 2006/10/23
- [Koha-cvs] koha/C4 Search.pm [rel_3_0], Antoine Farnault, 2006/10/23
- [Koha-cvs] koha/C4 Search.pm [rel_3_0], paul poulain, 2006/10/30
- [Koha-cvs] koha/C4 Search.pm [rel_3_0],
Antoine Farnault <=
- [Koha-cvs] koha/C4 Search.pm [rel_3_0], Antoine Farnault, 2006/10/31