/[Grep]/bin/kinosearch.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /bin/kinosearch.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 190 - (show annotations)
Fri May 23 21:05:42 2008 UTC (15 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 1512 byte(s)
make proper split between top-level Grep::Search package
and Grep::Search::KinoSearch
1 #!/usr/bin/perl -w
2
3 # kinosearch.pl
4 #
5 # 06/10/07 11:58:27 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
6
7 use strict;
8 use blib './lib';
9 use Grep::Search::KinoSearch;
10 use KinoSearch::Highlight::Highlighter;
11 use Data::Dump qw/dump/;
12
13 my ( $index_path, $query_string ) = @ARGV;
14
15 die "usage: $0 /path/to/index 'search query'\n" unless ( $index_path && $query_string );
16
17 my $searcher = KinoSearch::Searcher->new(
18 invindex => Grep::Search::KinoSearch::Schema->open( $index_path )
19 );
20
21 my @fields = ( qw/ title link content summary category author / );
22 my @excerpt_fields = ( qw/ content summary / );
23
24 my $query_parser = KinoSearch::QueryParser->new(
25 schema => Grep::Search::KinoSearch::Schema->new,
26 fields => \@fields,
27 );
28 $query_parser->set_heed_colons(1); # enable field:value AND/OR/NOT syntax
29 my $query = $query_parser->parse( $query_string );
30 my $hits = $searcher->search(
31 query => $query,
32 # offset => $offset,
33 # num_wanted => $hits_per_page,
34 );
35
36 my $highlighter = KinoSearch::Highlight::Highlighter->new(
37 searchable => $searcher,
38 query => $query,
39 field => 'content',
40 );
41
42 print "## found ", $hits->total_hits, " results for $query_string\n";
43
44 sub snippet {
45 my $t = shift;
46 $t =~ s/\s\s+/ /gs;
47 return substr($t,0,1024);
48 }
49
50 while ( my $hit = $hits->fetch_hit ) {
51 print $hit->get_score,$/;
52 foreach my $f ( @fields ) {
53 my $v = $hit->{$f};
54 next unless defined $v;
55 # $v = $highlighter->create_excerpt( $hit ) if grep(/^\Q$f\E^/, @excerpt_fields);
56 printf("%15s: %s\n", $f, snippet($v));
57 }
58 }
59

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26