1 package BackupPC::Search::KinoSearch;
5 use KinoSearch::Index::Indexer;
6 use KinoSearch::Plan::Schema;
7 use KinoSearch::Analysis::PolyAnalyzer;
8 use KinoSearch::Plan::FullTextType;
9 use KinoSearch::Search::IndexSearcher;
10 use Data::Dump qw(dump);
12 # my $tokenizer = KinoSearch::Analysis::Tokenizer->new( pattern => '\\w' );
17 my $schema = KinoSearch::Plan::Schema->new;
18 my $polyanalyzer = KinoSearch::Analysis::PolyAnalyzer->new(
21 my $ft_type = KinoSearch::Plan::FullTextType->new(
22 analyzer => $polyanalyzer,
24 my $blob_type = KinoSearch::Plan::BlobType->new( stored => 1 );
25 my $string_type = KinoSearch::Plan::StringType->new; # non-tokenized
26 my $num_type = KinoSearch::Plan::Int64Type->new;
28 $schema->spec_field( name => $_, type => $string_type ) foreach ( qw/
38 $schema->spec_field( name => $_, type => $string_type ) foreach ( qw/
39 _uri filepath hname sname
42 # $schema->spec_field( name => '_doc', type => $blob_type );
44 my $index_path = '/tmp/kinosearch'; # FIXME
46 my $indexer = KinoSearch::Index::Indexer->new(
52 warn "# using $index_path";
54 $indexer->commit; # make sure that index exists
58 searcher => KinoSearch::Search::IndexSearcher->new(
71 my $uri = $row->{hname} . ':' . $row->{sname} . '#' . $row->{backupnum} . ' ' . $row->{filepath};
73 my $hits = $self->{searcher}->hits( query => "_uri:$uri" );
74 return $hits->total_hits;
80 warn "XXX ",dump($row);
82 $row->{_uri} = $row->{hname} . ':' . $row->{sname} . '#' . $row->{backupnum} . ' ' . $row->{filepath};
84 $self->{indexer}->add_doc( $row );
90 $self->{indexer}->commit;
91 warn "# commit index";