Created
February 21, 2017 05:36
-
-
Save swuecho/1b960ae17a1f47466be006fd14e3b7ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl | |
package MyAnalyzer { | |
use v5.10; | |
use base qw( Lucy::Analysis::Analyzer ); | |
sub new { | |
my $self = shift->SUPER::new; | |
return $self; | |
} | |
sub transform { | |
my ($self, $inversion)= @_; | |
return $inversion; | |
} | |
sub transform_text { | |
my ($self, $text) = @_; | |
my $inversion = Lucy::Analysis::Inversion->new; | |
my @tokens = (['a', 0,1], ['b', 1,2] ); | |
$inversion->append( | |
Lucy::Analysis::Token->new(text =>$_->[0], | |
start_offset=> $_->[1] , | |
end_offset=>$_->[2] | |
) | |
) for @tokens; | |
return $inversion; | |
} | |
1; | |
} | |
package main; | |
use DBI; | |
use File::Spec::Functions qw( catfile ); | |
use Lucy::Plan::Schema; | |
use Lucy::Plan::FullTextType; | |
use Lucy::Index::Indexer; | |
my $path_to_index = '/tmp/test.index'; | |
# Create Schema. | |
my $schema = Lucy::Plan::Schema->new; | |
my $my_analyzer= MyAnalyzer->new(); | |
my $raw_type = Lucy::Plan::FullTextType->new( | |
analyzer => $my_analyzer, | |
); | |
$schema->spec_field( name => 'body', type => $raw_type); | |
use DDP; p $schema->dump; | |
# Create an Indexer object. | |
my $indexer = Lucy::Index::Indexer->new( | |
index => $path_to_index, | |
schema => $schema, | |
create => 1, | |
# truncate => 1, | |
); | |
my $doc = { body => 'test' }; | |
$indexer->add_doc($doc); | |
$indexer->commit; | |
print "Finished.\n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment