#!/usr/bin/perl -w
# $File: //depot/OurNet-FuzzyIndex/bin/fzquery $ $Author: autrijus $
# $Revision: #3 $ $Change: 2257 $ $DateTime: 2001/11/03 12:49:08 $

$VERSION = '1.53';

=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> at command line. The first argument is the Berkeley
DB file to query from, remaining arguments being the query string. If no
query was given, it will read from B<STDIN>.

Example usages:

    % 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.org>

=head1 COPYRIGHT

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

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
