#!/usr/bin/perl -w

$VERSION = '1.52';

=head1 NAME

fzquery - FuzzyIndex query utility

=head1 SYNOPSIS

    % fzquery index.db "where could i find some books?" # from arg
    % fzquery index.db << query.txt                     # from stdin

=head1 DESCRIPTION

Just run fzquery at command line. The first argument is the db file
to query from, remaining arguments being the query string. If no
query was given, it will read from STDIN.

=cut

use OurNet::FuzzyIndex '1.52';

my $idxfile = shift 
    or die "Usage: $0 <indexfile> [query]\n";

die "Cannot read $idxfile\n" unless -r $idxfile;

local $/;

$db = OurNet::FuzzyIndex->new($idxfile);

# Combine the result with another query
my %result = $db->query(join(' ', @ARGV ? @ARGV : <>), MATCH_FUZZY);

# Dump the results; note you have to call $db->getkey each time
foreach my $idx (sort {$result{$b} <=> $result{$a}} keys(%result)) {
    printf ("%5.1f%\t%s\n", $result{$idx}/10, $db->getkey($idx));
}

1;

__END__

=head1 AUTHORS

Autrijus Tang E<lt>autrijus@autrijus.org>

=head1 COPYRIGHT

Copyright 2001 by Autrijus Tang E<lt>autrijus@autrijus.org>.

All rights reserved.  You can redistribute and/or modify
this module under the same terms as Perl itself.

=cut

