Marvin Humphrey wrote on 8/30/11 4:59 PM:

> Make sure that you spec every field as "highlightable".  Then, at search time,
> try something like this:
> 
>     my $query = $query_parser->parse($query_string);
>     my $compiler = $query->make_compiler(searcher => $searcher);
>     my $hits = $searcher->hits;
>     while (my $hit = $hits->next) {
>         my $doc_vec = $searcher->fetch_doc_vec($hit->get_doc_id);
>         my @relevant_fields;
>         for my $field (@{ $schema->all_fields }) {
>             my $spans = $compiler->highlight_spans(
>                 searcher => $searcher,
>                 doc_vec  => $doc_vec,
>                 field    => $field,
>             );
>             if (@$spans) {
>                 push @relevant_fields, $field;
>             }
>         }
>         print "Relevant fields: ";
>         print join ", ", @relevant_fields;
>         print "\n";
>     }
> 
> If a field produces highlight spans, it was relevant.  If it doesn't produce
> highlight spans, it wasn't relevant.
> 
> Does that work?
> 

it does, quite well, thank you.

I've added a find_relevant_fields() method to SWISH::Prog::Lucy::Results that
implements the above nearly verbatim.

Aside from the index size increase, I think this is a win for this problem.

Thanks, Marvin.


-- 
Peter Karman  .  http://peknet.com/  .  [email protected]

Reply via email to