Ruby Forum Ferret > Use Index#highlight with custom key instead of doc_id

Posted by Eric Duminil (eric_duminil)
on 26.04.2008 14:35
Hi!

I'd like to highlight matching content of a document for a given query.
I use
    index.highlight(query, doc_id,
                            :field => :content, :excerpt_length => :all,
                            :pre_tag => "<<", :post_tag => ">>"
    )
for this. Problem is, I defined my index with a :key => some_hash, and
I'd like to give index.highlight query and some_hash as parameters,
since I have no idea what doc_id is for a given LazyDoc.

Is there a way to retrieve doc_id from a LazyDoc?
Would that be possible to provide index#highlight with a custom key
instead of doc_id?

As a work-around I retrieve doc_id like this:
index.search(Ferret::Search::TermQuery.new(:some_hash,some_hash)).hits.first.doc
which I suppose isn't really optimal.

Any suggestion would be greatly appreciated!

Thanks in advance,
Eric