package Grey::U::Model::Kioku; use Moose; use Grey::U::Backend::Kioku; has 'backend' => ( is => 'ro', isa => 'Grey::U::Backend::Kioku', required => 1, ); sub COMPONENT { my ($self, $app, $args) = @_; $self->new( backend => Grey::U::Backend::Kioku->new( %$args, ), ); } sub ACCEPT_CONTEXT { my ($self, $c, @args) = @_; my $be = $self->backend; $c->stash->{__kioku_scope} ||= $be->db->new_scope; return $be; } 1; --------------------------- Search::GIN::Extract::Callback->new( extract => sub { my ( $obj, $gin, %args ) = @_; my $l = $args{live_objects}; if ( $obj->isa("Grey::U::Schema::Tag" ) ) { return { tag_name => $obj->name, type => "tag", }; } elsif ( $obj->isa("Grey::U::Schema::User") ) { return { ldap_id => $obj->ldap_id, type => "user", }; } elsif ( $obj->isa("Grey::U::Schema::Tutorial") ) { return { type => "tutorial", }; } elsif ( $obj->isa("Grey::U::Schema::Curriculum") ) { return; } return; }, ); # later on ... my ( $users, $tags, $tutorials ) = map { Search::GIN::Query::Manual->new( values => { type => $_ } ) } qw(user tag tutorial); sub list_users { my $self = shift; $self->search($users); } sub list_tutorials { my $self = shift; $self->search($tutorials); } sub list_tags { my $self = shift; $self->search($tags); } --------------------------------- has db => ( is => 'ro', isa => 'KiokuDB', lazy_build => 1, handles => [qw( new_scope lookup store insert update search delete object_to_id objects_to_ids live_objects txn_do )], ); sub _build_db { my $self = shift; my @extra = $self->extra_options; return KiokuDB->new( typemap => get_typemap(), backend => $self->backend_class->new( manager => { home => $self->storage, @extra, }, extract => $self->gin_extractor, @extra, ), @extra, ); } has gin_extractor => ( does => "Search::GIN::Extract", is => "ro", lazy_build => 1, ); sub _build_gin_extractor { my ( $self, %args ) = @_; Search::GIN::Extract::Callback->new( extract => sub { my ( $obj, $gin, %args ) = @_; my $l = $args{live_objects}; if ( $obj->isa("Grey::U::Schema::Tag" ) ) { return { tag_name => $obj->name, type => "tag", }; } elsif ( $obj->isa("Grey::U::Schema::User") ) { return { ldap_id => $obj->ldap_id, type => "user", }; } elsif ( $obj->isa("Grey::U::Schema::Tutorial") ) { return { type => "tutorial", }; } elsif ( $obj->isa("Grey::U::Schema::Curriculum") ) { return; } return; }, ); }