Data::SearchEngine::Results - Results of a Data::SearchEngine serach


Data-SearchEngine documentation Contained in the Data-SearchEngine distribution.

Index


Code Index:

NAME

Top

Data::SearchEngine::Results - Results of a Data::SearchEngine serach

SYNOPSIS

Top

The Results object holds the list of items found during a query. They are usually sorted by a score. This object provides some standard attributes you are likely to use.

    use Data::SearchEngine::Item;
    use Data::SearchEngine::Results;
    use Time::HiRes;

    sub query {

        # boring, search specific implementation

        my $results = Data::SearchEngine::Results->new(
            query       => $query
            pager       => Data::Page->new(...)
        );

        my $start = time;
        foreach $product (@sorted_products) {
            my $item = Data::SearchEngine::Item->new(
                id      => $product->id,            # unique product id
                score   => $scores->{$product->id}  # make your own scores
            ));

            $item->set_value('url', 'http://example.com/product/'.$product->id);
            $item->set_value('price', $product->price);

            $results->add($item);
        }
        $results->elapsed(time - $start);

        return $results;
    }

SERIALIZATION

Top

This module uses MooseX::Storage::Deferred to provide serialization. You may serialize it thusly:

  my $json = $results->freeze({ format => 'JSON' };
  # ...
  my $results = Data::SearchEngine::Results->thaw($json, { format => 'JSON' });

ATTRIBUTES

Top

add ($item)

Add an item to this result.

count

Count of items in this result.

elapsed

The time it took to complete this search.

get ($n)

Get the nth item.

items

The list of Data::SearchEngine::Items found for the query.

pager

The Data::Page for this result.

query

The Data::SearchEngine::Query that yielded this Results object.

METHODS

Top

Appends an Item onto the end of this Results object's item list.

Gets the item at the specified index.

AUTHOR

Top

Cory G Watson, <gphat at cpan.org>

COPYRIGHT & LICENSE

Top


Data-SearchEngine documentation Contained in the Data-SearchEngine distribution.

package Data::SearchEngine::Results;
use Moose;
use MooseX::Storage;

with 'MooseX::Storage::Deferred';

has elapsed => (
    is => 'rw',
    isa => 'Num'
);
has items => (
    traits => [ 'Array' ],
    is => 'rw',
    isa => 'ArrayRef[Data::SearchEngine::Item]',
    default => sub { [] },
    handles => {
        count   => 'count',
        get     => 'get',
        add     => 'push',
    }
);
has query => (
    is => 'ro',
    isa => 'Data::SearchEngine::Query',
    required => 1,
);
has pager => (
    is => 'ro',
    isa => 'Data::SearchEngine::Paginator'
);

__PACKAGE__->meta->make_immutable;

1;

__END__