Skip to content

Commit

Permalink
In 0.90, don't support partials - just ignore the request
Browse files Browse the repository at this point in the history
  • Loading branch information
clintongormley committed Aug 16, 2014
1 parent ce1cb40 commit 26c92f1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
4 changes: 0 additions & 4 deletions lib/Elastic/Model/Result.pm
Expand Up @@ -13,10 +13,6 @@ around BUILDARGS => sub {
my $class = shift;
my $params = ref $_[0] eq 'HASH' ? shift : {@_};
my $fields = $params->{result}{fields};
if ( my $partial = delete $fields->{_partial_doc} ) {
$params->{result}{_source}
= ref $partial eq 'ARRAY' ? $partial->[0] : $partial;
}
for ( keys %$fields ) {
next if substr( $_, 0, 1 ) eq '_';
$fields->{$_} = [ $fields->{$_} ]
Expand Down
15 changes: 9 additions & 6 deletions lib/Elastic/Model/Role/Store.pm
Expand Up @@ -23,21 +23,22 @@ my @Top_Level = qw(
sub search {
#===================================
my $self = shift;
my $args = _tidy_search(@_);
my $args = _tidy_search( $self, @_ );
$self->es->search($args);
}

#===================================
sub scrolled_search {
#===================================
my $self = shift;
my $args = _tidy_search(@_);
my $args = _tidy_search( $self, @_ );
$self->es->scroll_helper($args);
}

#===================================
sub _tidy_search {
#===================================
my $self = shift;
my %body = ref $_[0] eq 'HASH' ? %{ shift() } : @_;
my %args;
for (@Top_Level) {
Expand All @@ -46,9 +47,11 @@ sub _tidy_search {
$args{$_} = $val;
}
}
my $source;
if ( $source = delete $body{_source} ) {
$body{partial_fields}{_partial_doc} = $source;
if ( $self->es->isa('Search::Elasticsearch::Client::0_90::Direct') ) {
if ( delete $body{_source} ) {
push @{ $body{fields} }, '_source'
unless grep { $_ eq '_source' } @{ $body{fields} };
}
}
$args{body} = \%body;
return \%args;
Expand All @@ -57,7 +60,7 @@ sub _tidy_search {
sub delete_by_query {
#===================================
my $self = shift;
my $args = _tidy_search(@_);
my $args = _tidy_search( $self, @_ );
$args->{body} = $args->{body}{query};
my $result = eval { $self->es->delete_by_query($args) };
return $result if $result;
Expand Down
6 changes: 2 additions & 4 deletions t/20_namespace/04_index_role.t
Expand Up @@ -95,8 +95,7 @@ sub test_domain {
sub get_interval {
my $name = shift;
my $settings
= $es->indices->get_settings( index => $name )
->{myapp3}{settings};
= $es->indices->get_settings( index => $name )->{myapp3}{settings};
return $settings->{"index.refresh_interval"}
|| $settings->{index}{refresh_interval};
}
Expand Down Expand Up @@ -135,8 +134,7 @@ SKIP: {
my $name = shift;
my $settings = $es->indices->get_settings( index => $name )
->{myapp3}{settings};
return $settings->{
"index.analysis.analyzer.edge_ngrams.tokenizer"}
return $settings->{"index.analysis.analyzer.edge_ngrams.tokenizer"}
|| $settings->{index}{analysis}{analyzer}{edge_ngrams}
{tokenizer};
}
Expand Down
10 changes: 7 additions & 3 deletions t/40_view/03_results.t
Expand Up @@ -11,6 +11,8 @@ use lib 't/lib';
our ( $es, $store );
do 'es.pl';

our $is_090 = $es->isa('Search::Elasticsearch::Client::0_90::Direct');

use_ok 'MyApp' || print 'Bail out';

my $model = new_ok( 'MyApp', [ es => $es ], 'Model' );
Expand Down Expand Up @@ -130,8 +132,7 @@ throws_ok sub { $it->index(-1000) }, qr/out of bounds/, 'Index out of bounds';
$it->reset;
is $it->_i, -1, 'Reset';

throws_ok sub { $it->index(20) }, qr/Values can be 0..9/,
'Index out of bounds';
throws_ok sub { $it->index(20) }, qr/Values can be 0..9/, 'Index out of bounds';
$it->shift for 1 .. 10;
throws_ok sub { $it->index(0) }, qr/ No values/, 'Empty index out of bounds';

Expand Down Expand Up @@ -249,8 +250,11 @@ sub test_single {
"$desc $name as partials - $id";
is $r->uid->is_partial, 1, "$desc $name as partials is partial";
ok $r->name, "$desc $name as partials has name";
ok !$r->{timestamp}, "$desc $name as partials has no timestamp";

SKIP: {
skip "Partials not supported in 0.90", 1 if $is_090;
ok !$r->{timestamp}, "$desc $name as partials has no timestamp";
}
}
else {
is my $r = $it->$el_method, undef, "$desc $el_method - undef";
Expand Down
7 changes: 6 additions & 1 deletion t/40_view/06_result.t
Expand Up @@ -125,7 +125,12 @@ isa_ok $result = $view->queryb( { name => 'Aardwolf' } ) #

isa_ok my $doc = $result->partial, 'MyApp::User', 'Partial->partial';
ok $doc->{name}, 'Partial has name';
ok !$doc->{timestamp}, 'Partial has no timestamp';
SKIP: {
skip "Partials not supported in 0.90", 1
if $es->isa('Search::Elasticsearch::Client::0_90::Direct');
ok !$doc->{timestamp}, 'Partial has no timestamp';
}

ok $doc->uid->is_partial, 'Partial UID is partial';

isa_ok $doc = $result->object, 'MyApp::User', 'Partial->object';
Expand Down

0 comments on commit 26c92f1

Please sign in to comment.