1 package C4::SearchMarc;
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
25 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
27 # set the version for version checking
32 C4::Search - Functions for searching the Koha MARC catalog
38 my ($count, @results) = catalogsearch();
42 This module provides the searching facilities for the Koha MARC catalog
44 C<&catalogsearch> is a front end to all the other searches. Depending
45 on what is passed to it, it calls the appropriate search function.
54 @EXPORT = qw(&catalogsearch);
55 # make all your functions, whether exported or not;
57 # marcsearch : search in the MARC biblio table.
58 # everything is choosen by the user : what to search, the conditions...
59 # FIXME this is a 1st version of the Marc Search. It does not use fulltext searching or marc_words table
62 my ($dbh, $tags, $subfields, $and_or, $excluding, $operator, $value, $offset,$length) = @_;
63 # build the sql request. She will look like :
65 # from marc_subfield_table as m1, marc_subfield_table as m2
66 # where m1.bibid=m2.bibid and
67 # (m1.subfieldvalue like "Des%" and m2.subfieldvalue like "27%")
69 my $sql_tables; # will contain marc_subfield_table as m1,...
70 my $sql_where1; # will contain the "true" where
71 my $sql_where2; # will contain m1.bibid=m2.bibid
73 warn "value : ".@$value;
74 for(my $i=0; $i<=@$value;$i++) {
77 if (@$operator[$i] eq "starts") {
78 $sql_tables .= "marc_subfield_table as m$nb,";
79 $sql_where1 .= "@$excluding[$i](m1.subfieldvalue like '@$value[$i]%'";
81 $sql_where1 .=" and m1.tag=@$tags[$i] and m1.subfieldcode='@$subfields[$i]'";
84 } elsif (@$operator[$i] eq "contains") {
85 $sql_tables .= "marc_word as m$nb,";
86 $sql_where1 .= "@$excluding[$i](m1.word ='@$value[$i]'";
88 $sql_where1 .=" and m1.tag=@$tags[$i] and m1.subfieldid='@$subfields[$i]'";
92 $sql_tables .= "marc_subfield_table as m$nb,";
93 $sql_where1 .= "@$excluding[$i](m1.subfieldvalue @$operator[$i] '@$value[$i]' ";
95 $sql_where1 .=" and m1.tag=@$tags[$i] and m1.subfieldcode='@$subfields[$i]'";
100 if (@$operator[$i] eq "starts") {
101 $sql_tables .= "marc_subfield_table as m$nb,";
102 $sql_where1 .= "@$and_or[$i] @$excluding[$i](m$nb.subfieldvalue like '@$value[$i]%'";
104 $sql_where1 .=" and m$nb.tag=@$tags[$i] and m$nb.subfieldcode='@$subfields[$i])";
107 $sql_where2 .= "m1.bibid=m$nb.bibid";
108 } elsif (@$operator[$i] eq "contains") {
109 $sql_tables .= "marc_word as m$nb,";
110 $sql_where1 .= "@$and_or[$i] @$excluding[$i](m$nb.word='@$value[$i]'";
112 $sql_where1 .=" and m$nb.tag=@$tags[$i] and m$nb.subfieldid='@$subfields[$i]'";
115 $sql_where2 .= "m1.bibid=m$nb.bibid";
117 $sql_tables .= "marc_subfield_table as m$nb,";
118 $sql_where1 .= "@$and_or[$i] @$excluding[$i](m$nb.subfieldvalue @$operator[$i] '@$value[$i]'";
120 $sql_where1 .=" and m$nb.tag=@$tags[$i] and m$nb.subfieldcode='@$subfields[$i]'";
122 $sql_where2 .= "m1.bibid=m$nb.bibid";
130 warn "select m1.bibid from $sql_tables where $sql_where2 and ($sql_where1)";
133 $sth = $dbh->prepare("select m1.bibid from $sql_tables where $sql_where2 and ($sql_where1)");
135 $sth = $dbh->prepare("select m1.bibid from $sql_tables where $sql_where1");
139 while (my ($bibid) = $sth->fetchrow) {
142 # we have bibid list. Now, loads title and author from [offset] to [offset]+[length]
143 my $counter = $offset;
144 $sth = $dbh->prepare("select author,title from biblio,marc_biblio where biblio.biblionumber=marc_biblio.biblionumber and bibid=?");
145 my @finalresult = ();
146 while ($counter <= ($offset + $length)) {
147 $sth->execute($result[$counter]);
148 my ($author,$title) = $sth->fetchrow;
150 $line{bibid}=$result[$counter];
151 $line{author}=$author;
153 push @finalresult, \%line;
159 END { } # module clean-up code here (global destructor)
168 Koha Developement team <info@koha.org>