NAME
Metabase::Index - Interface for Metabase indexing
VERSION
version 1.003
SYNOPSIS
package Metabase::Index::Bar;
use Metabase::Fact;
use Moose;
with 'Metabase::Index';
# define Moose attributes
sub add {
my ( $self, $fact ) = @_;
# index a fact
}
sub search {
my ( $self, %spec ) = @_;
# conduct search
return \@matches;
}
# ... implement other required methods ... *
DESCRIPTION
This module defines a Moose::Role for indexing and searching facts. Implementations for any particular backend indexer must provide all of the required methods described below.
METHODS
The following methods are provided by the Metabase::Index
role.
clone_metadata
my $metadata = $index->clone_metadata( $fact )
Assembles all three metadata types ('core', 'resource' and 'content') into a single-level hash by joining the type and the metadata name with a period. E.g. the guid
. field from the core metadata becomes core.guid
.
exists
if ( $index->exists( $guid ) ) { do_stuff() }
This method that calls search()
on the given GUID and returns a boolean value.
search
DEPRECATED
for $guid ( @{ $index->search( %query ) } ) {
# do stuff
}
Returns an arrayref of GUIDs satisfying the query parameters. The query must be given in the form described in Metabase::Query.
This method is deprecated in favor of query
and is included for backwards compatibility. It calls query
and accumulates all results before returning.
METHODS REQUIRED
The following methods must be implemented by consumers of the Metabase::Index
role.
Errors should throw exceptions rather than return false values.
add
$index->add( $fact );
Adds the given fact to the Metabase Index;
query
my $result = $index->search( %query );
while ( ! $result->is_done ) {
for $guid ( $result->items ) {
# do stuff
}
}
Returns a Data::Stream::Bulk iterator. Calling the iterator will return lists of GUIDs satisfying the query parameters. The query must be given in the form described in Metabase::Query. Valid fields for search are the keys from core, content, or resource metadata. E.g.
core.guid
core.type
core.resource
resource.somefield
content.somefield
See Data::Stream::Bulk for more on the iterator API.
count
my $count = $index->count( %query );
Takes query parameters and returns a count of facts satisfying the parameters. The query must be given in the form described in Metabase::Query, though -order
and -limit
clauses should not be included.
There is no guarantee that this query will take any less time than calling query
and counting all the results, though back end implementations are encouraged to optimize if possible. In the worst case, all results could be retrieved and then discarded.
delete
$index->delete( $guid );
Removes the fact with matching GUID from the index.
initialize
sub initialize {
my ($self, @fact_classes) = @_;
# prepare backend to store data (e.g. create database, etc.)
return;
}
Allows a backend to prepare to store various classes.
Metabase::Query methods
As Metabase::Index
consumes the Metabase::Query
role, all the required methods from that role must be implemented as well.
AUTHORS
David Golden <dagolden@cpan.org>
Ricardo Signes <rjbs@cpan.org>
Leon Brocard <acme@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by David Golden.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004