The code:
#!/usr/bin/perl use warnings; #use strict; use Plucene::Document; use Plucene::Document::Field; use Plucene::Index::Writer; use Plucene::Analysis::SimpleAnalyzer; use Plucene::QueryParser; use Plucene::Search::IndexSearcher; use Data::Dumper; my $content = join("",<DATA>); my $doc = Plucene::Document->new; $doc->add(Plucene::Document::Field->Text("content", $content)); my $writer = Plucene::Index::Writer->new("my_index", Plucene::Analysis::SimpleAnalyzer->new(), 1); $writer->add_document($doc); undef $writer; # close my @docs; my $parser = Plucene::QueryParser->new({ analyzer => Plucene::Analysis::SimpleAnalyzer->new(), default => "text" # Default field for non-specified q +ueries }); my $query = $parser->parse('content:Craigslist appears to have surrend +ered'); my $searcher = Plucene::Search::IndexSearcher->new("my_index"); my $hc = Plucene::Search::HitCollector->new(collect => sub { my ($self, $doc, $score) = @_; push @docs, $searcher->doc($doc); }); $searcher->search_hc($query, $hc); print Dumper @docs;

As you can see I print the docs array, but this array doesn't contain the matching strings


In reply to Re^2: Get matching strings by searching with PLucene by explodec14
in thread Get matching strings by searching with PLucene by explodec14

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.