[Koha-cvs] CVS: koha/C4 SearchMarc.pm,1.10,1.11

Paul POULAIN tipaul at users.sourceforge.net
Mon Mar 15 15:34:21 CET 2004


Update of /cvsroot/koha/koha/C4
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13724/C4

Modified Files:
	SearchMarc.pm 
Log Message:
introducing new features :
* search on non marc fields : the marc field is found by a sub in Biblio.pm
* ordering a search

This commit shows the sql in log. Pls test it's correctly indexed (using : explain <sql_in_log>)


Index: SearchMarc.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/SearchMarc.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** SearchMarc.pm	6 Mar 2004 20:26:13 -0000	1.10
--- SearchMarc.pm	15 Mar 2004 14:34:18 -0000	1.11
***************
*** 61,75 ****
  	my $tagslib = MARCgettagslib ($dbh,1);
  	for (my $i=0;$i<=$#{$fields};$i++) {
! 		my ($tag) =substr(@$fields[$i],1,4);
  		my ($subfield) =substr(@$fields[$i],4,1);
! 		warn "$tag / $subfield =>".$tagslib->{$tag}->{$subfield}->{seealso};
  	}
  }
  # marcsearch : search in the MARC biblio table.
  # everything is choosen by the user : what to search, the conditions...
  
  sub catalogsearch {
! 	my ($dbh, $tags, $and_or, $excluding, $operator, $value, $offset,$length) = @_;
! 	warn "=>@$tags / @$and_or, $excluding = $operator / $value";
  	# build the sql request. She will look like :
  	# select m1.bibid
--- 61,75 ----
  	my $tagslib = MARCgettagslib ($dbh,1);
  	for (my $i=0;$i<=$#{$fields};$i++) {
! 		my ($tag) =substr(@$fields[$i],1,3);
  		my ($subfield) =substr(@$fields[$i],4,1);
! 		@$fields[$i].=','.$tagslib->{$tag}->{$subfield}->{seealso} if ($tagslib->{$tag}->{$subfield}->{seealso});
  	}
  }
