[Koha-cvs] koha/C4 AuthoritiesMarc.pm Breeding.pm Context....

Tumer Garip tgarip at neu.edu.tr
Sun Oct 1 23:48:54 CEST 2006


CVSROOT:	/sources/koha
Module name:	koha
Changes by:	Tumer Garip <tgarip1957>	06/10/01 21:48:54

Modified files:
	C4             : AuthoritiesMarc.pm Breeding.pm Context.pm 
	                 Koha.pm Search.pm 
	C4/Circulation : Circ2.pm 

Log message:
	Field weighting applied to ranked searches. A new facets table in mysql db

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/AuthoritiesMarc.pm?cvsroot=koha&r1=1.35&r2=1.36
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Breeding.pm?cvsroot=koha&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Context.pm?cvsroot=koha&r1=1.47&r2=1.48
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Koha.pm?cvsroot=koha&r1=1.44&r2=1.45
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Search.pm?cvsroot=koha&r1=1.124&r2=1.125
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Circulation/Circ2.pm?cvsroot=koha&r1=1.119&r2=1.120

Patches:
Index: AuthoritiesMarc.pm
===================================================================
RCS file: /sources/koha/koha/C4/AuthoritiesMarc.pm,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- AuthoritiesMarc.pm	29 Sep 2006 16:14:25 -0000	1.35
+++ AuthoritiesMarc.pm	1 Oct 2006 21:48:54 -0000	1.36
@@ -121,7 +121,7 @@
 $length=10 unless $length;
 my @oAuth;
 my $i;
- $oAuth[0]=C4::Context->Zconn("authorityserver",1,1);
+ $oAuth[0]=C4::Context->Zconnauth("authorityserver");
 my ($mainentry)=MARCfind_attr_from_kohafield("mainentry");
 my ($allentry)=MARCfind_attr_from_kohafield("allentry");
 
@@ -738,7 +738,7 @@
 		if ($update==1){
 		my $biblionumber=XML_readline_onerecord($xmlhash,"biblionumber","biblios");
 		my $frameworkcode=MARCfind_frameworkcode($dbh,$biblionumber);
-		ModBiblio($dbh,$biblionumber,$xmlhash,$frameworkcode) ;
+		NEWmodbiblio($dbh,$biblionumber,$xmlhash,$frameworkcode) ;
 		}
 		
      }#foreach $xmlhash
@@ -811,7 +811,7 @@
 #$xml represents one record of MARCXML as perlhashed 
 ## returns an array of read fields--useful for reading repeated fields
 ### $recordtype is needed for mapping the correct field if supplied
-### If only $tag is give reads the whole tag
+### If only $tag is given reads the whole tag
 ###Returns subfieldcodes as well
 my @value;
  ($tag,$subf)=MARCfind_marc_from_kohafield($kohafield,$recordtype) if $kohafield;
@@ -847,7 +847,7 @@
 
 =cut
 
-# $Id: AuthoritiesMarc.pm,v 1.35 2006/09/29 16:14:25 kados Exp $
+# $Id: AuthoritiesMarc.pm,v 1.36 2006/10/01 21:48:54 tgarip1957 Exp $
 
 # Revision 1.30  2006/09/06 16:21:03  tgarip1957
 # Clean up before final commits

Index: Breeding.pm
===================================================================
RCS file: /sources/koha/koha/C4/Breeding.pm,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- Breeding.pm	1 Sep 2006 22:16:00 -0000	1.11
+++ Breeding.pm	1 Oct 2006 21:48:54 -0000	1.12
@@ -96,20 +96,22 @@
 			$oldbiblio->{issn} = substr($oldbiblio->{issn},0,10);
 			# search if biblio exists
 			my $biblioitemnumber;
