Field weighting applied to ranked searches. A new facets table in mysql db
This commit is contained in:
parent
7068b5f316
commit
df5492f167
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 <arensb at ooblick dot com>
|
|||
|
||||
=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
|
||||
#
|
||||
|
|
|
|||
10
C4/Koha.pm
10
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,
|
||||
|
|
|
|||
33
C4/Search.pm
33
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]="<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 @@ my $dbh=C4::Context->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{
|
||||
|
|
|
|||
Loading…
Reference in New Issue