Skip to content

Commit

Permalink
es > 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nics committed Nov 4, 2014
2 parents 420447c + c66b432 commit 99f80a3
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ my $builder = Module::Build->new(
},
requires => {
'perl' => '5.10.1',
'Catmandu' => '0.8',
'Catmandu' => '0.9206',
'CQL::Parser' => '1.12',
'Moo' => '1.00',
'Search::Elasticsearch' => '1.11',
'Search::Elasticsearch' => '1.14',
},
add_to_cleanup => [qw(
Catmandu-Store-Elasticsearch-*
Expand Down
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Revision history for Catmandu-Store-Elasticsearch
0.01 2014-04-29
- Continue development from Catmandu::Store::ElasticSearch with the
official Search::Elasticsearch client

57 changes: 51 additions & 6 deletions lib/Catmandu/Store/Elasticsearch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@ sub drop {

=head1 METHODS
=head2 new(index_name => $name, cql_mapping => \%mapping)
=head2 new(index_name => $name)
Create a new Catmandu::Store::Elasticsearch store connected to index $name. The
store supports CQL searches when a cql_mapping is provided. This hash
=head2 new(index_name => $name , bags => { data => { cql_mapping => \%mapping } })
=head2 new(index_name => $name , index_mapping => $mapping)
Create a new Catmandu::Store::ElasticSearch store connected to index $name.
The store supports CQL searches when a cql_mapping is provided. This hash
contains a translation of CQL fields into Elasticsearch searchable fields.
# Example mapping
Expand Down Expand Up @@ -118,7 +123,7 @@ The CQL mapping allows for sorting on the 'title' field. If, for instance, we wo
Elasticsearch field for sorting we could have written "sort => { field => 'mytitle.sort' }".
The CQL has an optional callback field 'cb' which contains a reference to subroutines to rewrite or
augment the search query. In this case, in the Biblio::Search package there is a normalize_title
augment the search query. In this case, in the Biblio::Search package there is a normalize_title
subroutine which returns a string or an ARRAY of string with augmented title(s). E.g.
package Biblio::Search;
Expand All @@ -131,11 +136,44 @@ subroutine which returns a string or an ARRAY of string with augmented title(s).
1;
Optionally, index_mappings contain Elastic Search schema mappings. E.g.
# The 'data' index can ony contain one field 'title' of type 'string'
index_mappings => {
data => {
dynamic => 'strict',
properties => {
title => { type => 'string' }
}
}
}
=head2 drop
Deletes the elasticsearch index backing this store. Calling functions after
this may fail until this class is reinstantiated, creating a new index.
=head1 COMPATIBILITY
This store expects version 1.0 or higher of the Elasticsearch server.
=head1 ERROR HANDLING
Error handling can be activated by specifying an error handling callback for index when creating
a store. E.g. to create an error handler for the bag 'data' index use:
my $store = Catmandu::Store::ElasticSearch->new(
index_name => 'catmandu'
bags => { data => { on_error => \&error_handler } }
});
sub error_handler {
my ($action,$response,$i) = @_;
}
See: http://search.cpan.org/~drtech/ElasticSearch-0.68/lib/ElasticSearch.pm#Error_handlers for more
information.
=head1 SEE ALSO
L<Catmandu::Store>
Expand All @@ -146,8 +184,15 @@ Nicolas Steenlant, C<< <nicolas.steenlant at ugent.be> >>
=head1 CONTRIBUTORS
Dave Sherohman, C<< dave.sherohman at ub.lu.se >>
Robin Sheat, C<< robin at kallisti.net.nz >>
=over 4
=item Dave Sherohman, C<< dave.sherohman at ub.lu.se >>
=item Robin Sheat, C<< robin at kallisti.net.nz >>
=item Patrick Hochstenbach, C<< patrick.hochstenbach at ugent.be >>
=back
=head1 LICENSE AND COPYRIGHT
Expand Down
8 changes: 3 additions & 5 deletions lib/Catmandu/Store/Elasticsearch/Bag.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ with 'Catmandu::Searchable';
has buffer_size => (is => 'ro', lazy => 1, builder => 'default_buffer_size');
has _bulk => (is => 'ro', lazy => 1, builder => '_build_bulk');
has cql_mapping => (is => 'ro');
has on_error => (is => 'ro', default => sub { 'IGNORE'} );

sub default_buffer_size { 100 }

Expand All @@ -21,14 +22,11 @@ sub _build_bulk {
index => $self->store->index_name,
type => $self->name,
max_count => $self->buffer_size,
on_error => sub {
my ($action, $res, $i) = @_;
$self->log->error($res);
},
on_error => $self->on_error,
);
if ($self->log->is_debug) {
$args{on_success} = sub {
my ($action, $res, $i) = @_;
my ($action, $res, $i) = @_; # TODO return doc instead of index
$self->log->debug($res);
};
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Catmandu/Store/Elasticsearch/CQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ sub _term_node {
map { _text_node($q, $_) } @$term;
} @$qualifier ] } };
} else {
if ($qualifier eq '_id') {
return { ids => { values => $term } };
}
return { bool => { should => [map { _text_node($qualifier, $_) } @$term] } };
}
} elsif ($base eq 'all') {
Expand Down

0 comments on commit 99f80a3

Please sign in to comment.