From df5492f1673f6b31d4eebd2e30bf601298f81847 Mon Sep 17 00:00:00 2001 From: tgarip1957 Date: Sun, 1 Oct 2006 21:48:54 +0000 Subject: [PATCH] Field weighting applied to ranked searches. A new facets table in mysql db --- C4/AuthoritiesMarc.pm | 6 +++--- C4/Breeding.pm | 6 ++++-- C4/Circulation/Circ2.pm | 5 +++-- C4/Context.pm | 9 ++++++--- C4/Koha.pm | 10 +++++----- C4/Search.pm | 33 ++++++++++++++++++++++++--------- 6 files changed, 45 insertions(+), 24 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 8a293cc9e3..2975a38475 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -121,7 +121,7 @@ my $counter = $offset; $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 @@ $oConnection[0]->destroy(); 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 @@ my ($xml,$kohafield,$recordtype,$tag,$subf)=@_; #$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; diff --git a/C4/Breeding.pm b/C4/Breeding.pm index 6a509406d7..cccbdeab42 100644 --- a/C4/Breeding.pm +++ b/C4/Breeding.pm @@ -96,20 +96,22 @@ my $findbreedingid = $dbh->prepare("select max(id) from marc_breeding"); $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,@results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations); + + ($count,$facets,@results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations); } else { push @kohafields,"issn"; push @values,$oldbiblio->{issn}; push @relations,""; push @and_or,""; $sort=""; - ($count,@results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations); + ($count,$facets,@results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations); } } if ($count>0 && !$z3950random) { diff --git a/C4/Circulation/Circ2.pm b/C4/Circulation/Circ2.pm index 6172007c99..ffb0baee28 100755 --- a/C4/Circulation/Circ2.pm +++ b/C4/Circulation/Circ2.pm @@ -237,20 +237,21 @@ sub listitemsforinventory { 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,@results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations,$sort,\@and_or,0,"",$offset,$size); + ($count,$facets,@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,@results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations,$sort,\@and_or,0,"",$offset,$size); + ($count,$facets,@results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations,$sort,\@and_or,0,"",$offset,$size); } return @results; diff --git a/C4/Context.pm b/C4/Context.pm index be8e8687a0..5626ca53cd 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -652,11 +652,11 @@ sub _new_attrfromkohafield { 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 @@ Andrew Arensburger =cut # $Log$ +# 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 # diff --git a/C4/Koha.pm b/C4/Koha.pm index 51a406091c..d7ca7d35d0 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -916,18 +916,18 @@ sub getFacets { ###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,@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, diff --git a/C4/Search.pm b/C4/Search.pm index 40b1fa0814..b65381bf84 100755 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -93,11 +93,11 @@ my $i; 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 @@ if (@sortpart){ }elsif ($sortpart[1]==1){ $sortpart[1]="dbh; return ($numresults,$facets,@parsed) ; } }# if numresults -EXITING: + $oResult->destroy(); $oConnection[0]->destroy(); +EXITING: return ($numresults,@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{ -- 2.39.5