Which field(s) matched?

Is there a way to discover which fields in a document matched the search
that was performed?

I’ve just started with Ferret, but so far I can only get back the ids of
the documents that were matched (along with the score).

I’m aware there is a highlighting method, but I was hoping for something
computer readable (unless I’m misunderstanding what data can be gained
from that method).

Thanks
-Rob

Robert H. wrote:

Is there a way to discover which fields in a document matched the search
that was performed?

I’ve just started with Ferret, but so far I can only get back the ids of
the documents that were matched (along with the score).

I’m aware there is a highlighting method, but I was hoping for something
computer readable (unless I’m misunderstanding what data can be gained
from that method).

I’ve implemented a field_scores hash that can be returned along with
each document and aggregate score. It’s only currently working in
Ferret 0.11.4.

I’ve implemented a field_scores hash that can be returned along with
each document and aggregate score. It’s only currently working in
Ferret 0.11.4.
Could you please give a code example of how to do a query and get the
field_scores hash?

I have Ferret 0.11.6.

-Rob

Robert H. wrote:

I’ve implemented a field_scores hash that can be returned along with
each document and aggregate score. It’s only currently working in
Ferret 0.11.4.
Could you please give a code example of how to do a query and get the
field_scores hash?

I have Ferret 0.11.6.

Rob, FerretResult objects are given a ferret_field_scores attribute,
which is an array (not a hash, as I said above) of field_score objects,
in order of decreasing score. Field_score objects have “field” and
“score” attributes.

You specify which fields you want to see the field scores for by adding
the field_info option :field_score => :yes.

You can use field_scores to display an extract of the field that best
matches the user’s query:

@result.highlight @query, :field =>
@result.ferret_field_scores.first.field

It’d take some work to port it to Ferret 0.11.6, though I will do
this soon.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs