Ticket #420: xapian-perl.patch

File xapian-perl.patch, 7.4 KB (added by Henry, 14 years ago)
  • search-xapian/t/index.t

    diff -U3 -r xapian-clean/search-xapian/t/index.t xapian-test/search-xapian/t/index.t
    old new  
    3232
    3333  my $term = 'test';
    3434  ok( $term = $stemmer->stem_word( $term ) );
     35  if ($backend ne "inmemory") {
     36    # inmemory doesn't implement spelling correction support.
     37    $database->add_spelling( $term, 1 );
     38  }
    3539
    3640  my $docid;
    3741  for my $num qw( one two three ) {
     
    4448    $docs{$num}->add_posting( $num, 1 );
    4549
    4650    $docs{$num}->add_value(0, $num);
     51
     52    if ($backend ne "inmemory") {
     53      # inmemory doesn't implement spelling correction support.
     54      $database->add_spelling( "x" . $term, 1 );
     55      $database->add_spelling( $term, 1 );
     56      $database->remove_spelling( "x" . $term, 1 );
     57    }
    4758    ok( $docid = $database->add_document( $docs{$num} ) );
    4859  }
    4960  $database->delete_document( $docid );
  • search-xapian/t/parser.t

    diff -U3 -r xapian-clean/search-xapian/t/parser.t xapian-test/search-xapian/t/parser.t
    old new  
    66
    77use Test;
    88use Devel::Peek;
    9 BEGIN { plan tests => 53 };
     9BEGIN { plan tests => 54 };
    1010use Search::Xapian qw(:standard);
    1111ok(1); # If we made it this far, we're ok.
    1212
     
    2929$qp->set_default_op( OP_AND );
    3030
    3131my $query;
    32 ok( $query = $qp->parse_query( 'one or two', FLAG_BOOLEAN|FLAG_BOOLEAN_ANY_CASE ) );
     32ok( $query = $qp->parse_query( 'one or two', FLAG_BOOLEAN|FLAG_BOOLEAN_ANY_CASE|FLAG_SPELLING_CORRECTION ) );
     33ok( not $qp->get_corrected_query_string());
    3334ok( $query->get_description(), "Xapian::Query((one:(pos=1) OR two:(pos=2)))" );
    3435
    3536ok( $query = $qp->parse_query( 'one OR (two AND three)' ) );
     
    130131    ok( $query->get_description(), "Xapian::Query($res)" );
    131132}
    132133
     134
     135
    133136# Regression test for Search::Xapian bug fixed in 1.0.5.0.  In 1.0.0.0-1.0.4.0
    134137# we tried to catch const char * not Xapian::Error, so std::terminate got
    135138# called.
  • search-xapian/t/search.t

    diff -U3 -r xapian-clean/search-xapian/t/search.t xapian-test/search-xapian/t/search.t
    old new  
    66# change 'tests => 1' to 'tests => last_test_to_print';
    77
    88use Test::More;
    9 BEGIN { plan tests => 114 };
     9BEGIN { plan tests => 115 };
    1010use Search::Xapian qw(:ops);
    1111
    1212#########################
     
    5555
    5656ok( $enq = $db->enquire( $query ), "db queries return ok"  );
    5757ok( $enq = $db->enquire( OP_OR, 'test', 'help' ), "in-line db queries return ok" );
     58is( $db->get_spelling_suggestion( 'tost' ), 'test', "spelling suggestion ok" );
    5859
    5960ok( $query = Search::Xapian::Query->new(OP_SCALE_WEIGHT, $query, 3.14), "OP_SCALE_WEIGHT understood" );
    6061
  • search-xapian/Xapian/Database.pm

    diff -U3 -r xapian-clean/search-xapian/Xapian/Database.pm xapian-test/search-xapian/Xapian/Database.pm
    old new  
    138138
    139139return a description of this object.
    140140
     141=item get_spelling_suggestion
     142
     143returns a suggested spelling correction.
     144
    141145=item allterms_begin [<prefix>]
    142146
    143147Returns a L<Search::Xapian::TermIterator> iterating over the termlist for the
  • search-xapian/Xapian/QueryParser.pm

    diff -U3 -r xapian-clean/search-xapian/Xapian/QueryParser.pm xapian-test/search-xapian/Xapian/QueryParser.pm
    old new  
    157157
    158158Returns a string describing this object.
    159159
     160=item get_corrected_query_string
     161
     162Get the spelling-corrected query string.
     163
     164This will only be set if FLAG_SPELLING_CORRECTION is specified when
     165QueryParser::parse_query() was last called.
     166
     167If there were no corrections, an empty string is returned.
     168
    160169=back
    161170
    162171=head1 REFERENCE
  • search-xapian/Xapian/WritableDatabase.pm

    diff -U3 -r xapian-clean/search-xapian/Xapian/WritableDatabase.pm xapian-test/search-xapian/Xapian/WritableDatabase.pm
    old new  
    174174replaced and an exception is thrown (possibly at a later time when flush is
    175175called or the database is closed).
    176176
     177=item add_spelling <word> <freqinc>
     178
     179Add a word to the spelling dictionary.
     180
     181If the word is already present, its frequency is increased.
     182
     183Parameters:
     184    word        The word to add.
     185    freqinc     How much to increase its frequency by (default 1).
     186
     187=item remove_spelling <word> <freqdec>
     188
     189Remove a word from the spelling dictionary.
     190
     191The word's requency is decreased, and if would become zero or less
     192then the word is removed completely.
     193
     194Parameters:
     195    word        The word to remove.
     196    freqdec     How much to decrease its frequency by (default 1).
     197
    177198=item reopen
    178199
    179 Re-open the database. makes sure you have a fresh db handle.
     200Re-open the database. Makes sure you have a fresh db handle.
     201
     202=item close
     203
     204Close the database. This also implies a flush().
    180205
    181206=back
    182207
  • search-xapian/XS/Database.xs

    diff -U3 -r xapian-clean/search-xapian/XS/Database.xs xapian-test/search-xapian/XS/Database.xs
    old new  
    256256        RETVAL
    257257
    258258string
     259Database::get_spelling_suggestion(word, max_edit_distance = 2)
     260    string  word
     261    int     max_edit_distance
     262    CODE:
     263    try {
     264        RETVAL = THIS->get_spelling_suggestion(word, max_edit_distance);
     265        }
     266        catch (const Error &error) {
     267            croak( "Exception: %s", error.get_msg().c_str() );
     268        }
     269    OUTPUT:
     270        RETVAL
     271
     272string
    259273Database::get_metadata(string key)
    260274
    261275void
  • search-xapian/XS/QueryParser.xs

    diff -U3 -r xapian-clean/search-xapian/XS/QueryParser.xs xapian-test/search-xapian/XS/QueryParser.xs
    old new  
    9999        RETVAL
    100100
    101101string
     102QueryParser::get_corrected_query_string()
     103    CODE:
     104    try {
     105            RETVAL = THIS->get_corrected_query_string();
     106    }
     107    catch (const Error &error) {
     108        croak( "Exception: %s", error.get_msg().c_str() );
     109    }
     110    OUTPUT:
     111        RETVAL
     112   
     113
     114string
    102115QueryParser::get_description()
    103116
    104117void
  • search-xapian/XS/WritableDatabase.xs

    diff -U3 -r xapian-clean/search-xapian/XS/WritableDatabase.xs xapian-test/search-xapian/XS/WritableDatabase.xs
    old new  
    417417        } catch (const Error &error) {
    418418            croak( "Exception: %s", error.get_msg().c_str() );
    419419        }
     420
     421void
     422WritableDatabase::add_spelling(word, freqinc = 1)
     423    string word
     424    termcount freqinc
     425    CODE:
     426        try {
     427            THIS->add_spelling(word, freqinc);
     428        } catch (const Error &error) {
     429            croak( "Exception: %s", error.get_msg().c_str() );
     430        }
     431
     432void
     433WritableDatabase::remove_spelling(word, freqdec  = 1)
     434    string word
     435    termcount freqdec
     436    CODE:
     437        try {
     438            THIS->remove_spelling(word, freqdec);
     439        } catch (const Error &error) {
     440            croak( "Exception: %s", error.get_msg().c_str() );
     441        }