Metabase::Index - Interface for Metabase indexing
version 1.002
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 ... *
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.
The following methods are provided by the Metabase::Index role.
Metabase::Index
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.
guid
core.guid
exists
if ( $index->exists( $guid ) ) { do_stuff() }
This method that calls search() on the given GUID and returns a boolean value.
search()
search
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.
query
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;
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.
-order
-limit
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.
As Metabase::Index consumes the Metabase::Query role, all the required methods from that role must be implemented as well.
Metabase::Query
David Golden <dagolden@cpan.org>
Ricardo Signes <rjbs@cpan.org>
Leon Brocard <acme@cpan.org>
This software is Copyright (c) 2013 by David Golden.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
To install Metabase, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Metabase
CPAN shell
perl -MCPAN -e shell install Metabase
For more information on module installation, please visit the detailed CPAN module installation guide.