From 8a007211f150a8f0752a0226efb340ccbfdbdf6b Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 16 Sep 2014 15:33:50 +0200 Subject: [PATCH] Add support for Type-1's proximity operator Patch from Simon Jacob --- SimpleServer.pm | 8 +++++++- SimpleServer.xs | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/SimpleServer.pm b/SimpleServer.pm index dff0f9c..77ad19e 100644 --- a/SimpleServer.pm +++ b/SimpleServer.pm @@ -114,12 +114,15 @@ package Net::Z3950::RPN::Or; our @ISA = qw(Net::Z3950::RPN::Node); package Net::Z3950::RPN::AndNot; our @ISA = qw(Net::Z3950::RPN::Node); +package Net::Z3950::RPN::Prox; +our @ISA = qw(Net::Z3950::RPN::Node); package Net::Z3950::RPN::Term; our @ISA = qw(Net::Z3950::RPN::Node); package Net::Z3950::RPN::RSID; our @ISA = qw(Net::Z3950::RPN::Node); package Net::Z3950::RPN::Attributes; package Net::Z3950::RPN::Attribute; +package Net::Z3950::RPN::Prox::Attributes; package Net::Z3950::FacetList; package Net::Z3950::FacetField; package Net::Z3950::FacetTerms; @@ -144,6 +147,9 @@ sub toPQF { return '@and ' . $this->[0]->toPQF() . ' ' . $this->[1]->toPQF(); } elsif ($class eq "Net::Z3950::RPN::AndNot") { return '@not ' . $this->[0]->toPQF() . ' ' . $this->[1]->toPQF(); + } elsif ($class eq "Net::Z3950::RPN::Prox") { + my $pattrs = $this->[3]; + return '@prox ' . $pattrs->{exclusion} . ' ' . $pattrs->{distance} . ' ' . $pattrs->{ordered} . ' ' . $pattrs->{relationType} . (defined $pattrs->{known} ? ' k ' . $pattrs->{known} : ' p ' . $pattrs->{zprivate}) . ' ' . $this->[0]->toPQF() . ' ' . $this->[1]->toPQF(); } elsif ($class eq "Net::Z3950::RPN::RSID") { return '@set ' . $this->{id}; } elsif ($class ne "Net::Z3950::RPN::Term") { @@ -904,7 +910,7 @@ http://search.cpan.org/~esummers/CQL-Parser/ =head1 AUTHORS -Anders Sønderberg (sondberg@indexdata.dk), +Anders Sønderberg (sondberg@indexdata.dk), Sebastian Hammer (quinn@indexdata.dk), Mike Taylor (indexdata.com). diff --git a/SimpleServer.xs b/SimpleServer.xs index c9eb888..26e7413 100644 --- a/SimpleServer.xs +++ b/SimpleServer.xs @@ -482,7 +482,7 @@ static SV *rpn2perl(Z_RPNStructure *s) case Z_Operator_and: type = "Net::Z3950::RPN::And"; break; case Z_Operator_or: type = "Net::Z3950::RPN::Or"; break; case Z_Operator_and_not: type = "Net::Z3950::RPN::AndNot"; break; - case Z_Operator_prox: fatal("proximity not yet supported"); + case Z_Operator_prox: type = "Net::Z3950::RPN::Prox"; break; default: fatal("unknown RPN operator %d", (int) c->roperator->which); } sv = newObject(type, (SV*) (av = newAV())); @@ -492,6 +492,21 @@ static SV *rpn2perl(Z_RPNStructure *s) if ((tmp = rpn2perl(c->s2)) == 0) return 0; av_push(av, tmp); + if (c->roperator->which == Z_Operator_prox) { + Z_ProximityOperator prox = *c->roperator->u.prox; + HV *hv; + tmp = newObject("Net::Z3950::RPN::Prox::Attributes", (SV*) (hv = newHV())); + setMember(hv, "exclusion", newSViv(*prox.exclusion)); + setMember(hv, "distance", newSViv(*prox.distance)); + setMember(hv, "ordered", newSViv(*prox.ordered)); + setMember(hv, "relationType", newSViv(*prox.relationType)); + if (prox.which == Z_ProximityOperator_known) { + setMember(hv, "known", newSViv(*prox.u.known)); + } else { + setMember(hv, "zprivate", newSViv(*prox.u.zprivate)); + } + av_push(av, tmp); + } return sv; } -- 1.7.10.4