Ticket #565: patch-Search-Xapian-1.2.6.0-select-backend.diff

File patch-Search-Xapian-1.2.6.0-select-backend.diff, 5.4 KB (added by Vitaliy Filippov, 13 years ago)

Backend and block size selection for Search::Xapian::WritableDatabase

  • Xapian/WritableDatabase.pm

    diff -NaurpBb Search-Xapian-1.2.6.0/Xapian/WritableDatabase.pm Search-Xapian-mod/Xapian/WritableDatabase.pm
    old new sub new() {  
    2929  my $class = shift;
    3030  my $database;
    3131  my $invalid_args;
    32   if( scalar(@_) == 1 ) {
     32  if( @_ == 1 ) {
    3333    my $arg = shift;
    3434    my $arg_class = ref( $arg );
    3535    if( $arg_class eq $class ) {
    sub new() {  
    3737    } else {
    3838      $invalid_args = 1;
    3939    }
    40   } elsif( scalar(@_) == 2 ) {
     40  } elsif( @_ >= 2 ) {
    4141    $database = new1( @_ );
    42   } elsif( scalar(@_) == 0 ) {
     42  } elsif( !@_ ) {
    4343    $database = new3();
    4444  } else {
    4545    $invalid_args = 1;
    4646  }
    4747  if( $invalid_args ) {
    48     Carp::carp( "USAGE: $class->new(\$file, DB_OPTS), $class->new(\$database), $class->new()" );
     48    Carp::carp( "USAGE: $class->new(\$file, DB_OPTS[, BACKEND]), $class->new(\$database), $class->new()" );
    4949    exit;
    5050  }
    5151  bless $database, $class;
    L<Search::Xapian::Database>, which is us  
    6969
    7070=over 4
    7171
    72 =item new <database> or new <path> <mode>
     72=item new <database> or new <path> <mode> [backend] [block size]
    7373
    74 Class constructor. Takes either a database object, or a path and one
    75 of DB_OPEN, DB_CREATE, DB_CREATE_OR_OPEN or DB_CREATE_OR_OVERWRITE.
    76 These are exported by L<Search::Xapian> with the 'db' option.
     74Class constructor. Takes either a database object, or a path to database directory,
     75mode, which is one of DB_OPEN, DB_CREATE, DB_CREATE_OR_OPEN or DB_CREATE_OR_OVERWRITE,
     76exported by L<Search::Xapian> with the ':db' option, backend selector,
     77which is one of BACKEND_FLINT, BACKEND_CHERT (default) and BACKEND_BRASS,
     78exported by L<Search::Xapian> with the ':backend' option, and block size
     79(default 8192).
    7780
    7881=item clone
    7982
  • Xapian.pm

    diff -NaurpBb Search-Xapian-1.2.6.0/Xapian.pm Search-Xapian-mod/Xapian.pm
    old new our %EXPORT_TAGS = (  
    9191                                 STEM_NONE
    9292                                 STEM_SOME
    9393                                 STEM_ALL
    94                                  ) ]
     94                                 ) ],
     95                    'backend' => [ qw(
     96                                 BACKEND_FLINT
     97                                 BACKEND_CHERT
     98                                 BACKEND_BRASS
     99                                 ) ],
    95100                   );
    96101$EXPORT_TAGS{standard} = [ @{ $EXPORT_TAGS{'ops'} },
    97102                           @{ $EXPORT_TAGS{'db'} },
    98103                           @{ $EXPORT_TAGS{'qpflags'} },
    99104                           @{ $EXPORT_TAGS{'qpstem'} } ];
    100 $EXPORT_TAGS{all} = [ @{ $EXPORT_TAGS{'standard'} }, @{ $EXPORT_TAGS{'enq_order'} } ];
     105$EXPORT_TAGS{all} = [ @{ $EXPORT_TAGS{'standard'} },
     106                           @{ $EXPORT_TAGS{'backend'} },
     107                           @{ $EXPORT_TAGS{'enq_order'} } ];
    101108
    102109
    103110# Names which can be exported.
    Overwrite database if it exists.  
    205212
    206213=back
    207214
     215=head1 :backend
     216
     217=item BACKEND_FLINT
     218
     219Tells L<Search::Xapian::WritableDatabase>'s constructor to use
     220Flint backend for newly created databases. Flint is the "old stable"
     221backend in Xapian 1.2.x. Use Chert instead.
     222
     223=item BACKEND_CHERT
     224
     225Tells L<Search::Xapian::WritableDatabase>'s constructor to use
     226Chert backend for newly created databases. Chert is considered stable
     227in Xapian 1.2.x and is the default.
     228
     229=item BACKEND_BRASS
     230
     231Tells L<Search::Xapian::WritableDatabase>'s constructor to use
     232Brass backend for newly created databases. Brass is the development
     233backend and will be considered stable in 1.4.0.
     234
    208235=head1 :ops
    209236
    210237=over 4
  • Xapian.xs

    diff -NaurpBb Search-Xapian-1.2.6.0/Xapian.xs Search-Xapian-mod/Xapian.xs
    old new extern "C" {  
    2222using namespace std;
    2323using namespace Xapian;
    2424
     25#define XAPIAN_BACKEND_FLINT 1
     26#define XAPIAN_BACKEND_CHERT 2
     27#define XAPIAN_BACKEND_BRASS 3
     28
    2529extern void handle_exception(void);
    2630
    2731/* PerlStopper class
    BOOT:  
    245249        ENUM_CONST(FLAG_AUTO_MULTIWORD_SYNONYMS, QueryParser::FLAG_AUTO_SYNONYMS);
    246250        ENUM_CONST(FLAG_DEFAULT, QueryParser::FLAG_DEFAULT);
    247251
     252        ENUM_CONST(BACKEND_FLINT, XAPIAN_BACKEND_FLINT);
     253        ENUM_CONST(BACKEND_CHERT, XAPIAN_BACKEND_CHERT);
     254        ENUM_CONST(BACKEND_BRASS, XAPIAN_BACKEND_BRASS);
     255
    248256        ENUM_CONST(STEM_NONE, QueryParser::STEM_NONE);
    249257        ENUM_CONST(STEM_SOME, QueryParser::STEM_SOME);
    250258        ENUM_CONST(STEM_ALL, QueryParser::STEM_ALL);
  • XS/WritableDatabase.xs

    diff -NaurpBb Search-Xapian-1.2.6.0/XS/WritableDatabase.xs Search-Xapian-mod/XS/WritableDatabase.xs
    old new MODULE = Search::Xapian PACKAGE = Searc  
    33PROTOTYPES: ENABLE
    44
    55WritableDatabase *
    6 new1(file, opts)
     6new1(file, opts, backend = XAPIAN_BACKEND_CHERT, blocksize = 8192)
    77    string      file
    88    int         opts
     9    int         backend
     10    int         blocksize
    911    CODE:
    1012        try {
    11             RETVAL = new WritableDatabase(file, opts);
     13            switch (backend) {
     14            case XAPIAN_BACKEND_FLINT:
     15                RETVAL = new WritableDatabase(Xapian::Flint::open(file, opts, blocksize));
     16                break;
     17            case XAPIAN_BACKEND_BRASS:
     18                RETVAL = new WritableDatabase(Xapian::Brass::open(file, opts, blocksize));
     19                break;
     20            case XAPIAN_BACKEND_CHERT:
     21            default:
     22                RETVAL = new WritableDatabase(Xapian::Chert::open(file, opts, blocksize));
     23            }
    1224        } catch (...) {
    1325            handle_exception();
    1426        }