Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

UIDs from search results missing routing

Closes #14
  • Loading branch information...
commit 939b507b6a870269111af1438a4078f32c14b3a6 1 parent 0521a84
@clintongormley authored
Showing with 104 additions and 2 deletions.
  1. +2 −2 lib/Elastic/Model/UID.pm
  2. +102 −0 t/40_view/06_routing.t
View
4 lib/Elastic/Model/UID.pm
@@ -79,7 +79,7 @@ sub new_from_store {
my %params = %{ shift() };
$class->new(
from_store => 1,
- routing => $params{fields}{routing},
+ routing => $params{fields}{_routing},
map { $_ => $params{"_$_"} } qw(index type id version)
);
}
@@ -92,7 +92,7 @@ sub new_partial {
$class->new(
from_store => 1,
is_partial => 1,
- routing => $params{fields}{routing},
+ routing => $params{fields}{_routing},
map { $_ => $params{"_$_"} } qw(index type id version)
);
}
View
102 t/40_view/06_routing.t
@@ -0,0 +1,102 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More 0.96;
+use Test::Exception;
+use Test::Deep;
+use Test::Moose;
+
+use lib 't/lib';
+
+our ( $es, $store );
+do 'es.pl';
+
+use_ok 'MyApp' || print 'Bail out';
+
+my $model = new_ok( 'MyApp', [ es => $es ], 'Model' );
+ok my $ns = $model->namespace('myapp'), 'Got ns';
+
+ok $ns->index('myapp2')->create, 'Create index myapp2';
+ok $ns->alias()->to('myapp2'), 'Add index to ns';
+ok $ns->alias('myapp3')->to( myapp2 => { routing => 'foo' } ),
+ 'Create alias myapp3';
+
+ok my $doc = $model->domain('myapp3')->create( user => { name => 'John' } ),
+ 'Create routed doc';
+ok $ns->index('myapp2')->refresh, 'Refresh index';
+
+note "Routing from main alias";
+
+is $model->view->domain('myapp')->search->first_result->uid->routing, 'foo',
+ 'search myapp/result';
+is $model->view->domain('myapp')->search->first_object->uid->routing, 'foo',
+ 'search myapp/object';
+is $model->view->domain('myapp')->include_paths('*')
+ ->search->first_object->uid->routing, 'foo', 'search myapp/partial';
+
+is $model->view->domain('myapp')->scroll->first_result->uid->routing, 'foo',
+ 'scroll myapp/result';
+is $model->view->domain('myapp')->scroll->first_object->uid->routing, 'foo',
+ 'scroll myapp/object';
+is $model->view->domain('myapp')->include_paths('*')
+ ->scroll->first_object->uid->routing, 'foo', 'scroll myapp/partial';
+
+is $model->view->domain('myapp')->scan->first_result->uid->routing, 'foo',
+ 'scan myapp/result';
+is $model->view->domain('myapp')->scan->first_object->uid->routing, 'foo',
+ 'scan myapp/object';
+is $model->view->domain('myapp')->include_paths('*')
+ ->scan->first_object->uid->routing, 'foo', 'scan myapp/partial';
+
+
+note "Routing from real index";
+
+is $model->view->domain('myapp2')->search->first_result->uid->routing, 'foo',
+ 'search myapp2/result';
+is $model->view->domain('myapp2')->search->first_object->uid->routing, 'foo',
+ 'search myapp2/object';
+is $model->view->domain('myapp2')->include_paths('*')
+ ->search->first_object->uid->routing, 'foo', 'search myapp2/partial';
+
+is $model->view->domain('myapp2')->scroll->first_result->uid->routing, 'foo',
+ 'scroll myapp2/result';
+is $model->view->domain('myapp2')->scroll->first_object->uid->routing, 'foo',
+ 'scroll myapp2/object';
+is $model->view->domain('myapp2')->include_paths('*')
+ ->scroll->first_object->uid->routing, 'foo', 'scroll myapp2/partial';
+
+is $model->view->domain('myapp2')->scan->first_result->uid->routing, 'foo',
+ 'scan myapp2/result';
+is $model->view->domain('myapp2')->scan->first_object->uid->routing, 'foo',
+ 'scan myapp2/object';
+is $model->view->domain('myapp2')->include_paths('*')
+ ->scan->first_object->uid->routing, 'foo', 'scan myapp2/partial';
+
+
+note "Routing from filtered alias";
+
+is $model->view->domain('myapp3')->search->first_result->uid->routing, 'foo',
+ 'search myapp3/result';
+is $model->view->domain('myapp3')->search->first_object->uid->routing, 'foo',
+ 'search myapp3/object';
+is $model->view->domain('myapp3')->include_paths('*')
+ ->search->first_object->uid->routing, 'foo', 'search myapp3/partial';
+
+is $model->view->domain('myapp3')->scroll->first_result->uid->routing, 'foo',
+ 'scroll myapp3/result';
+is $model->view->domain('myapp3')->scroll->first_object->uid->routing, 'foo',
+ 'scroll myapp3/object';
+is $model->view->domain('myapp3')->include_paths('*')
+ ->scroll->first_object->uid->routing, 'foo', 'scroll myapp3/partial';
+
+is $model->view->domain('myapp3')->scan->first_result->uid->routing, 'foo',
+ 'scan myapp3/result';
+is $model->view->domain('myapp3')->scan->first_object->uid->routing, 'foo',
+ 'scan myapp3/object';
+is $model->view->domain('myapp3')->include_paths('*')
+ ->scan->first_object->uid->routing, 'foo', 'scan myapp3/partial';
+
+done_testing;
+
+__END__
Please sign in to comment.
Something went wrong with that request. Please try again.