#!/usr/bin/perl -w
# $File: //depot/libOurNet/FuzzyIndex/bin/fzquery $ $Author: autrijus $
# $Revision: #1 $ $Change: 1 $ $DateTime: 2002/06/11 15:35:12 $

$VERSION = '1.55';

=head1 NAME

fzquery - FuzzyIndex query utility

=head1 SYNOPSIS

B<fzquery> I<database> [ I<query> ]
B<fzquery> I<database> << I<file>

=head1 DESCRIPTION

Just run F<fzquery> from command line. The first argument is the Berkeley
DB file to query from, remaining arguments being the query string. If no
query was given this way, it will read from B<STDIN> instead.

Example usage:

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

=cut

use OurNet::FuzzyIndex;

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.orgE<gt>

=head1 COPYRIGHT

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

This program is free software; you can redistribute it and/or 
modify it under the same terms as Perl itself.

See L<http://www.perl.com/perl/misc/Artistic.html>

=cut
