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' );
18 my $schema = KinoSearch::Plan::Schema->new;
21 my $case_folder = KinoSearch::Analysis::CaseFolder->new;
22 my $tokenizer = KinoSearch::Analysis::Tokenizer->new;
23 my $polyanalyzer = KinoSearch::Analysis::PolyAnalyzer->new(
24 analyzers => [ $case_folder, $tokenizer ],
27 my $ft_type = KinoSearch::Plan::FullTextType->new(
28 analyzer => $polyanalyzer,
30 my $blob_type = KinoSearch::Plan::BlobType->new( stored => 1 );
31 my $string_type = KinoSearch::Plan::StringType->new; # non-tokenized
32 my $num_type = KinoSearch::Plan::Int64Type->new;
34 $schema->spec_field( name => $_, type => $string_type ) foreach ( qw/
44 $schema->spec_field( name => $_, type => $string_type ) foreach ( qw/
45 _uri _file_path_split filepath hname sname
48 # $schema->spec_field( name => '_doc', type => $blob_type );
50 my $index_path = $Conf{KinoPath} || die "no KinoPath";
52 my $indexer = KinoSearch::Index::Indexer->new(
58 warn "# using $index_path";
60 $indexer->commit; # make sure that index exists
64 searcher => KinoSearch::Search::IndexSearcher->new(
75 my $uri = $row->{hname} . ':' . $row->{sname} . '#' . $row->{backupnum} . ' ' . $row->{filepath};
76 my $hits = $self->{searcher}->hits( query => "_uri:$uri" );
77 return $hits->total_hits;
83 $row->{_uri} = $row->{hname} . ':' . $row->{sname} . '#' . $row->{backupnum} . ' ' . $row->{filepath};
84 my $path = $row->{filepath};
85 $path =~ s/(.)/$1 /g; # XXX our tokenize
86 $row->{_file_path_split} = $path;
88 warn "XXX ",dump($row) if $ENV{DEBUG};
90 $self->{indexer}->add_doc( $row );
96 $self->{indexer}->commit;
97 warn "# commit index";