1#!/usr/bin/perl 2 3=head1 NAME 4 5t/multiple_fields.t - Using Plucene::Simple::add with multiple fields 6 7=head1 DESCRIPTION 8 9This tests adding multiple fields to an index. 10 11=cut 12 13use strict; 14use warnings; 15 16use Plucene::Simple; 17use File::Path; 18 19use Test::More tests => 4; 20 21use constant DIR => "/tmp/testindex/$$"; 22 23END { rmtree DIR } 24 25my $plucy = Plucene::Simple->open(DIR); 26 27$plucy->add( 28 1, 29 { 30 title => "Moby-Dick", 31 author => "Herman Melville", 32 text => "Call me Ishmael ...", 33 }, 34 2, 35 { 36 title => "Boo-Hoo", 37 author => "Lydia Lee", 38 text => 'foo', 39 }, 40); 41$plucy->index_document('Moby Dick Chapter 1', 'Call me Ishmael ...'); 42$plucy->optimize; 43 44$plucy = Plucene::Simple->open(DIR); 45 46{ 47 my @ids = $plucy->search("author:lee"); 48 is scalar @ids, 1, "One result for author:lee..."; 49 is $ids[0] => 2, "...with the correct id"; 50} 51 52{ 53 my @ids = $plucy->search("ishmael"); 54 is scalar @ids => 2, "Two results for 'ishmael'..."; 55 is_deeply \@ids, [ "Moby Dick Chapter 1", 1 ], "...the correct ones"; 56} 57