Class: Ferret::Search::Explanation

Summary

Explanation is used to give a description of why a document matched with the score that it did. Use the Explanation#to_s or Explanation#to_html methods to display the explanation in a human readable format. Creating explanations is an expensive operation so it should only be used for debugging purposes. To create an explanation use the Searcher#explain method.

Example

  puts searcher.explain(query, doc_id).to_s

Public Instance Methods


explanation.score → float

Returns the score represented by the query. This can be used for debugging purposes mainly to check that the score returned by the explanation matches that of the score for the document in the original query.

/*
 *  call-seq:
 *     explanation.score -> float
 *
 *  Returns the score represented by the query. This can be used for debugging
 *  purposes mainly to check that the score returned by the explanation
 *  matches that of the score for the document in the original query.
 */
static VALUE
frt_expl_score(VALUE self)
{
    GET_EXPL();
    return rb_float_new((double)expl->value);
}

explanation.to_html → string

Returns an html representation of the explanation in readable format.

/*
 *  call-seq:
 *     explanation.to_html -> string
 *
 *  Returns an html representation of the explanation in readable format.
 */
static VALUE
frt_expl_to_html(VALUE self)
{
    GET_EXPL();
    char *str = expl_to_html(expl);
    VALUE rstr = rb_str_new2(str);
    free(str);
    return rstr;
}

explanation.to_s → string

Returns a string representation of the explanation in readable format.

/*
 *  call-seq:
 *     explanation.to_s -> string
 *
 *  Returns a string representation of the explanation in readable format.
 */
static VALUE
frt_expl_to_s(VALUE self)
{
    GET_EXPL();
    char *str = expl_to_s(expl);
    VALUE rstr = rb_str_new2(str);
    free(str);
    return rstr;
}