The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

SolarBeam::Response - Represents a Solr search response

SYNOPSIS

 use SolarBeam::Response;
 my $tx = Mojo::UserAgent->new->post($solr_url, form => \%query);
 my $res = SolarBeam::Response->new->parse($tx);

 if ($res->error) {
    die sprintf "%s: %s", $res->error->{code} || 0, $res->error->{message};
 }

 for my $doc (@{$res->docs}) {
    say $doc->{surname};
 }

DESCRIPTION

SolarBeam::Response holds the response from "autocomplete" in SolarBeam or "search" in SolarBeam.

ATTRIBUTES

docs

  $array_ref = $self->docs;
  $self = $self->docs([{}, ...]);

Holds a list of the documents retrieved from Solr.

error

  $hash_ref = $self->error;
  $self = $self->error({message => "Error message", code => 500});

Holds either a hash-ref with error details or undef() if no error is detected. This attribute is modeled the same way as "error" in Mojo::Transaction, but can also contain detailed error messages from the Solr server.

facet_dates

  $hash_ref = $self->facet_dates;

TODO.

facet_fields

  $hash_ref = $self->facet_fields;

TODO.

facet_queries

  $hash_ref = $self->facet_queries;

TODO.

facet_ranges

  $hash_ref = $self->facet_ranges;

TODO.

num_found

  $int = $self->num_found;

Holds the number of matching documents. This number can be higher than the number of elements in "docs".

pager

  $pager = $self->pager;
  $self = $self->pager(Data::Page->new);

Holds a Data::Page object.

params

  $hash_ref = $self->params;

Holds the search params sent to Solr.

query_time

  $int = $self->query_time;

The time the search took.

start

  $int = $self->start;

Offset of the search result.

terms

    $hash_ref = $self->terms;

tx

    last tx passed to parse

TODO

METHODS

facet_fields_as_hashes

    $hash_ref = $self->facet_fields_as_hashes;

Turns the arrays in "facet_fields" into hashes instead. Example:

    $self->facet_fields = {colors => [{value => "red", count => 42}]};
    $self->facet_fields_as_hashes = {colors => {red => 42}}

parse

    $self = $self->parse(Mojo::Transaction->new);

Used to parse the result from a query. Will populate the different "ATTRIBUTES".

SEE ALSO

SolarBeam.