On 16/07/2013 12:44, Moritz Lenz wrote:
For my purposes it would be much nicer to obtain indexes into the string
where the search term was found, (or alternatively, let me set separate
callbacks for both the context and the search results) so that I could
do my own processing with that information.
This should be possible via the `highlight_spans` method of
`Lucy::Search::Compiler`. Something like the following should work, at
least that's what the highlighter does internally:
my $compiler = $query->make_compiler(searcher => $searcher);
my $doc_vec = $searcher->fetch_doc_vec($hit->get_doc_id);
my $spans = $compiler->highlight_spans(
searcher => $searcher,
doc_vec => $doc_vec,
field => $field,
);
for my $span (@$spans) {
my $offset = $span->get_offset;
my $length = $span->get_length;
my $weight = $span->get_weight;
}
`offset` and `length` are in Unicode code points. `fetch_doc_vec` is
undocumented, unfortunately.
Nick