Nano::Search - Persisted Index Search
Persisted Index Search
use Nano::Nodes; use Nano::Search; my $nodes = Nano::Nodes->new( type => 'Nano::Node', ); my $search = Nano::Search->new( nodes => $nodes, ); # $search->count;
This package provides a mechanism for searching a prior persisted index.
This package uses type constraints from:
Nano::Types
This package has the following attributes:
nodes(Nodes)
This attribute is read-only, accepts (Nodes) values, and is required.
(Nodes)
orders(ArrayRef[CodeRef])
This attribute is read-only, accepts (ArrayRef[CodeRef]) values, and is optional.
(ArrayRef[CodeRef])
scopes(ArrayRef[CodeRef])
table(Table)
This attribute is read-only, accepts (Table) values, and is optional.
(Table)
This package implements the following methods:
all() : ArrayRef[Object]
The all method returns all objects (qualified via scopes, when present) from the index.
# given: synopsis my $result = $search->all;
# given: synopsis use Nano::Node; $search->nodes->set(Nano::Node->new); $search->nodes->set(Nano::Node->new); my $result = $search->all;
count() : Int
The count method returns the count of objects (qualified via scopes, when present) in the index.
# given: synopsis my $count = $search->count;
# given: synopsis use Nano::Node; $search->nodes->set(Nano::Node->new); $search->nodes->set(Nano::Node->new); my $count = $search->count;
fetch(Int $size = 1) : ArrayRef[Object]
The fetch method returns a variable number of objects (qualified via scopes, when present) from the index.
# given: synopsis my $result = $search->fetch;
# given: synopsis use Nano::Node; $search->nodes->set(Nano::Node->new); $search->nodes->set(Nano::Node->new); my $result = $search->fetch;
# given: synopsis use Nano::Node; $search->nodes->set(Nano::Node->new); $search->nodes->set(Nano::Node->new); $search->nodes->set(Nano::Node->new); my $result = $search->fetch(2);
first() : Maybe[Object]
The first method returns the first object (qualified via scopes, when present) from the index.
# given: synopsis my $first = $search->first;
# given: synopsis use Nano::Node; $search->nodes->set(Nano::Node->new(id => '1st')); $search->nodes->set(Nano::Node->new(id => '2nd')); $search->nodes->set(Nano::Node->new(id => '3rd')); my $first = $search->first;
last() : Maybe[Object]
The last method returns the last object (qualified via scopes, when present) from the index.
# given: synopsis my $last = $search->last;
# given: synopsis use Nano::Node; $search->nodes->set(Nano::Node->new(id => '1st')); $search->nodes->set(Nano::Node->new(id => '2nd')); $search->nodes->set(Nano::Node->new(id => '3rd')); my $last = $search->last;
next() : Maybe[Object]
The next method returns the next object based on the currently held cursor (qualified via scopes, when present) from the index.
# given: synopsis my $next = $search->next;
# given: synopsis use Nano::Node; $search->nodes->set(Nano::Node->new(id => '1st')); $search->nodes->set(Nano::Node->new(id => '2nd')); $search->nodes->set(Nano::Node->new(id => '3rd')); my $next = $search->next;
# given: synopsis use Nano::Node; $search->nodes->set(Nano::Node->new(id => '1st')); $search->nodes->set(Nano::Node->new(id => '2nd')); $search->nodes->set(Nano::Node->new(id => '3rd')); my $next; $next = $search->next; $next = $search->next;
order(ArrayRef[Object] $results) : ArrayRef[Object]
The order method determines the sort order of the array of objects provided based on the registered ordering routines.
# given: synopsis use Nano::Node; my $results = [ Nano::Node->new(id => '1st'), Nano::Node->new(id => '2nd'), Nano::Node->new(id => '3rd'), ]; $search = Nano::Search->new( nodes => $nodes, orders => [sub { my ($a, $b) = @_; $a->id cmp $b->id }], ); $results = $search->order($results);
# given: synopsis use Nano::Node; my $results = [ Nano::Node->new(id => '1st'), Nano::Node->new(id => '2nd'), Nano::Node->new(id => '3rd'), ]; $search = Nano::Search->new( nodes => $nodes, orders => [sub { my ($a, $b) = @_; $b->id cmp $a->id }], ); $results = $search->order($results);
prev() : Maybe[Object]
The prev method returns the previous object based on the currently held cursor (qualified via scopes, when present) from the index.
# given: synopsis my $prev = $search->prev;
# given: synopsis use Nano::Node; $search->table->position(3); $search->nodes->set(Nano::Node->new(id => '1st')); $search->nodes->set(Nano::Node->new(id => '2nd')); $search->nodes->set(Nano::Node->new(id => '3rd')); my $prev = $search->prev;
# given: synopsis use Nano::Node; $search->table->position(3); $search->nodes->set(Nano::Node->new(id => '1st')); $search->nodes->set(Nano::Node->new(id => '2nd')); $search->nodes->set(Nano::Node->new(id => '3rd')); my $prev; $prev = $search->prev; $prev = $search->prev;
reset() : Object
The reset method resets the position on the currently held cursor.
# given: synopsis $search = $search->reset;
scope(Object $object) : Maybe[Object]
The scope method determines whether the object provided passes-through the registered scopes and if-so returns the object provided.
# given: synopsis use Nano::Node; my $node = Nano::Node->new(id => '0000003'); my $result = $search->scope($node);
# given: synopsis use Nano::Node; $search = Nano::Search->new( nodes => $nodes, scopes => [sub { my ($node) = @_; $node->id ne '0000003' }], ); my $node = Nano::Node->new(id => '0000003'); my $result = $search->scope($node);
# given: synopsis use Nano::Node; $search = Nano::Search->new( nodes => $nodes, scopes => [sub { my ($node) = @_; $node->id ne '0000003' }], ); my $node = Nano::Node->new(id => '0000004'); my $result = $search->scope($node);
Al Newkirk, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".
Wiki
Project
Initiatives
Milestones
Contributing
Issues
To install Nano, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nano
CPAN shell
perl -MCPAN -e shell install Nano
For more information on module installation, please visit the detailed CPAN module installation guide.