Hello, I'm using the XS Perl bindings packaged with Debian stable and am interested in implementing my a custom ValueRangeProcessor (using DateTimeX::Easy for human-friendly date parsing) Unfortunately, I'm not sure if it's possible with the add_valuerangeprocessor API via Perl. Reading the XS/*ValueRangeProcessor.xs source files, I'm seeing "process_value_range" methods being defined (but I can't figure out how they're called); but attempting to define my own classes does not result in the methods being called when performing a query. I suppose I can workaround this by parsing the query string myself by translating the dates with DateTimeX::Easy to Unix epochs which are compatible with timestamp value field in my database for use with NumericValueRangeProcessor. Reading the source to sup (Ruby Xapian mail client[1]), it seems to do this workaround (using the Chronic date parsing library). Below are my attempts at making my own ValueRangeProcessor class. Thanks in advance for any help or pointers you can provide. Disclaimer: I am not knowledgeable in XS, SWIG, C++, or experienced in using Xapian at all. # Try #1 with subclassing NumberValueRangeProcessor: package PublicInbox::Search::DateVRP1; use strict; use warnings; use base 'Search::Xapian::NumberValueRangeProcessor'; sub new { my ($class, @args) = @_; Search::Xapian::NumberValueRangeProcessor::new($class, @args); } # doesn't seem to get called sub process_value_range { use Data::Dumper; print STDERR "PVR called ", Dumper(\@_); 1; } 1; # Try 2 without subclassing package PublicInbox::Search::DateVRP2; use strict; use warnings; sub new { my ($class, @args) = @_; my $s = 1; bless \$s, $class; } # doesn't seem to get called sub process_value_range { use Data::Dumper; print STDERR "PVR called ", Dumper(\@_); 1; } 1; [1] - sup: git clone git://github.com/sup-heliotrope/sup.git
Eric Wong <e at 80x24.org> wrote:> Unfortunately, I'm not sure if it's possible with the > add_valuerangeprocessor API via Perl.Ping? <snip>> I suppose I can workaround this by parsing the query string myself by > translating the dates with DateTimeX::Easy to Unix epochs which are > compatible with timestamp value field in my database for use with > NumericValueRangeProcessor. > > Reading the source to sup (Ruby Xapian mail client[1]), it seems to do > this workaround (using the Chronic date parsing library).It looks like I'll need do this myself in Perl, too.> [1] - sup: git clone git://github.com/sup-heliotrope/sup.git
On Wed, Sep 09, 2015 at 11:19:34PM +0000, Eric Wong wrote:> Hello, I'm using the XS Perl bindings packaged with Debian stable > and am interested in implementing my a custom ValueRangeProcessor > (using DateTimeX::Easy for human-friendly date parsing) > > Unfortunately, I'm not sure if it's possible with the > add_valuerangeprocessor API via Perl.It isn't currently with the stable versions of Search::Xapian. The SWIG-generated Perl bindings should support custom VRPs though. The SWIG-generated bindings are present in 1.2.x, but are not the standard Perl bindings. In 1.3.x, the XS ones have been retired in favour of the SWIG ones (as the SWIG ones are easier to keep up to date, and provide a more complete wrapping). The two aren't 100% compatible though.> Reading the XS/*ValueRangeProcessor.xs source files, I'm seeing > "process_value_range" methods being defined (but I can't figure out how > they're called)They're only called if you call them (which you normally wouldn't).> but attempting to define my own classes does not result > in the methods being called when performing a query.The C++ QueryParser class will call the operator() method on the C++ object which the Perl object is wrapping. There isn't anything in the XS wrappers to turn that into an "upcall" to a Perl method. This is possible though, e.g. see the perlMatchDecider class in Xapian.xs for how it is done for MatchDecider. Since ValueRangeProcessor also only has one virtual method, you could probably similarly wrap it such that from perl you could pass a subroutine reference. Cheers, Olly