+			my $facets;
 		    if ( !$z3950random){
 			if ($oldbiblio->{isbn}) {
 			push @kohafields,"isbn";
 			push @values,$oldbiblio->{isbn};
 			push @relations,"";
 			push @and_or,"";
-			($count, at results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations);
+			
+			($count,$facets, at results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations);
 			} else {
 			push @kohafields,"issn";
 			push @values,$oldbiblio->{issn};
 			push @relations,"";
 			push @and_or,"";
 			$sort="";
-			($count, at results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations);
+			($count,$facets, at results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations);
 			}
 	    	     }
 			if ($count>0 && !$z3950random) {

Index: Context.pm
===================================================================
RCS file: /sources/koha/koha/C4/Context.pm,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -b -r1.47 -r1.48
--- Context.pm	27 Sep 2006 19:53:52 -0000	1.47
+++ Context.pm	1 Oct 2006 21:48:54 -0000	1.48
@@ -15,7 +15,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: Context.pm,v 1.47 2006/09/27 19:53:52 tgarip1957 Exp $
+# $Id: Context.pm,v 1.48 2006/10/01 21:48:54 tgarip1957 Exp $
 package C4::Context;
 use strict;
 use DBI;
@@ -25,7 +25,7 @@
 	qw($context),
 	qw(@context_stack);
 
-$VERSION = do { my @v = '$Revision: 1.47 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.48 $' =~ /\d+/g;
 		shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 =head1 NAME
@@ -652,11 +652,11 @@
 {
 	my $dbh = C4::Context->dbh;
 	my $attrfromkohafield;
-	my $sth2 = $dbh->prepare("select kohafield,attr,extraattr from koha_attr" );
+	my $sth2 = $dbh->prepare("select kohafield,attr from koha_attr" );
 	$sth2->execute;
-	while (my ($kohafield,$attr,$extra) = $sth2->fetchrow) {
+	while (my ($kohafield,$attr) = $sth2->fetchrow) {
 		my $retval = {};
-		$attrfromkohafield->{$kohafield} = "\@attr 1=".$attr." ".$extra;
+		$attrfromkohafield->{$kohafield} = $attr;
 	}
 	return $attrfromkohafield;
 }
@@ -832,6 +832,9 @@
 
 =cut
 # $Log: Context.pm,v $
+# Revision 1.48  2006/10/01 21:48:54  tgarip1957
+# Field weighting applied to ranked searches. A new facets table in mysql db
+#
 # Revision 1.47  2006/09/27 19:53:52  tgarip1957
 # Finalizing main components. All koha modules are now working with the new XML API
 #

Index: Koha.pm
===================================================================
RCS file: /sources/koha/koha/C4/Koha.pm,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -b -r1.44 -r1.45
--- Koha.pm	27 Sep 2006 19:53:52 -0000	1.44
+++ Koha.pm	1 Oct 2006 21:48:54 -0000	1.45
@@ -17,7 +17,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: Koha.pm,v 1.44 2006/09/27 19:53:52 tgarip1957 Exp $
+# $Id: Koha.pm,v 1.45 2006/10/01 21:48:54 tgarip1957 Exp $
 
 use strict;
 require Exporter;
@@ -25,7 +25,7 @@
 use C4::Biblio;
 use vars qw($VERSION @ISA @EXPORT);
 
-$VERSION = do { my @v = '$Revision: 1.44 $' =~ /\d+/g; shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
+$VERSION = do { my @v = '$Revision: 1.45 $' =~ /\d+/g; shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 =head1 NAME
 
@@ -916,18 +916,18 @@
 ###Subfields is an array as well although MARC21 has them all in "a" in case UNIMARC has differing subfields
 my $dbh=C4::Context->dbh;
 my @facets;
-my $sth=$dbh->prepare("SELECT  facets_label,attr FROM koha_attr  where (facets_label<>'' ) group by facets_label");
-my $sth2=$dbh->prepare("SELECT * FROM koha_attr where facets_label=?");
+my $sth=$dbh->prepare("SELECT  facets_label,kohafield FROM facets  where (facets_label<>'' ) group by facets_label");
+my $sth2=$dbh->prepare("SELECT * FROM facets where facets_label=?");
 $sth->execute();
-while (my ($label,$attr)=$sth->fetchrow){
+while (my ($label,$kohafield)=$sth->fetchrow){
  $sth2->execute($label);
 my (@tags, at subfield);
 	while (my $data=$sth2->fetchrow_hashref){
 	push @tags,$data->{tagfield} ;
-	push @subfield,$data->{tagsubfield} ;
+	push @subfield,$data->{subfield} ;
 	}
    	 my $facet =  {
-      	 link_value =>"kohafield=$attr",
+      	 link_value =>"kohafield=$kohafield",
         	label_value =>$label,
         	tags => \@tags,
         	subfield =>\@subfield,

Index: Search.pm
===================================================================
RCS file: /sources/koha/koha/C4/Search.pm,v
retrieving revision 1.124
retrieving revision 1.125
diff -u -b -r1.124 -r1.125
--- Search.pm	27 Sep 2006 19:53:52 -0000	1.124
+++ Search.pm	1 Oct 2006 21:48:54 -0000	1.125
@@ -32,7 +32,7 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.124 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.125 $' =~ /\d+/g;
           shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 =head1 NAME
@@ -93,11 +93,11 @@
      unless($searchtype){
 	for ( $i=0; $i<=$#{$value}; $i++){
 	next if (@$value[$i] eq "");
-
 	my $keyattr=MARCfind_attr_from_kohafield(@$kohafield[$i]) if (@$kohafield[$i]);
 	if (!$keyattr){$keyattr=" \@attr 1=any";}
 	@$value[$i]=~ s/(\.|\?|\;|\=|\/|\\|\||\:|\*|\!|\,|\(|\)|\[|\]|\{|\}|\/)/ /g;
-	$query.=@$relation[$i]." ".$keyattr." \"".@$value[$i]."\" " if @$value[$i];
+	my $weighted=weightRank(@$kohafield[$i],@$value[$i],$i) unless($sort || $reorder);
+	$query.=$weighted.@$relation[$i]." ".$keyattr." \"".@$value[$i]."\" " if @$value[$i];
 	}
 	for (my $z= 0;$z<=$#{$and_or};$z++){
 	$query=@$and_or[$z]." ".$query if (@$value[$z+1] ne "");
@@ -124,11 +124,6 @@
 	}elsif ($sortpart[1]==1){
 	$sortpart[1]="<i"; ##Ascending
 	}
-}else{
- unless($query=~/4=109/){ ###ranked sort not valid for numeric fields
-##Use Ranked sort
-$query="\@attr 2=102 ".$query;
-}
 }
 
 if ($searchtype){
@@ -191,16 +186,36 @@
 			return ($numresults,$facets, at parsed)  ;
 			}
     }# if numresults
-EXITING:
+
 $oResult->destroy();
 $oConnection[0]->destroy();
+EXITING:
 return ($numresults, at results)  ;
 }
 
+sub weightRank {
+my ($kohafield,$value,$i)=@_;
+### If a multi query is received weighting is reduced from 1st query being highest rank to last query being lowest;
+my $weighted;
+my $weight=1000 -($i*100);
+$weight=100 if $weight==0;
+	return "" if $value eq "";
+	my $keyattr=MARCfind_attr_from_kohafield($kohafield) if ($kohafield);
+	return "" if($keyattr=~/4=109/ || $keyattr=~/4=4/ || $keyattr=~/4=5/); ###ranked sort not valid for numeric fields
+	my $fullfield; ### not all indexes are Complete-field. Use only for title||author
+	if ($kohafield eq "title" || $kohafield eq "" || $kohafield eq "any"){
+	$keyattr=" \@attr 1=title-cover";
+ 	$fullfield="\@attr 6=3 ";
+	}elsif ($kohafield eq "author"){
+	$fullfield="\@attr 6=3 ";
+	}
+	$weighted.="\@attr 2=102 ".$keyattr." \@attr 3=1 $fullfield  \@attr 9=$weight \"".$value."\" " ;
+      $weighted=" \@or ".$weighted;
+  return $weighted;
+}
 sub convertPQF{
 # Convert CCL, CQF or PQF to ZEBRA RPN queries,trap errors
 my ($search_type,$zconn,$query)=@_;
-
 my $pqf_query;
 if ($search_type eq "pqf"){
 eval{

Index: Circulation/Circ2.pm
===================================================================
RCS file: /sources/koha/koha/C4/Circulation/Circ2.pm,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -b -r1.119 -r1.120
--- Circulation/Circ2.pm	27 Sep 2006 19:53:52 -0000	1.119
+++ Circulation/Circ2.pm	1 Oct 2006 21:48:54 -0000	1.120
@@ -3,7 +3,7 @@
 
 package C4::Circulation::Circ2;
 
-# $Id: Circ2.pm,v 1.119 2006/09/27 19:53:52 tgarip1957 Exp $
+# $Id: Circ2.pm,v 1.120 2006/10/01 21:48:54 tgarip1957 Exp $
 
 #package to deal with Returns
 #written 3/11/99 by olwen at katipo.co.nz
@@ -237,20 +237,21 @@
 	my @relations;
 	my $sort;
 	my @and_or;
+	my $facets;
 	if ($datelastseen){
 		push @kohafields, "classification","datelastseen";
 		push @values,$minlocation,$datelastseen;
 		push @relations,"\@attr 5=1  \@attr 6=3 \@attr 4=1 ","\@attr 2=1 ";
 		push @and_or,"\@and";
 		$sort="lcsort";
-		($count, at results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations,$sort,\@and_or,0,"",$offset,$size);
+		($count,$facets, at results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations,$sort,\@and_or,0,"",$offset,$size);
 	}else{
 	push @kohafields, "classification";
 		push @values,$minlocation;
 		push @relations,"\@attr 5=1  \@attr 6=3 \@attr 4=1 ";
 		push @and_or,"";
 		$sort="lcsort";
-		($count, at results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations,$sort,\@and_or,0,"",$offset,$size);
+		($count,$facets, at results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations,$sort,\@and_or,0,"",$offset,$size);
 	}
 	
 	return @results;





More information about the Koha-cvs mailing list