Browse Source

Bug 7440 - Remove NoZebra vestiges

Removed NoZebra vestiges. This comprises several code blocks that depend on the NoZebra syspref and NZ related functions/methods.

C4::Biblio->
 GetNoZebraIndexes
 _DelBiblioNoZebra
 _AddBiblioNoZebra

C4::Search->
 NZgetRecords
 NZanalyse
 NZoperatorAND
 NZoperatorOR
 NZoperatorNOT
 NZorder

C4::Installer->
 set_indexing_engine

Sponsored-by: Universidad Nacional de Córdoba
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
3.12.x
Tomás Cohen Arazi 10 years ago
committed by Jared Camins-Esakov
parent
commit
4dcee58a4d
  1. 1
      C4/Auth.pm
  2. 462
      C4/AuthoritiesMarc.pm
  3. 379
      C4/Biblio.pm
  4. 26
      C4/Installer.pm
  5. 28
      C4/Items.pm
  6. 738
      C4/Search.pm
  7. 3
      INSTALL.fedora7
  8. 2
      about.pl
  9. 16
      catalogue/search.pl
  10. 14
      installer/data/mysql/kohastructure.sql
  11. 2
      installer/data/mysql/ru-RU/mandatory/system_preferences_full_optimal_for_install_only.sql
  12. 2
      installer/data/mysql/ru-RU/mandatory/system_preferences_optimal_values_insert_only.sql
  13. 3
      installer/data/mysql/sysprefs.sql
  14. 28
      installer/data/mysql/uk-UA/mandatory/system_preferences_full_optimal_for_install_only.sql
  15. 28
      installer/data/mysql/uk-UA/mandatory/system_preferences_optimal_values_insert_only.sql
  16. 1
      installer/install.pl
  17. 1
      koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc
  18. 5
      koha-tmpl/intranet-tmpl/prog/en/modules/about.tt
  19. 2
      koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt
  20. 40
      koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt
  21. 343
      misc/migration_tools/rebuild_nozebra.pl
  22. 4
      misc/migration_tools/rebuild_zebra.pl
  23. 7
      opac/opac-search.pl
  24. 4
      t/db_dependent/Search.t
  25. 8
      t/db_dependent/lib/KohaTest.pm
  26. 3
      t/db_dependent/lib/KohaTest/Biblio.pm
  27. 72
      t/db_dependent/lib/KohaTest/Biblio/GetNoZebraIndexes.pm
  28. 1
      t/db_dependent/lib/KohaTest/Installer.pm
  29. 6
      t/db_dependent/lib/KohaTest/Search.pm
  30. 235
      t/db_dependent/lib/KohaTest/Search/NoZebra.pm

1
C4/Auth.pm

