NAME

Nano::Search - Persisted Index Search

ABSTRACT

Persisted Index Search

SYNOPSIS

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

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

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

# $search->count;

DESCRIPTION

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

LIBRARIES

This package uses type constraints from:

Nano::Types

ATTRIBUTES

This package has the following attributes:

cursor

cursor(Cursor)

This attribute is read-only, accepts (Cursor) values, and is optional.

lookup

lookup(Lookup)

This attribute is read-only, accepts (Lookup) values, and is optional.

nodes

nodes(Nodes)

This attribute is read-only, accepts (Nodes) values, and is required.

scopes

scopes(ArrayRef[CodeRef])

This attribute is read-only, accepts (ArrayRef[CodeRef]) values, and is optional.

METHODS

This package implements the following methods:

all

all() : ArrayRef[Object]

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

all example #1
# given: synopsis

my $result = $search->all;
all example #2
# given: synopsis

use Nano::Node;

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

my $result = $search->all;

count

count() : Int

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

count example #1
# given: synopsis

my $count = $search->count;
count example #2
# given: synopsis

use Nano::Node;

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

my $count = $search->count;

fetch

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

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

fetch example #1
# given: synopsis

my $result = $search->fetch;
fetch example #2
# given: synopsis

use Nano::Node;

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

my $result = $search->fetch;
fetch example #3
# 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

first() : Maybe[Object]

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

first example #1
# given: synopsis

my $first = $search->first;
first example #2
# 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

last() : Maybe[Object]

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

last example #1
# given: synopsis

my $last = $search->last;
last example #2
# 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

next() : Maybe[Object]

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

next example #1
# given: synopsis

my $next = $search->next;
next example #2
# 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;
next example #3
# 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;

prev

prev() : Maybe[Object]

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

prev example #1
# given: synopsis

my $prev = $search->prev;
prev example #2
# 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 $prev = $search->prev;
prev example #3
# 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 $prev;

$prev = $search->prev;
$prev = $search->prev;

reset

reset() : Object

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

reset example #1
# given: synopsis

$search = $search->reset;

scope

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.

scope example #1
# given: synopsis

use Nano::Node;

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

my $result = $search->scope($node);
scope example #2
# 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);
scope example #3
# 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);

AUTHOR

Al Newkirk, awncorp@cpan.org

LICENSE

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".

PROJECT

Wiki

Project

Initiatives

Milestones

Contributing

Issues