Elastic::Model::Result - A wrapper for individual search results
version 0.02
$result = $results->next_result; $object = $result->object; $uid = $result->uid; \%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;
Elastic::Model::Result wraps the individual result returned from Elastic::Model::Results or Elastic::Model::Results::Scrolled.
$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.
'_source'
Also see Elastic::Manual::Scoping.
$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.
\%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.
\%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 = $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.
_score
$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.
\%raw_result = $result->result
The raw result hashref as returned by ElasticSearch.
\%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.
_source
Clinton Gormley <drtech@cpan.org>
This software is copyright (c) 2012 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.
To install Elastic::Model, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Elastic::Model
CPAN shell
perl -MCPAN -e shell install Elastic::Model
For more information on module installation, please visit the detailed CPAN module installation guide.