@ -362,7 +362,6 @@ sub get_template_and_user {
suggestion => C4::Context->preference("suggestion"),
virtualshelves => C4::Context->preference("virtualshelves"),
StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"),
NoZebra => C4::Context->preference('NoZebra'),
EasyAnalyticalRecords => C4::Context->preference('EasyAnalyticalRecords'),
LocalCoverImages => C4::Context->preference('LocalCoverImages'),
OPACLocalCoverImages => C4::Context->preference('OPACLocalCoverImages'),

462
C4/AuthoritiesMarc.pm

@ -109,305 +109,213 @@ sub SearchAuthorities {
my ($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby,$skipmetadata) = @_;
# warn Dumper($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby);
my $dbh=C4::Context->dbh;
if (C4::Context->preference('NoZebra')) {
#
# build the query
#
my $query;
my $query;
my $qpquery = '';
my $QParser;
$QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
my $attr = '';
# the marclist may contain "mainentry". In this case, search the tag_to_report, that depends on
# the authtypecode. Then, search on $a of this tag_to_report
# also store main entry MARC tag, to extract it at end of search
my $mainentrytag;
##first set the authtype search and may be multiple authorities
if ($authtypecode) {
my $n=0;
my @authtypecode;
my @auths=split / /,$authtypecode ;
foreach my $auth (@auths){
$query .="AND auth_type= $auth ";
$query .=" \@attr 1=authtype \@attr 5=100 ".$auth; ##No truncation on authtype
push @authtypecode ,$auth;
$n++;
}
$query =~ s/^AND //;
my $dosearch;
for(my $i = 0 ; $i <= $#{$value} ; $i++)
{
if (@$value[$i]){
if (@$tags[$i] =~/mainentry|mainmainentry/) {
$query .= qq( AND @$tags[$i] );
} else {
$query .=" AND ";
}
if (@$operator[$i] eq 'is') {
$query.=(@$tags[$i]?"=":""). '"'.@$value[$i].'"';
}elsif (@$operator[$i] eq "="){
$query.=(@$tags[$i]?"=":""). '"'.@$value[$i].'"';
}elsif (@$operator[$i] eq "start"){
$query.=(@$tags[$i]?"=":"").'"'.@$value[$i].'%"';
} else {
$query.=(@$tags[$i]?"=":"").'"'.@$value[$i].'%"';
}
$dosearch=1;
}#if value
if ($n>1){
while ($n>1){$query= "\@or ".$query;$n--;}
}
#
# do the query (if we had some search term
#
if ($dosearch) {
# warn "QUERY : $query";
my $result = C4::Search::NZanalyse($query,'authorityserver');
# warn "result : $result";
my %result;
foreach (split /;/,$result) {
my ($authid,$title) = split /,/,$_;
# hint : the result is sorted by title.biblionumber because we can have X biblios with the same title
# and we don't want to get only 1 result for each of them !!!
# hint & speed improvement : we can order without reading the record
# so order, and read records only for the requested page !
$result{$title.$authid}=$authid;
if ($QParser) {
$qpquery .= '(authtype:' . join('|| authtype:', @auths) . ')';
}
}
my $dosearch;
my $and=" \@and " ;
my $q2;
my $attr_cnt = 0;
for(my $i = 0 ; $i <= $#{$value} ; $i++)
{
if (@$value[$i]){
if ( @$tags[$i] eq "mainmainentry" ) {
$attr = " \@attr 1=Heading-Main ";
}
# sort the hash and return the same structure as GetRecords (Zebra querying)
my @listresult = ();
my $numbers=0;
if ($sortby eq 'HeadingDsc') { # sort by mainmainentry desc
foreach my $key (sort {$b cmp $a} (keys %result)) {
push @listresult, $result{$key};
# warn "push..."$#finalresult;
$numbers++;
}
} else { # sort by mainmainentry ASC
foreach my $key (sort (keys %result)) {
push @listresult, $result{$key};
# warn "push..."$#finalresult;
$numbers++;
}
elsif ( @$tags[$i] eq "mainentry" ) {
$attr = " \@attr 1=Heading ";
}
# limit the $results_per_page to result size if it's more
$length = $numbers-$offset if $numbers < ($offset+$length);
# for the requested page, replace authid by the complete record
# speed improvement : avoid reading too much things
my @finalresult;
for (my $counter=$offset;$counter<=$offset+$length-1;$counter++) {
# $finalresult[$counter] = GetAuthority($finalresult[$counter])->as_usmarc;
my $separator=C4::Context->preference('authoritysep');
my $authrecord =GetAuthority($listresult[$counter]);
my $authid=$listresult[$counter];
my $summary=BuildSummary($authrecord,$authid,$authtypecode);
my $query_auth_tag = "SELECT auth_tag_to_report FROM auth_types WHERE authtypecode=?";
my $sth = $dbh->prepare($query_auth_tag);
$sth->execute($authtypecode);
my $auth_tag_to_report = $sth->fetchrow;
my %newline;
$newline{used}=CountUsage($authid);
$newline{summary} = $summary;
$newline{authid} = $authid;
$newline{even} = $counter % 2;
push @finalresult, \%newline;
elsif ( @$tags[$i] eq "match" ) {
$attr = " \@attr 1=Match ";
}
return (\@finalresult, $numbers);
} else {
return;
}
} else {
my $query;
my $qpquery = '';
my $QParser;
$QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
my $attr = '';
# the marclist may contain "mainentry". In this case, search the tag_to_report, that depends on
# the authtypecode. Then, search on $a of this tag_to_report
# also store main entry MARC tag, to extract it at end of search
my $mainentrytag;
##first set the authtype search and may be multiple authorities
if ($authtypecode) {
my $n=0;
my @authtypecode;
my @auths=split / /,$authtypecode ;
foreach my $auth (@auths){
$query .=" \@attr 1=authtype \@attr 5=100 ".$auth; ##No truncation on authtype
push @authtypecode ,$auth;
$n++;
elsif ( @$tags[$i] eq "match-heading" ) {
$attr = " \@attr 1=Match-heading ";
}
elsif ( @$tags[$i] eq "see-from" ) {
$attr = " \@attr 1=Match-heading-see-from ";
}
elsif ( @$tags[$i] eq "thesaurus" ) {
$attr = " \@attr 1=Subject-heading-thesaurus ";
}
else { # Assume any if no index was specified
$attr = " \@attr 1=Any ";
}
if ( @$operator[$i] eq 'is' ) {
$attr .= " \@attr 4=1 \@attr 5=100 "
; ##Phrase, No truncation,all of subfield field must match
}
elsif ( @$operator[$i] eq "=" ) {
$attr .= " \@attr 4=107 "; #Number Exact match
}
elsif ( @$operator[$i] eq "start" ) {
$attr .= " \@attr 3=2 \@attr 4=1 \@attr 5=1 "
; #Firstinfield Phrase, Right truncated
}
elsif ( @$operator[$i] eq "exact" ) {
$attr .= " \@attr 4=1 \@attr 5=100 \@attr 6=3 "
; ##Phrase, No truncation,all of subfield field must match
}
if ($n>1){
while ($n>1){$query= "\@or ".$query;$n--;}
else {
$attr .= " \@attr 5=1 \@attr 4=6 "
; ## Word list, right truncated, anywhere
if ($sortby eq 'Relevance') {
$attr .= "\@attr 2=102 ";
}
}
@$value[$i] =~ s/"/\\"/g; # Escape the double-quotes in the search value
$attr =$attr."\"".@$value[$i]."\"";
$q2 .=$attr;
$dosearch=1;
++$attr_cnt;
if ($QParser) {
$qpquery .= '(authtype:' . join('|| authtype:', @auths) . ')';
$qpquery .= " $tags->[$i]:\"$value->[$i]\"";
}
}#if value
}
##Add how many queries generated
if (defined $query && $query=~/\S+/){
$query= $and x $attr_cnt . $query . (defined $q2 ? $q2 : '');
} else {
$query= $q2;
}
## Adding order
#$query=' @or @attr 7=2 @attr 1=Heading 0 @or @attr 7=1 @attr 1=Heading 1'.$query if ($sortby eq "HeadingDsc");
my $orderstring;
if ($sortby eq 'HeadingAsc') {
$orderstring = '@attr 7=1 @attr 1=Heading 0';
} elsif ($sortby eq 'HeadingDsc') {
$orderstring = '@attr 7=2 @attr 1=Heading 0';
} elsif ($sortby eq 'AuthidAsc') {
$orderstring = '@attr 7=1 @attr 4=109 @attr 1=Local-Number 0';
} elsif ($sortby eq 'AuthidDsc') {
$orderstring = '@attr 7=2 @attr 4=109 @attr 1=Local-Number 0';
}
if ($QParser) {
$qpquery .= ' all:all' unless $value->[0];
if ( $value->[0] =~ m/^qp=(.*)$/ ) {
$qpquery = $1;
}
my $dosearch;
my $and=" \@and " ;
my $q2;
my $attr_cnt = 0;
for(my $i = 0 ; $i <= $#{$value} ; $i++)
{
if (@$value[$i]){
if ( @$tags[$i] eq "mainmainentry" ) {
$attr = " \@attr 1=Heading-Main ";
}
elsif ( @$tags[$i] eq "mainentry" ) {
$attr = " \@attr 1=Heading ";
}
elsif ( @$tags[$i] eq "match" ) {
$attr = " \@attr 1=Match ";
}
elsif ( @$tags[$i] eq "match-heading" ) {
$attr = " \@attr 1=Match-heading ";
}
elsif ( @$tags[$i] eq "see-from" ) {
$attr = " \@attr 1=Match-heading-see-from ";
}
elsif ( @$tags[$i] eq "thesaurus" ) {
$attr = " \@attr 1=Subject-heading-thesaurus ";
}
else { # Assume any if no index was specified
$attr = " \@attr 1=Any ";
}
if ( @$operator[$i] eq 'is' ) {
$attr .= " \@attr 4=1 \@attr 5=100 "
; ##Phrase, No truncation,all of subfield field must match
}
elsif ( @$operator[$i] eq "=" ) {
$attr .= " \@attr 4=107 "; #Number Exact match
}
elsif ( @$operator[$i] eq "start" ) {
$attr .= " \@attr 3=2 \@attr 4=1 \@attr 5=1 "
; #Firstinfield Phrase, Right truncated
}
elsif ( @$operator[$i] eq "exact" ) {
$attr .= " \@attr 4=1 \@attr 5=100 \@attr 6=3 "
; ##Phrase, No truncation,all of subfield field must match
}
else {
$attr .= " \@attr 5=1 \@attr 4=6 "
; ## Word list, right truncated, anywhere
if ($sortby eq 'Relevance') {
$attr .= "\@attr 2=102 ";
}
}
@$value[$i] =~ s/"/\\"/g; # Escape the double-quotes in the search value
$attr =$attr."\"".@$value[$i]."\"";
$q2 .=$attr;
$dosearch=1;
++$attr_cnt;
if ($QParser) {
$qpquery .= " $tags->[$i]:\"$value->[$i]\"";
}
}#if value
}
##Add how many queries generated
if (defined $query && $query=~/\S+/){
$query= $and x $attr_cnt . $query . (defined $q2 ? $q2 : '');
} else {
$query= $q2;
}
## Adding order
#$query=' @or @attr 7=2 @attr 1=Heading 0 @or @attr 7=1 @attr 1=Heading 1'.$query if ($sortby eq "HeadingDsc");
my $orderstring;
if ($sortby eq 'HeadingAsc') {
$orderstring = '@attr 7=1 @attr 1=Heading 0';
} elsif ($sortby eq 'HeadingDsc') {
$orderstring = '@attr 7=2 @attr 1=Heading 0';
} elsif ($sortby eq 'AuthidAsc') {
$orderstring = '@attr 7=1 @attr 4=109 @attr 1=Local-Number 0';
} elsif ($sortby eq 'AuthidDsc') {
$orderstring = '@attr 7=2 @attr 4=109 @attr 1=Local-Number 0';
}
if ($QParser) {
$qpquery .= ' all:all' unless $value->[0];
if ( $value->[0] =~ m/^qp=(.*)$/ ) {
$qpquery = $1;
}
$qpquery .= " #$sortby";
$qpquery .= " #$sortby";
$QParser->parse( $qpquery );
$query = $QParser->target_syntax('authorityserver');
} else {
$query=($query?$query:"\@attr 1=_ALLRECORDS \@attr 2=103 ''");
$query="\@or $orderstring $query" if $orderstring;
}
$QParser->parse( $qpquery );
$query = $QParser->target_syntax('authorityserver');
} else {
$query=($query?$query:"\@attr 1=_ALLRECORDS \@attr 2=103 ''");
$query="\@or $orderstring $query" if $orderstring;
}
$offset=0 unless $offset;
my $counter = $offset;
$length=10 unless $length;
my @oAuth;
my $i;
$oAuth[0]=C4::Context->Zconn("authorityserver" , 1);
my $Anewq= new ZOOM::Query::PQF($query,$oAuth[0]);
my $oAResult;
$oAResult= $oAuth[0]->search($Anewq) ;
while (($i = ZOOM::event(\@oAuth)) != 0) {
my $ev = $oAuth[$i-1]->last_event();
last if $ev == ZOOM::Event::ZEND;
}
my($error, $errmsg, $addinfo, $diagset) = $oAuth[0]->error_x();
if ($error) {
warn "oAuth error: $errmsg ($error) $addinfo $diagset\n";
goto NOLUCK;
}
$offset=0 unless $offset;
my $counter = $offset;
$length=10 unless $length;
my @oAuth;
my $i;
$oAuth[0]=C4::Context->Zconn("authorityserver" , 1);
my $Anewq= new ZOOM::Query::PQF($query,$oAuth[0]);
my $oAResult;
$oAResult= $oAuth[0]->search($Anewq) ;
while (($i = ZOOM::event(\@oAuth)) != 0) {
my $ev = $oAuth[$i-1]->last_event();
last if $ev == ZOOM::Event::ZEND;
}
my($error, $errmsg, $addinfo, $diagset) = $oAuth[0]->error_x();
if ($error) {
warn "oAuth error: $errmsg ($error) $addinfo $diagset\n";
goto NOLUCK;
}
my $nbresults;
$nbresults=$oAResult->size();
my $nremains=$nbresults;
my @result = ();
my @finalresult = ();
if ($nbresults>0){
my $nbresults;
$nbresults=$oAResult->size();
my $nremains=$nbresults;
my @result = ();
my @finalresult = ();
if ($nbresults>0){
##Find authid and linkid fields
##we may be searching multiple authoritytypes.
## FIXME this assumes that all authid and linkid fields are the same for all authority types
# my ($authidfield,$authidsubfield)=GetAuthMARCFromKohaField($dbh,"auth_header.authid",$authtypecode[0]);
# my ($linkidfield,$linkidsubfield)=GetAuthMARCFromKohaField($dbh,"auth_header.linkid",$authtypecode[0]);
while (($counter < $nbresults) && ($counter < ($offset + $length))) {
##Find authid and linkid fields
##we may be searching multiple authoritytypes.
## FIXME this assumes that all authid and linkid fields are the same for all authority types
# my ($authidfield,$authidsubfield)=GetAuthMARCFromKohaField($dbh,"auth_header.authid",$authtypecode[0]);
# my ($linkidfield,$linkidsubfield)=GetAuthMARCFromKohaField($dbh,"auth_header.linkid",$authtypecode[0]);
while (($counter < $nbresults) && ($counter < ($offset + $length))) {
##Here we have to extract MARC record and $authid from ZEBRA AUTHORITIES
my $rec=$oAResult->record($counter);
my $marcdata=$rec->raw();
my $authrecord;
my $separator=C4::Context->preference('authoritysep');
$authrecord = MARC::File::USMARC::decode($marcdata);
my $authid=$authrecord->field('001')->data();
my %newline;
$newline{authid} = $authid;
if ( !$skipmetadata ) {
my $summary =
BuildSummary( $authrecord, $authid, $authtypecode );
my $query_auth_tag =
##Here we have to extract MARC record and $authid from ZEBRA AUTHORITIES
my $rec=$oAResult->record($counter);
my $marcdata=$rec->raw();
my $authrecord;
my $separator=C4::Context->preference('authoritysep');
$authrecord = MARC::File::USMARC::decode($marcdata);
my $authid=$authrecord->field('001')->data();
my %newline;
$newline{authid} = $authid;
if ( !$skipmetadata ) {
my $summary =
BuildSummary( $authrecord, $authid, $authtypecode );
my $query_auth_tag =
"SELECT auth_tag_to_report FROM auth_types WHERE authtypecode=?";
my $sth = $dbh->prepare($query_auth_tag);
$sth->execute($authtypecode);
my $auth_tag_to_report = $sth->fetchrow;
my $reported_tag;
my $mainentry = $authrecord->field($auth_tag_to_report);
if ($mainentry) {
foreach ( $mainentry->subfields() ) {
$reported_tag .= '$' . $_->[0] . $_->[1];
}
my $sth = $dbh->prepare($query_auth_tag);
$sth->execute($authtypecode);
my $auth_tag_to_report = $sth->fetchrow;
my $reported_tag;
my $mainentry = $authrecord->field($auth_tag_to_report);
if ($mainentry) {
foreach ( $mainentry->subfields() ) {
$reported_tag .= '$' . $_->[0] . $_->[1];
}
my $thisauthtype = GetAuthType(GetAuthTypeCode($authid));
unless (defined $thisauthtype) {
$thisauthtype = GetAuthType($authtypecode) if $authtypecode;
}
$newline{authtype} = defined($thisauthtype) ?
$thisauthtype->{'authtypetext'} : '';
$newline{summary} = $summary;
$newline{even} = $counter % 2;
$newline{reported_tag} = $reported_tag;
}
$counter++;
push @finalresult, \%newline;
}## while counter
###
if (! $skipmetadata) {
for (my $z=0; $z<@finalresult; $z++){
my $count=CountUsage($finalresult[$z]{authid});
$finalresult[$z]{used}=$count;
}# all $z's
my $thisauthtype = GetAuthType(GetAuthTypeCode($authid));
unless (defined $thisauthtype) {
$thisauthtype = GetAuthType($authtypecode) if $authtypecode;
}
$newline{authtype} = defined($thisauthtype) ?
$thisauthtype->{'authtypetext'} : '';
$newline{summary} = $summary;
$newline{even} = $counter % 2;
$newline{reported_tag} = $reported_tag;
}
$counter++;
push @finalresult, \%newline;
}## while counter
###
if (! $skipmetadata) {
for (my $z=0; $z<@finalresult; $z++){
my $count=CountUsage($finalresult[$z]{authid});
$finalresult[$z]{used}=$count;
}# all $z's
}
}## if nbresult
NOLUCK:
$oAResult->destroy();
# $oAuth[0]->destroy();
return (\@finalresult, $nbresults);
}
}## if nbresult
NOLUCK:
$oAResult->destroy();
# $oAuth[0]->destroy();
return (\@finalresult, $nbresults);
}
=head2 CountUsage

379
C4/Biblio.pm

@ -136,7 +136,6 @@ BEGIN {
&TransformHtmlToMarc2
&TransformHtmlToMarc
&TransformHtmlToXml
&GetNoZebraIndexes
prepare_host_field
);
}
@ -444,17 +443,9 @@ sub DelBiblio {
# Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
# for at least 2 reasons :
# - we need to read the biblio if NoZebra is set (to remove it from the indexes
# - if something goes wrong, the biblio may be deleted from Koha but not from zebra
# and we would have no way to remove it (except manually in zebra, but I bet it would be very hard to handle the problem)
my $oldRecord;
if ( C4::Context->preference("NoZebra") ) {
# only NoZebra indexing needs to have
# the previous version of the record
$oldRecord = GetMarcBiblio($biblionumber);
}
ModZebra( $biblionumber, "recordDelete", "biblioserver", $oldRecord, undef );
ModZebra( $biblionumber, "recordDelete", "biblioserver" );
# delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
$sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
@ -2760,7 +2751,7 @@ sub TransformMarcToKohaOneField {
=head2 ModZebra
ModZebra( $biblionumber, $op, $server, $oldRecord, $newRecord );
ModZebra( $biblionumber, $op, $server );
$biblionumber is the biblionumber we want to index
@ -2768,99 +2759,34 @@ $op is specialUpdate or delete, and is used to know what we want to do
$server is the server that we want to update
$oldRecord is the MARC::Record containing the previous version of the record. This is used only when
NoZebra=1, as NoZebra indexing needs to know the previous version of a record in order to
do an update.
$newRecord is the MARC::Record containing the new record. It is usefull only when NoZebra=1, and is used to know what to add to the nozebra database. (the record in mySQL being, if it exist, the previous record, the one just before the modif. We need both : the previous and the new one.
=cut
sub ModZebra {
###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
my ( $biblionumber, $op, $server, $oldRecord, $newRecord ) = @_;
my ( $biblionumber, $op, $server ) = @_;
my $dbh = C4::Context->dbh;
# true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
# at the same time
# replaced by a zebraqueue table, that is filled with ModZebra to run.
# the table is emptied by misc/cronjobs/zebraqueue_start.pl script
# the table is emptied by rebuild_zebra.pl script (using the -z switch)
if ( C4::Context->preference("NoZebra") ) {
# lock the nozebra table : we will read index lines, update them in Perl process
# and write everything in 1 transaction.
# lock the table to avoid someone else overwriting what we are doing
$dbh->do('LOCK TABLES nozebra WRITE,biblio WRITE,biblioitems WRITE, systempreferences WRITE, auth_types WRITE, auth_header WRITE, auth_subfield_structure READ');
my %result; # the result hash that will be built by deletion / add, and written on mySQL at the end, to improve speed
if ( $op eq 'specialUpdate' ) {
# OK, we have to add or update the record
# 1st delete (virtually, in indexes), if record actually exists
if ($oldRecord) {
%result = _DelBiblioNoZebra( $biblionumber, $oldRecord, $server );
}
# ... add the record
%result = _AddBiblioNoZebra( $biblionumber, $newRecord, $server, %result );
} else {
# it's a deletion, delete the record...
# warn "DELETE the record $biblionumber on $server".$record->as_formatted;
%result = _DelBiblioNoZebra( $biblionumber, $oldRecord, $server );
}
# ok, now update the database...
my $sth = $dbh->prepare("UPDATE nozebra SET biblionumbers=? WHERE server=? AND indexname=? AND value=?");
foreach my $key ( keys %result ) {
foreach my $index ( keys %{ $result{$key} } ) {
$sth->execute( $result{$key}->{$index}, $server, $key, $index );
}
}
$dbh->do('UNLOCK TABLES');
} else {
#
# we use zebra, just fill zebraqueue table
#
my $check_sql = "SELECT COUNT(*) FROM zebraqueue
WHERE server = ?
AND biblio_auth_number = ?
AND operation = ?
AND done = 0";
my $check_sth = $dbh->prepare_cached($check_sql);
$check_sth->execute( $server, $biblionumber, $op );
my ($count) = $check_sth->fetchrow_array;
$check_sth->finish();
if ( $count == 0 ) {
my $sth = $dbh->prepare("INSERT INTO zebraqueue (biblio_auth_number,server,operation) VALUES(?,?,?)");
$sth->execute( $biblionumber, $server, $op );
$sth->finish;
}
my $check_sql = "SELECT COUNT(*) FROM zebraqueue
WHERE server = ?
AND biblio_auth_number = ?
AND operation = ?
AND done = 0";
my $check_sth = $dbh->prepare_cached($check_sql);
$check_sth->execute( $server, $biblionumber, $op );
my ($count) = $check_sth->fetchrow_array;
$check_sth->finish();
if ( $count == 0 ) {
my $sth = $dbh->prepare("INSERT INTO zebraqueue (biblio_auth_number,server,operation) VALUES(?,?,?)");
$sth->execute( $biblionumber, $server, $op );
$sth->finish;
}
}
=head2 GetNoZebraIndexes
%indexes = GetNoZebraIndexes;
return the data from NoZebraIndexes syspref.
=cut
sub GetNoZebraIndexes {
my $no_zebra_indexes = C4::Context->preference('NoZebraIndexes');
my %indexes;
INDEX: foreach my $line ( split /['"],[\n\r]*/, $no_zebra_indexes ) {
$line =~ /(.*)=>(.*)/;
my $index = $1; # initial ' or " is removed afterwards
my $fields = $2;
$index =~ s/'|"|\s//g;
$fields =~ s/'|"|\s//g;
$indexes{$index} = $fields;
}
return %indexes;
}
=head2 EmbedItemsInMarcBiblio
@ -2899,268 +2825,6 @@ sub EmbedItemsInMarcBiblio {
=head1 INTERNAL FUNCTIONS
=head2 _DelBiblioNoZebra($biblionumber,$record,$server);
function to delete a biblio in NoZebra indexes
This function does NOT delete anything in database : it reads all the indexes entries
that have to be deleted & delete them in the hash
The SQL part is done either :
- after the Add if we are modifying a biblio (delete + add again)
- immediatly after this sub if we are doing a true deletion.
$server can be 'biblioserver' or 'authorityserver' : it indexes biblios or authorities (in the same table, $server being part of the table itself
=cut
sub _DelBiblioNoZebra {
my ( $biblionumber, $record, $server ) = @_;
# Get the indexes
my $dbh = C4::Context->dbh;
# Get the indexes
my %index;
my $title;
if ( $server eq 'biblioserver' ) {
%index = GetNoZebraIndexes;
# get title of the record (to store the 10 first letters with the index)
my ( $titletag, $titlesubfield ) = GetMarcFromKohaField( 'biblio.title', '' ); # FIXME: should be GetFrameworkCode($biblionumber) ??
$title = lc( $record->subfield( $titletag, $titlesubfield ) );
} else {
# for authorities, the "title" is the $a mainentry
my ( $auth_type_tag, $auth_type_sf ) = C4::AuthoritiesMarc::get_auth_type_location();
my $authref = C4::AuthoritiesMarc::GetAuthType( $record->subfield( $auth_type_tag, $auth_type_sf ) );
warn "ERROR : authtype undefined for " . $record->as_formatted unless $authref;
$title = $record->subfield( $authref->{auth_tag_to_report}, 'a' );
$index{'mainmainentry'} = $authref->{'auth_tag_to_report'} . 'a';
$index{'mainentry'} = $authref->{'auth_tag_to_report'} . '*';
$index{'auth_type'} = "${auth_type_tag}${auth_type_sf}";
}
my %result;
# remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
$title =~ s/ |,|;|\[|\]|\(|\)|\*|-|'|=//g;
# limit to 10 char, should be enough, and limit the DB size
$title = substr( $title, 0, 10 );
#parse each field
my $sth2 = $dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
foreach my $field ( $record->fields() ) {
#parse each subfield
next if $field->tag < 10;
foreach my $subfield ( $field->subfields() ) {
my $tag = $field->tag();
my $subfieldcode = $subfield->[0];
my $indexed = 0;
# check each index to see if the subfield is stored somewhere
# otherwise, store it in __RAW__ index
foreach my $key ( keys %index ) {
# warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
if ( $index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/ ) {
$indexed = 1;
my $line = lc $subfield->[1];
# remove meaningless value in the field...
$line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
# ... and split in words
foreach ( split / /, $line ) {
next unless $_; # skip empty values (multiple spaces)
# if the entry is already here, do nothing, the biblionumber has already be removed
unless ( defined( $result{$key}->{$_} ) && ( $result{$key}->{$_} =~ /$biblionumber,$title\-(\d);/ ) ) {
# get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
$sth2->execute( $server, $key, $_ );
my $existing_biblionumbers = $sth2->fetchrow;
# it exists
if ($existing_biblionumbers) {
# warn " existing for $key $_: $existing_biblionumbers";
$result{$key}->{$_} = $existing_biblionumbers;
$result{$key}->{$_} =~ s/$biblionumber,$title\-(\d);//;
}
}
}
}
}
# the subfield is not indexed, store it in __RAW__ index anyway
unless ($indexed) {
my $line = lc $subfield->[1];
$line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
# ... and split in words
foreach ( split / /, $line ) {
next unless $_; # skip empty values (multiple spaces)
# if the entry is already here, do nothing, the biblionumber has already be removed
unless ( $result{'__RAW__'}->{$_} =~ /$biblionumber,$title\-(\d);/ ) {
# get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
$sth2->execute( $server, '__RAW__', $_ );
my $existing_biblionumbers = $sth2->fetchrow;
# it exists
if ($existing_biblionumbers) {
$result{'__RAW__'}->{$_} = $existing_biblionumbers;
$result{'__RAW__'}->{$_} =~ s/$biblionumber,$title\-(\d);//;
}
}
}
}
}
}
return %result;
}
=head2 _AddBiblioNoZebra
_AddBiblioNoZebra($biblionumber, $record, $server, %result);
function to add a biblio in NoZebra indexes
=cut
sub _AddBiblioNoZebra {
my ( $biblionumber, $record, $server, %result ) = @_;
my $dbh = C4::Context->dbh;
# Get the indexes
my %index;
my $title;
if ( $server eq 'biblioserver' ) {
%index = GetNoZebraIndexes;
# get title of the record (to store the 10 first letters with the index)
my ( $titletag, $titlesubfield ) = GetMarcFromKohaField( 'biblio.title', '' ); # FIXME: should be GetFrameworkCode($biblionumber) ??
$title = lc( $record->subfield( $titletag, $titlesubfield ) );
} else {
# warn "server : $server";
# for authorities, the "title" is the $a mainentry
my ( $auth_type_tag, $auth_type_sf ) = C4::AuthoritiesMarc::get_auth_type_location();
my $authref = C4::AuthoritiesMarc::GetAuthType( $record->subfield( $auth_type_tag, $auth_type_sf ) );
warn "ERROR : authtype undefined for " . $record->as_formatted unless $authref;
$title = $record->subfield( $authref->{auth_tag_to_report}, 'a' );
$index{'mainmainentry'} = $authref->{auth_tag_to_report} . 'a';
$index{'mainentry'} = $authref->{auth_tag_to_report} . '*';
$index{'auth_type'} = "${auth_type_tag}${auth_type_sf}";
}
# remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
$title =~ s/ |\.|,|;|\[|\]|\(|\)|\*|-|'|:|=|\r|\n//g;
# limit to 10 char, should be enough, and limit the DB size
$title = substr( $title, 0, 10 );
#parse each field
my $sth2 = $dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
foreach my $field ( $record->fields() ) {
#parse each subfield
###FIXME: impossible to index a 001-009 value with NoZebra
next if $field->tag < 10;
foreach my $subfield ( $field->subfields() ) {
my $tag = $field->tag();
my $subfieldcode = $subfield->[0];
my $indexed = 0;
# warn "INDEXING :".$subfield->[1];
# check each index to see if the subfield is stored somewhere
# otherwise, store it in __RAW__ index
foreach my $key ( keys %index ) {
# warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
if ( $index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/ ) {
$indexed = 1;
my $line = lc $subfield->[1];
# remove meaningless value in the field...
$line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:|\r|\n/ /g;
# ... and split in words
foreach ( split / /, $line ) {
next unless $_; # skip empty values (multiple spaces)
# if the entry is already here, improve weight
# warn "managing $_";
if ( exists $result{$key}->{$_} && $result{$key}->{"$_"} =~ /$biblionumber,\Q$title\E\-(\d+);/ ) {
my $weight = $1 + 1;
$result{$key}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//g;
$result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
} else {
# get the value if it exist in the nozebra table, otherwise, create it
$sth2->execute( $server, $key, $_ );
my $existing_biblionumbers = $sth2->fetchrow;
# it exists
if ($existing_biblionumbers) {
$result{$key}->{"$_"} = $existing_biblionumbers;
my $weight = defined $1 ? $1 + 1 : 1;
$result{$key}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//g;
$result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
# create a new ligne for this entry
} else {
# warn "INSERT : $server / $key / $_";
$dbh->do( 'INSERT INTO nozebra SET server=' . $dbh->quote($server) . ', indexname=' . $dbh->quote($key) . ',value=' . $dbh->quote($_) );
$result{$key}->{"$_"} .= "$biblionumber,$title-1;";
}
}
}
}
}
# the subfield is not indexed, store it in __RAW__ index anyway
unless ($indexed) {
my $line = lc $subfield->[1];
$line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:|\r|\n/ /g;
# ... and split in words
foreach ( split / /, $line ) {
next unless $_; # skip empty values (multiple spaces)
# if the entry is already here, improve weight
my $tmpstr = $result{'__RAW__'}->{"$_"} || "";
if ( $tmpstr =~ /$biblionumber,\Q$title\E\-(\d+);/ ) {
my $weight = $1 + 1;
$result{'__RAW__'}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//;
$result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
} else {
# get the value if it exist in the nozebra table, otherwise, create it
$sth2->execute( $server, '__RAW__', $_ );
my $existing_biblionumbers = $sth2->fetchrow;
# it exists
if ($existing_biblionumbers) {
$result{'__RAW__'}->{"$_"} = $existing_biblionumbers;
my $weight = ( $1 ? $1 : 0 ) + 1;
$result{'__RAW__'}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//;
$result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
# create a new ligne for this entry
} else {
$dbh->do( 'INSERT INTO nozebra SET server=' . $dbh->quote($server) . ', indexname="__RAW__",value=' . $dbh->quote($_) );
$result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-1;";
}
}
}
}
}
}
return %result;
}
=head2 _koha_marc_update_bib_ids
@ -3641,17 +3305,10 @@ sub ModBiblioMarc {
$f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005;
}
my $oldRecord;
if ( C4::Context->preference("NoZebra") ) {
# only NoZebra indexing needs to have
# the previous version of the record
$oldRecord = GetMarcBiblio($biblionumber);
}
$sth = $dbh->prepare("UPDATE biblioitems SET marc=?,marcxml=? WHERE biblionumber=?");
$sth->execute( $record->as_usmarc(), $record->as_xml_record($encoding), $biblionumber );
$sth->finish;
ModZebra( $biblionumber, "specialUpdate", "biblioserver", $oldRecord, $record );
ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
return $biblionumber;
}

26
C4/Installer.pm

@ -38,7 +38,6 @@ C4::Installer
my ($fwk_language, $error_list) = $installer->load_sql_in_order($all_languages, @$list);
$installer->set_version_syspref();
$installer->set_marcflavour_syspref('MARC21');
$installer->set_indexing_engine(0);
=head1 DESCRIPTION
@ -430,31 +429,6 @@ sub set_marcflavour_syspref {
$request->execute;
}
=head2 set_indexing_engine
$installer->set_indexing_engine($nozebra);
Sets system preferences related to the indexing
engine. The C<$nozebra> argument is a boolean;
if true, turn on NoZebra mode and turn off QueryFuzzy,
QueryWeightFields, and QueryStemming. If false, turn
off NoZebra mode (i.e., use the Zebra search engine).
=cut
sub set_indexing_engine {
my $self = shift;
my $nozebra = shift;
if ($nozebra) {
$self->{'dbh'}->do("UPDATE systempreferences SET value=1 WHERE variable='NoZebra'");
$self->{'dbh'}->do("UPDATE systempreferences SET value=0 WHERE variable in ('QueryFuzzy','QueryWeightFields','QueryStemming')");
} else {
$self->{'dbh'}->do("UPDATE systempreferences SET value=0 WHERE variable='NoZebra'");
}
}
=head2 set_version_syspref
$installer->set_version_syspref();

28
C4/Items.pm

@ -295,7 +295,7 @@ sub AddItem {
my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} );
$item->{'itemnumber'} = $itemnumber;
ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver", undef, undef );
ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver" );
logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
@ -549,7 +549,7 @@ sub ModItem {
# request that bib be reindexed so that searching on current
# item status is possible
ModZebra( $biblionumber, "specialUpdate", "biblioserver", undef, undef );
ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
logaction("CATALOGUING", "MODIFY", $itemnumber, Dumper($item)) if C4::Context->preference("CataloguingLog");
}
@ -615,7 +615,7 @@ sub DelItem {
# get the MARC record
my $record = GetMarcBiblio($biblionumber);
ModZebra( $biblionumber, "specialUpdate", "biblioserver", undef, undef );
ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
# backup the record
my $copy2deleted = $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?");
@ -2173,8 +2173,8 @@ sub MoveItemFromBiblio {
$sth = $dbh->prepare("UPDATE items SET biblioitemnumber = ?, biblionumber = ? WHERE itemnumber = ? AND biblionumber = ?");
my $return = $sth->execute($tobiblioitem, $tobiblio, $itemnumber, $frombiblio);
if ($return == 1) {
ModZebra( $tobiblio, "specialUpdate", "biblioserver", undef, undef );
ModZebra( $frombiblio, "specialUpdate", "biblioserver", undef, undef );
ModZebra( $tobiblio, "specialUpdate", "biblioserver" );
ModZebra( $frombiblio, "specialUpdate", "biblioserver" );
# Checking if the item we want to move is in an order
require C4::Acquisition;
my $order = C4::Acquisition::GetOrderFromItemnumber($itemnumber);
@ -2460,18 +2460,12 @@ counts Usage of itemnumber in Analytical bibliorecords.
sub GetAnalyticsCount {
my ($itemnumber) = @_;
require C4::Search;
if (C4::Context->preference('NoZebra')) {
# Read the index Koha-Auth-Number for this authid and count the lines
my $result = C4::Search::NZanalyse("hi=$itemnumber");
my @tab = split /;/,$result;
return scalar @tab;
} else {
### ZOOM search here
my $query;
$query= "hi=".$itemnumber;
my ($err,$res,$result) = C4::Search::SimpleSearch($query,0,10);
return ($result);
}
### ZOOM search here
my $query;
$query= "hi=".$itemnumber;
my ($err,$res,$result) = C4::Search::SimpleSearch($query,0,10);
return ($result);
}
=head2 GetItemHolds

738
C4/Search.pm

@ -68,7 +68,6 @@ This module provides searching functions for Koha's bibliographic databases
&searchResults
&getRecords
&buildQuery
&NZgetRecords
&AddSearchHistory
&GetDistinctValues
&enabled_staff_search_views
@ -223,91 +222,82 @@ $template->param(result=>\@results);
sub SimpleSearch {
my ( $query, $offset, $max_results, $servers ) = @_;
if ( C4::Context->preference('NoZebra') ) {
my $result = NZorder( NZanalyse($query) )->{'biblioserver'};
my $search_result =
( $result->{hits}
&& $result->{hits} > 0 ? $result->{'RECORDS'} : [] );
return ( undef, $search_result, scalar($result->{hits}) );
}
else {
return ( 'No query entered', undef, undef ) unless $query;
# FIXME hardcoded value. See catalog/search.pl & opac-search.pl too.
my @servers = defined ( $servers ) ? @$servers : ( 'biblioserver' );
my @zoom_queries;
my @tmpresults;
my @zconns;
my $results = [];
my $total_hits = 0;
return ( 'No query entered', undef, undef ) unless $query;
# FIXME hardcoded value. See catalog/search.pl & opac-search.pl too.
my @servers = defined ( $servers ) ? @$servers : ( 'biblioserver' );
my @zoom_queries;
my @tmpresults;
my @zconns;
my $results = [];
my $total_hits = 0;
my $QParser;
$QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser') && ! ($query =~ m/\w,\w|\w=\w/));
my $QParser;
$QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser') && ! ($query =~ m/\w,\w|\w=\w/));
# Initialize & Search Zebra
for ( my $i = 0 ; $i < @servers ; $i++ ) {
eval {
$zconns[$i] = C4::Context->Zconn( $servers[$i], 1 );
if ($QParser) {
$query =~ s/=/:/g;
$QParser->parse( $query );
$query = $QParser->target_syntax($servers[$i]);
$zoom_queries[$i] = new ZOOM::Query::PQF( $query, $zconns[$i]);
} else {
$query =~ s/:/=/g;
$zoom_queries[$i] = new ZOOM::Query::CCL2RPN( $query, $zconns[$i]);
}
$tmpresults[$i] = $zconns[$i]->search( $zoom_queries[$i] );
# error handling
my $error =
$zconns[$i]->errmsg() . " ("
. $zconns[$i]->errcode() . ") "
. $zconns[$i]->addinfo() . " "
. $zconns[$i]->diagset();
return ( $error, undef, undef ) if $zconns[$i]->errcode();
};
if ($@) {
# caught a ZOOM::Exception
my $error =
$@->message() . " ("
. $@->code() . ") "
. $@->addinfo() . " "
. $@->diagset();
warn $error." for query: $query";
return ( $error, undef, undef );
# Initialize & Search Zebra
for ( my $i = 0 ; $i < @servers ; $i++ ) {
eval {
$zconns[$i] = C4::Context->Zconn( $servers[$i], 1 );
if ($QParser) {
$query =~ s/=/:/g;
$QParser->parse( $query );
$query = $QParser->target_syntax($servers[$i]);
$zoom_queries[$i] = new ZOOM::Query::PQF( $query, $zconns[$i]);
} else {
$query =~ s/:/=/g;
$zoom_queries[$i] = new ZOOM::Query::CCL2RPN( $query, $zconns[$i]);
}
}
$tmpresults[$i] = $zconns[$i]->search( $zoom_queries[$i] );
_ZOOM_event_loop(
\@zconns,
\@tmpresults,
sub {
my ($i, $size) = @_;
my $first_record = defined($offset) ? $offset + 1 : 1;
my $hits = $tmpresults[ $i - 1 ]->size();
$total_hits += $hits;
my $last_record = $hits;
if ( defined $max_results && $offset + $max_results < $hits ) {
$last_record = $offset + $max_results;
}
# error handling
my $error =
$zconns[$i]->errmsg() . " ("
. $zconns[$i]->errcode() . ") "
. $zconns[$i]->addinfo() . " "
. $zconns[$i]->diagset();
for my $j ( $first_record .. $last_record ) {
my $record =
$tmpresults[ $i - 1 ]->record( $j - 1 )->raw()
; # 0 indexed
push @{$results}, $record;
}
return ( $error, undef, undef ) if $zconns[$i]->errcode();
};
if ($@) {
# caught a ZOOM::Exception
my $error =
$@->message() . " ("
. $@->code() . ") "
. $@->addinfo() . " "
. $@->diagset();
warn $error." for query: $query";
return ( $error, undef, undef );
}
}
_ZOOM_event_loop(
\@zconns,
\@tmpresults,
sub {
my ($i, $size) = @_;
my $first_record = defined($offset) ? $offset + 1 : 1;
my $hits = $tmpresults[ $i - 1 ]->size();
$total_hits += $hits;
my $last_record = $hits;
if ( defined $max_results && $offset + $max_results < $hits ) {
$last_record = $offset + $max_results;
}
);
foreach my $zoom_query (@zoom_queries) {
$zoom_query->destroy();
for my $j ( $first_record .. $last_record ) {
my $record =
$tmpresults[ $i - 1 ]->record( $j - 1 )->raw()
; # 0 indexed
push @{$results}, $record;
}
}
);
return ( undef, $results, $total_hits );
foreach my $zoom_query (@zoom_queries) {
$zoom_query->destroy();
}
return ( undef, $results, $total_hits );
}
=head2 getRecords
@ -2171,602 +2161,6 @@ sub SearchAcquisitions{
$qdataacquisitions->finish;
return \@loopacquisitions;
}
#----------------------------------------------------------------------
#
# Non-Zebra GetRecords#
#----------------------------------------------------------------------
=head2 NZgetRecords
NZgetRecords has the same API as zera getRecords, even if some parameters are not managed
=cut
sub NZgetRecords {
my (
$query, $simple_query, $sort_by_ref, $servers_ref,
$results_per_page, $offset, $expanded_facet, $branches,
$query_type, $scan
) = @_;
warn "query =$query" if $DEBUG;
my $result = NZanalyse($query);
warn "results =$result" if $DEBUG;
return ( undef,
NZorder( $result, @$sort_by_ref[0], $results_per_page, $offset ),
undef );
}
=head2 NZanalyse
NZanalyse : get a CQL string as parameter, and returns a list of biblionumber;title,biblionumber;title,...
the list is built from an inverted index in the nozebra SQL table
note that title is here only for convenience : the sorting will be very fast when requested on title
if the sorting is requested on something else, we will have to reread all results, and that may be longer.
=cut
sub NZanalyse {
my ( $string, $server ) = @_;
# warn "---------" if $DEBUG;
warn " NZanalyse" if $DEBUG;
# warn "---------" if $DEBUG;
# $server contains biblioserver or authorities, depending on what we search on.
#warn "querying : $string on $server";
$server = 'biblioserver' unless $server;
# if we have a ", replace the content to discard temporarily any and/or/not inside
my $commacontent;
if ( $string =~ /"/ ) {
$string =~ s/"(.*?)"/__X__/;
$commacontent = $1;
warn "commacontent : $commacontent" if $DEBUG;
}
# split the query string in 3 parts : X AND Y means : $left="X", $operand="AND" and $right="Y"
# then, call again NZanalyse with $left and $right
# (recursive until we find a leaf (=> something without and/or/not)
# delete repeated operator... Would then go in infinite loop
while ( $string =~ s/( and| or| not| AND| OR| NOT)\1/$1/g ) {
}
#process parenthesis before.
if ( $string =~ /^\s*\((.*)\)(( and | or | not | AND | OR | NOT )(.*))?/ ) {
my $left = $1;
my $right = $4;
my $operator = lc($3); # FIXME: and/or/not are operators, not operands
warn
"dealing w/parenthesis before recursive sub call. left :$left operator:$operator right:$right"
if $DEBUG;
my $leftresult = NZanalyse( $left, $server );
if ($operator) {
my $rightresult = NZanalyse( $right, $server );
# OK, we have the results for right and left part of the query
# depending of operand, intersect, union or exclude both lists
# to get a result list
if ( $operator eq ' and ' ) {
return NZoperatorAND($leftresult,$rightresult);
}
elsif ( $operator eq ' or ' ) {
# just merge the 2 strings
return $leftresult . $rightresult;
}
elsif ( $operator eq ' not ' ) {
return NZoperatorNOT($leftresult,$rightresult);
}
}
else {
# this error is impossible, because of the regexp that isolate the operand, but just in case...
return $leftresult;
}
}
warn "string :" . $string if $DEBUG;
my $left = "";
my $right = "";
my $operator = "";
if ($string =~ /(.*?)( and | or | not | AND | OR | NOT )(.*)/) {
$left = $1;
$right = $3;
$operator = lc($2); # FIXME: and/or/not are operators, not operands
}
warn "no parenthesis. left : $left operator: $operator right: $right"
if $DEBUG;
# it's not a leaf, we have a and/or/not
if ($operator) {
# reintroduce comma content if needed
$right =~ s/__X__/"$commacontent"/ if $commacontent;
$left =~ s/__X__/"$commacontent"/ if $commacontent;
warn "node : $left / $operator / $right\n" if $DEBUG;
my $leftresult = NZanalyse( $left, $server );
my $rightresult = NZanalyse( $right, $server );
warn " leftresult : $leftresult" if $DEBUG;
warn " rightresult : $rightresult" if $DEBUG;
# OK, we have the results for right and left part of the query
# depending of operand, intersect, union or exclude both lists
# to get a result list
if ( $operator eq ' and ' ) {
return NZoperatorAND($leftresult,$rightresult);
}
elsif ( $operator eq ' or ' ) {
# just merge the 2 strings
return $leftresult . $rightresult;
}
elsif ( $operator eq ' not ' ) {
return NZoperatorNOT($leftresult,$rightresult);
}
else {
# this error is impossible, because of the regexp that isolate the operand, but just in case...
die "error : operand unknown : $operator for $string";
}
# it's a leaf, do the real SQL query and return the result
}
else {
$string =~ s/__X__/"$commacontent"/ if $commacontent;
$string =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|&|\+|\*|\// /g;
#remove trailing blank at the beginning
$string =~ s/^ //g;
warn "leaf:$string" if $DEBUG;
# parse the string in in operator/operand/value again
my $left = "";
my $operator = "";
my $right = "";
if ($string =~ /(.*)(>=|<=)(.*)/) {
$left = $1;
$operator = $2;
$right = $3;
} else {
$left = $string;
}
# warn "handling leaf... left:$left operator:$operator right:$right"
# if $DEBUG;
unless ($operator) {
if ($string =~ /(.*)(>|<|=)(.*)/) {
$left = $1;
$operator = $2;
$right = $3;
warn
"handling unless (operator)... left:$left operator:$operator right:$right"
if $DEBUG;
} else {
$left = $string;
}
}
my $results;
# strip adv, zebra keywords, currently not handled in nozebra: wrdl, ext, phr...
$left =~ s/ .*$//;
# automatic replace for short operators
$left = 'title' if $left =~ '^ti$';
$left = 'author' if $left =~ '^au$';
$left = 'publisher' if $left =~ '^pb$';
$left = 'subject' if $left =~ '^su$';
$left = 'koha-Auth-Number' if $left =~ '^an$';
$left = 'keyword' if $left =~ '^kw$';
$left = 'itemtype' if $left =~ '^mc$';