Ticket #607: 0001-Add-support-for-2-and-3-arg-versions-of-StringValueR.patch

File 0001-Add-support-for-2-and-3-arg-versions-of-StringValueR.patch, 3.5 KB (added by Adam Sjøgren, 12 years ago)

Updated patch

  • search-xapian/XS/StringValueRangeProcessor.xs

    diff --git a/search-xapian/XS/StringValueRangeProcessor.xs b/search-xapian/XS/StringValueRangeProcessor.xs
    index 95da8d3..cd4c9d3 100644
    a b MODULE = Search::Xapian PACKAGE = Search::Xapian::StringValueRangeProcessor  
    33PROTOTYPES: ENABLE
    44
    55StringValueRangeProcessor *
    6 StringValueRangeProcessor::new(valueno valno)
     6StringValueRangeProcessor::new(valno, str="", prefix = TRUE)
     7    valueno valno
     8    string str
     9    bool prefix
    710    CODE:
    8         RETVAL = new StringValueRangeProcessor(valno);
     11        switch (items) { /* items includes the hidden this pointer */
     12        case 2:
     13            RETVAL = new StringValueRangeProcessor(valno);
     14            break;
     15        case 3:
     16        case 4: {
     17            RETVAL = new StringValueRangeProcessor(valno, str, prefix);
     18            break;
     19        }
     20        default:
     21            croak("Bad parameter count for new");
     22        }
    923    OUTPUT:
    1024        RETVAL
    1125
  • search-xapian/t/parser.t

    diff --git a/search-xapian/t/parser.t b/search-xapian/t/parser.t
    index ea0716a..1d12296 100644
    a b  
    66
    77use Test;
    88use Devel::Peek;
    9 BEGIN { plan tests => 58 };
     9BEGIN { plan tests => 60 };
    1010use Search::Xapian qw(:standard);
    1111ok(1); # If we made it this far, we're ok.
    1212
    my $vrp2 = new Search::Xapian::NumberValueRangeProcessor(2);  
    8585my $vrp3 = new Search::Xapian::StringValueRangeProcessor(3);
    8686my $vrp4 = new Search::Xapian::NumberValueRangeProcessor(4, '$');
    8787my $vrp5 = new Search::Xapian::NumberValueRangeProcessor(5, 'kg', 0);
     88my $vrp6 = new Search::Xapian::StringValueRangeProcessor(6, 'country:');
     89my $vrp7 = new Search::Xapian::StringValueRangeProcessor(7, ':name', 0);
    8890$qp->add_valuerangeprocessor( $vrp1 );
    8991$qp->add_valuerangeprocessor( $vrp2 );
    9092$qp->add_valuerangeprocessor( $vrp4 );
    9193$qp->add_valuerangeprocessor( $vrp5 );
     94$qp->add_valuerangeprocessor( $vrp6 );
     95$qp->add_valuerangeprocessor( $vrp7 );
    9296$qp->add_valuerangeprocessor( $vrp3 );
    9397
    9498$qp->add_boolean_prefix("test", "XTEST");
    foreach $pair (  
    108112    [ '12/03/99..12/04/01', 'VALUE_RANGE 1 19990312 20010412' ],
    109113    [ '03-12-99..04-14-01', 'VALUE_RANGE 1 19990312 20010414' ],
    110114    [ '(test:a..test:b hello)', '(hello:(pos=1) FILTER VALUE_RANGE 3 test:a test:b)' ],
     115    [ 'country:chile..denmark', 'VALUE_RANGE 6 chile denmark' ],
     116    [ 'albert..xeni:name', 'VALUE_RANGE 7 albert xeni' ],
    111117    ) {
    112118    my ($str, $res) = @{$pair};
    113119    my $query = $qp->parse_query($str);
  • xapian-core/docs/valueranges.rst

    diff --git a/xapian-core/docs/valueranges.rst b/xapian-core/docs/valueranges.rst
    index 85a8df4..8b7d023 100644
    a b would report::  
    6060The ``VALUE_RANGE`` subquery will only match documents where value 4 is
    6161>= asimov and <= bradbury (using a string comparison).
    6262
     63``StringValueRangeProcessor`` also supports supplying a prefix or
     64suffix, so the user is able to filter queries to a range within a
     65specified value:
     66
     67    prose country:chile..denmark
     68
     69This is done by providing the string to ``StringValueRangeProcessor``,
     70like this:
     71
     72    Xapian::QueryParser qp;
     73    Xapian::StringValueRangeProcessor country_proc(7, "country:", TRUE);
     74    qp.add_valuerangeprocessor(&country_proc);
     75
     76The parsed query will include ``(VALUE_RANGE 7 chile denmark)`` in
     77this case.
     78
     79The last argument determines whether the string is a prefix or a
     80suffix (like perhaps a currency indicator: 10..100$).
     81
    6382DateValueRangeProcessor
    6483=======================
    6584