Clinton Gormley > Elastic-Model-0.27 > Elastic::Model::Result

Download:
Elastic-Model-0.27.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.27   Source   Latest Release: Elastic-Model-0.28

NAME ^

Elastic::Model::Result - A wrapper for individual search results

VERSION ^

version 0.27

SYNOPSIS ^

    $result             = $results->next_result;

    $object             = $result->object;
    $uid                = $result->uid;
    $partial_obj        = $result->partial;

    \%all_highlights    = $result->highlights;
    @field_highlights   = $result->highlight('field_name');

    \%all_fields        = $result->fields;
    $field_value        = $result->field('field_name');
    $script_field_value = $result->field('script_field_name');

    $explain            = $result->explain;
    $score              = $result->score;
    \%source_field      = $result->source;
    \%raw_result        = $result->result;

DESCRIPTION ^

Elastic::Model::Result wraps the individual result returned from Elastic::Model::Results, Elastic::Model::Results::Cached or Elastic::Model::Results::Scrolled.

ATTRIBUTES ^

object

    $object = $result->object();

The object associated with the result. By default, the "source" field is returned in search results, meaning that we can inflate the object directly from the search results. Note: If you set "fields" in Elastic::Model::View and you don't include '_source' then you will be unable to inflate your object without a separate (but automatic) step to retrieve it from Elasticsearch.

Also see Elastic::Manual::Scoping.

uid

index, type, id, routing

    $uid     = $result->uid;
    $index   = $result->index   | $result->uid->index;
    $type    = $result->type    | $result->uid->type;
    $id      = $result->id      | $result->uid->id;
    $routing = $result->routing | $result->uid->routing;

The uid of the doc. index, type, id and routing are provided for convenience.

partial

    $partial_obj = $result->partial_object();

If your objects are large, you may want to load only part of the object in your search results. You can specify which parts of the object to include or exclude using "include_paths / exclude_paths" in Elastic::Model::View.

The partial objects returned by "partial" function exactly as real objects, except that they cannot be saved.

highlights

highlight

    \%all_highlights  = $result->highlights;
    @field_highlights = $result->highlight('field_name');

The snippets from the highlighted fields in your view. "highlights" returns a hash ref containing snippets from all the highlighted fields, while "highlight" returns a list of the snippets for the named field.

fields

field

    \%all_fields        = $result->fields;
    $field_value        = $result->field('field_name');
    $script_field_value = $result->field('script_field_name');

The values of any fields or script_fields specified in your view.

score

    $score = $result->score;

The relevance score of the result. Note: if you sort on any value other than _score then the "score" will be zero, unless you also set "track_scores" in Elastic::Model::View to a true value.

explain

    $explanation = $result->explain;

If "explain" in Elastic::Model::View is set to true, then you can retrieve the text explanation using "explain", for instance:

    print $result->explain;

    Doc: [myapp|user|BS8mmGFhRdS5YcpeLkdw_g], Shard: [a7gbLmJWQE2EdIaP_Rnnew|4]:
     - product of:                                                 |    1.1442
       - sum of:                                                   |    2.2885
         - weight(name:aardwolf in 0), product of:                 |    2.2885
           - queryWeight(name:aardwolf), product of:               |    0.6419
             - idf(docFreq=1, maxDocs=26)                          |    3.5649
             - queryNorm                                           |    0.1801
           - fieldWeight(name:aardwolf in 0), product of:          |    3.5649
             - tf(termFreq(name:aardwolf)=1)                       |    1.0000
             - idf(docFreq=1, maxDocs=26)                          |    3.5649
             - fieldNorm(field=name, doc=0)                        |    1.0000
       - coord(1/2)                                                |    0.5000

And here's a brief explanation of what these numbers mean: http://www.lucenetutorial.com/advanced-topics/scoring.html.

result

    \%raw_result = $result->result

The raw result hashref as returned by Elasticsearch.

source

    \%source_field = $result->source

The _source field (ie the hashref which represents your object in Elasticsearch). This value is returned by default with any search, and is used to inflate your "object" without having to retrieve it in a separate step. Note: If you set "fields" in Elastic::Model::View and you don't include '_source' then you will be unable to inflate your object without a separate (but automatic) step to retrieve it from Elasticsearch.

AUTHOR ^

Clinton Gormley <drtech@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2013 by Clinton Gormley.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: