View on
MetaCPAN
Egor Korablev > Sphinx-XML-Pipe2-0.002 > Sphinx::XML::Pipe2

Download:
Sphinx-XML-Pipe2-0.002.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Sphinx::XML::Pipe2 - generates xml to feed xmlpipe2 of Sphinx Search

VERSION ^

version 0.002

SYNOPSIS ^

Example script which creates XML data for Sphinx Search xmlpipe2 data source of some documents in directories specified as script arguments

     use v5.14;
     use Sphinx::XML::Pipe2;
     use File::Find;

     binmode STDIN, ":encoding(utf8)";  
     binmode STDOUT, ":encoding(utf8)"

     my $p = Sphinx::XML::Pipe2->new;
      
     $p->attr('size', 'int');
     $p->attr('type', 'str2ordinal');
     $p->field('content');
     $p->field('path');
    
     my $i = 0;
     find( sub {
        my $file = $_;
        if (-f -r $file && (my $size = -s $file) && $file =~ /\.(html?|txt|rtf)?$/i) {
            $p->add( 
                $i, # document id
                $size, # attributes in declaration order, i.e. 'size'
                lc($1), # 'type'
                do { local( @ARGV, $/ ) = $name; <> }, # then fields in declaration order, i.e. 'content' 
                $File::Find::name # 'path'
            );
        }
    }, @ARGV);
    
    print $p->xml;

METHODS ^

attr($name, $type, $bits, $default)

Declare document attribute. $name and $type is mandatory.

field($name, $attr)

Declare document field. $name is mandatory.

add($id, @attr, @field)

Add document. $id - must be integer, @attr and @field must be be in declaration order.

xml

Returns XML data suitable for xmlpipe2 data source.

process

Returns XML::LibXML::Document

NOTICE ^

Experimental state

SEE ALSO ^

Sphinx Search xmlpipe2 data source

AUTHOR ^

Yegor Korablev <egor@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2011 by Yegor Korablev.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: