diff --git a/lib/WebService/Solr.pm b/lib/WebService/Solr.pm index bae6a26..292991c 100644 --- a/lib/WebService/Solr.pm +++ b/lib/WebService/Solr.pm @@ -161,7 +161,7 @@ sub generic_solr_request { $self->agent->post( $self->_gen_url( $path ), Content_Type => 'application/x-www-form-urlencoded; charset=utf-8', - Content => { $self->default_params, %$params } ) ) ); + Content => $self->_encode_content( { $self->default_params, %$params } ) ) ) ); } sub _gen_url { @@ -172,6 +172,18 @@ sub _gen_url { return $url; } +sub _encode_content { + my ( $self, $param ) = @_; + + if ( ref $param eq "HASH" ) { + return { map { $self->_encode_content($_) } %$param }; + } elsif ( ref $param eq "ARRAY" ) { + return [ map { $self->_encode_content($_) } @$param ]; + } else { + return encode('utf-8', $param); + } +} + sub _send_update { my ( $self, $xml, $params, $autocommit ) = @_; $autocommit = $self->autocommit unless defined $autocommit; diff --git a/t/request/search.t b/t/request/search.t index b1e05e0..d0070e9 100644 --- a/t/request/search.t +++ b/t/request/search.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 8; use Test::Mock::LWP; use WebService::Solr; @@ -28,6 +28,15 @@ my ( $expect_path, $expect_params ); is $solr->last_response, undef, "The last_response attribute hasn't been set yet"; $solr->search( 'foo' ); isa_ok $solr->last_response, 'WebService::Solr::Response'; + + $expect_params = { + q => "\xc3\x86\xc3\x98\xc3\x85", + wt => 'json', + fl => 'id', + fq => [ 'id:[0 TO 42]', "value:\xc3\x86\xc3\x98\xc3\x85" ] + }; + $solr->search( "\xc6\xd8\xc5", { fl => 'id', fq => [ 'id:[0 TO 42]', "value:\xc6\xd8\xc5" ] } ); + isa_ok $solr->last_response, 'WebService::Solr::Response'; } sub _test_req {