+ 
  # marcsearch : search in the MARC biblio table.
  # everything is choosen by the user : what to search, the conditions...
  
  sub catalogsearch {
! 	my ($dbh, $tags, $and_or, $excluding, $operator, $value, $offset,$length,$orderby) = @_;
  	# build the sql request. She will look like :
  	# select m1.bibid
***************
*** 80,84 ****
  	# "Normal" statements
  	my @normal_tags = ();
- #	my @normal_subfields = ();
  	my @normal_and_or = ();
  	my @normal_operator = ();
--- 80,83 ----
***************
*** 86,95 ****
  	# Extracts the NOT statements from the list of statements
  	my @not_tags = ();
- #	my @not_subfields = ();
  	my @not_and_or = ();
  	my @not_operator = ();
  	my @not_value = ();
  	my $any_not = 0;
! 
  	for(my $i = 0 ; $i <= $#{$value} ; $i++)
  	{
--- 85,93 ----
  	# Extracts the NOT statements from the list of statements
  	my @not_tags = ();
  	my @not_and_or = ();
  	my @not_operator = ();
  	my @not_value = ();
  	my $any_not = 0;
! 	$orderby = "biblio.title" unless $orderby;
  	for(my $i = 0 ; $i <= $#{$value} ; $i++)
  	{
***************
*** 103,107 ****
  					unless (C4::Context->stopwords->{uc($word)}) {	#it's NOT a stopword => use it. Otherwise, ignore
  						push @not_tags, @$tags[$i];
- #						push @not_subfields, @$subfields[$i];
  						push @not_and_or, "or"; # as request is negated, finds "foo" or "bar" if final request is NOT "foo" and "bar"
  						push @not_operator, @$operator[$i];
--- 101,104 ----
***************
*** 113,117 ****
  			{
  				push @not_tags, @$tags[$i];
- #				push @not_subfields, @$subfields[$i];
  				push @not_and_or, "or"; # as request is negated, finds "foo" or "bar" if final request is NOT "foo" and "bar"
  				push @not_operator, @$operator[$i];
--- 110,113 ----
***************
*** 126,131 ****
  				{
  					unless (C4::Context->stopwords->{uc($word)}) {	#it's NOT a stopword => use it. Otherwise, ignore
  						push @normal_tags, @$tags[$i];
- #						push @normal_subfields, @$subfields[$i];
  						push @normal_and_or, "and";	# assumes "foo" and "bar" if "foo bar" is entered
  						push @normal_operator, @$operator[$i];
--- 122,128 ----
  				{
  					unless (C4::Context->stopwords->{uc($word)}) {	#it's NOT a stopword => use it. Otherwise, ignore
+ 						my $tag = substr(@$tags[$i],0,3);
+ 						my $subf = substr(@$tags[$i],3,1);
  						push @normal_tags, @$tags[$i];
  						push @normal_and_or, "and";	# assumes "foo" and "bar" if "foo bar" is entered
  						push @normal_operator, @$operator[$i];
***************
*** 137,141 ****
  			{
  				push @normal_tags, @$tags[$i];
- #				push @normal_subfields, @$subfields[$i];
  				push @normal_and_or, @$and_or[$i];
  				push @normal_operator, @$operator[$i];
--- 134,137 ----
***************
*** 150,158 ****
  	my $sth;
  	if ($sql_where2) {
! 		$sth = $dbh->prepare("select distinct m1.bibid from $sql_tables where $sql_where2 and ($sql_where1)");
  	} else {
! 		$sth = $dbh->prepare("select distinct m1.bibid from $sql_tables where $sql_where1");
  	}
- 	warn "===> select distinct m1.bibid from $sql_tables where $sql_where2 and ($sql_where1)";
  	$sth->execute();
  	my @result = ();
--- 146,155 ----
  	my $sth;
  	if ($sql_where2) {
! 		$sth = $dbh->prepare("select distinct m1.bibid from biblio,biblioitems,marc_biblio,$sql_tables where biblio.biblionumber=marc_biblio.biblionumber and biblio.biblionumber=biblioitems.biblionumber and m1.bibid=marc_biblio.bibid and $sql_where2 and ($sql_where1) order by $orderby");
! 		warn "Q2 : select distinct m1.bibid from biblio,biblioitems,marc_biblio,$sql_tables where biblio.biblionumber=marc_biblio.biblionumber and biblio.biblionumber=biblioitems.biblionumber and m1.bibid=marc_biblio.bibid and $sql_where2 and ($sql_where1) order by $orderby";
  	} else {
! 		$sth = $dbh->prepare("select distinct m1.bibid from biblio,biblioitems,marc_biblio,$sql_tables where biblio.biblionumber=marc_biblio.biblionumber and biblio.biblionumber=biblioitems.biblionumber and m1.bibid=marc_biblio.bibid and $sql_where1 order by $orderby");
! 		warn "Q : select distinct m1.bibid from biblio,biblioitems,marc_biblio,$sql_tables where biblio.biblionumber=marc_biblio.biblionumber and biblio.biblionumber=biblioitems.biblionumber and m1.bibid=marc_biblio.bibid and $sql_where1 order by $orderby";
  	}
  	$sth->execute();
  	my @result = ();
***************
*** 171,174 ****
--- 168,172 ----
  		}
  		my $sth_not;
+ 		warn "NOT : select distinct m1.bibid from $not_sql_tables where $not_sql_where2 and ($not_sql_where1)";
  		if ($not_sql_where2) {
  			$sth_not = $dbh->prepare("select distinct m1.bibid from $not_sql_tables where $not_sql_where2 and ($not_sql_where1)");
***************
*** 176,180 ****
  			$sth_not = $dbh->prepare("select distinct m1.bibid from $not_sql_tables where $not_sql_where1");
  		}
- 
  		$sth_not->execute();
  
--- 174,177 ----





More information about the Koha-cvs mailing list