Nano::Search

Persisted Index Search

Persisted Index Search

method: all method: count method: fetch method: first method: last method: next method: order method: prev method: reset method: scope

use Nano::Nodes;
use Nano::Search;

my $nodes = Nano::Nodes->new(
  type => 'Nano::Node',
);

my $search = Nano::Search->new(
  nodes => $nodes,
);

# $search->count;

Nano::Types

nodes: ro, req, Nodes orders: ro, opt, ArrayRef[CodeRef] scopes: ro, opt, ArrayRef[CodeRef] table: ro, opt, Table

This package provides a mechanism for searching a prior persisted index.

The all method returns all objects (qualified via scopes, when present) from the index.

all() : ArrayRef[Object]

=example-1 all

# given: synopsis

my $result = $search->all;

=example-2 all

# given: synopsis

use Nano::Node;

$search->nodes->set(Nano::Node->new);
$search->nodes->set(Nano::Node->new);

my $result = $search->all;

The count method returns the count of objects (qualified via scopes, when present) in the index.

count() : Int

=example-1 count

# given: synopsis

my $count = $search->count;

=example-2 count

# given: synopsis

use Nano::Node;

$search->nodes->set(Nano::Node->new);
$search->nodes->set(Nano::Node->new);

my $count = $search->count;

The fetch method returns a variable number of objects (qualified via scopes, when present) from the index.

fetch(Int $size = 1) : ArrayRef[Object]

=example-1 fetch

# given: synopsis

my $result = $search->fetch;

=example-2 fetch

# given: synopsis

use Nano::Node;

$search->nodes->set(Nano::Node->new);
$search->nodes->set(Nano::Node->new);

my $result = $search->fetch;

=example-3 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);

The first method returns the first object (qualified via scopes, when present) from the index.

first() : Maybe[Object]

=example-1 first

# given: synopsis

my $first = $search->first;

=example-2 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;

The last method returns the last object (qualified via scopes, when present) from the index.

last() : Maybe[Object]

=example-1 last

# given: synopsis

my $last = $search->last;

=example-2 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;

The next method returns the next object based on the currently held cursor (qualified via scopes, when present) from the index.

next() : Maybe[Object]

=example-1 next

# given: synopsis

my $next = $search->next;

=example-2 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;

=example-3 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;

The order method determines the sort order of the array of objects provided based on the registered ordering routines.

order(ArrayRef[Object] $results) : ArrayRef[Object]

=example-1 order

# 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);

=example-2 order

# 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);

The prev method returns the previous object based on the currently held cursor (qualified via scopes, when present) from the index.

prev() : Maybe[Object]

=example-1 prev

# given: synopsis

my $prev = $search->prev;

=example-2 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;

=example-3 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;

The reset method resets the position on the currently held cursor.

reset() : Object

=example-1 reset

# given: synopsis

$search = $search->reset;

The scope method determines whether the object provided passes-through the registered scopes and if-so returns the object provided.

scope(Object $object) : Maybe[Object]

=example-1 scope

# given: synopsis

use Nano::Node;

my $node = Nano::Node->new(id => '0000003');

my $result = $search->scope($node);

=example-2 scope

# 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);

=example-3 scope

# 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);

28 POD Errors

The following errors were encountered while parsing the POD:

Around line 10:

Unknown directive: =name

Around line 16:

Unknown directive: =tagline

Around line 22:

Unknown directive: =abstract

Around line 28:

Unknown directive: =includes

Around line 43:

Unknown directive: =synopsis

Around line 60:

Unknown directive: =libraries

Around line 66:

Unknown directive: =attributes

Around line 75:

Unknown directive: =description

Around line 81:

Unknown directive: =method

Around line 86:

Unknown directive: =signature

Around line 109:

Unknown directive: =method

Around line 114:

Unknown directive: =signature

Around line 137:

Unknown directive: =method

Around line 142:

Unknown directive: =signature

Around line 177:

Unknown directive: =method

Around line 182:

Unknown directive: =signature

Around line 206:

Unknown directive: =method

Around line 211:

Unknown directive: =signature

Around line 235:

Unknown directive: =method

Around line 240:

Unknown directive: =signature

Around line 279:

Unknown directive: =method

Around line 284:

Unknown directive: =signature

Around line 334:

Unknown directive: =method

Around line 339:

Unknown directive: =signature

Around line 382:

Unknown directive: =method

Around line 386:

Unknown directive: =signature

Around line 398:

Unknown directive: =method

Around line 403:

Unknown directive: =signature