basho / riak-php-client

PHP clients for Riak
Apache License 2.0
160 stars 69 forks source link

Search with sort is returning null [JIRA: CLIENTS-883] #121

Closed imaimai86 closed 8 years ago

imaimai86 commented 8 years ago

When i query my index using http client with following parameters, it returns me proper results, but php client is not giving me results. Removing the sort option in php client returns results

Host::8098/search/query/indx_profile?wt=json&q=profile_name_s_register:*&sort=profile_name_s_register%20asc&start=0&rows=500

{ "responseHeader": { "status": 0, "QTime": 13, "params": { "127.0.0.1:8293": "_yz_pn:47 OR _yz_pn:32 OR _yz_pn:17 OR _yz_pn:2", "shards": "127.0.0.1:8193/internal_solr/indx_profile,127.0.0.1:8293/internal_solr/indx_profile,127.0.0.1:8393/internal_solr/indx_profile,127.0.0.1:8493/internal_solr/indx_profile,10.28.50.80:8093/internal_solr/indx_profile", "sort": "profile_name_s_register asc", "127.0.0.1:8193": "_yz_pn:56 OR _yz_pn:41 OR _yz_pn:26 OR _yz_pn:11", "start": "0", "q": "profile_name_s_register:00", "10.28.50.80:8093": "(_yz_pn:60 AND (_yz_fpn:60)) OR _yz_pn:50 OR _yz_pn:35 OR _yz_pn:20 OR _yz_pn:5", "wt": "json", "127.0.0.1:8393": "_yz_pn:63 OR _yz_pn:53 OR _yz_pn:38 OR _yz_pn:23 OR _yz_pn:8", "127.0.0.1:8493": "_yz_pn:59 OR _yz_pn:44 OR _yz_pn:29 OR _yz_pn:14", "rows": "500" } }, "response": { "numFound": 24, "start": 0, "docs": [ { "profile_name_s_register": "000001", "profile_name_biography_s_register": "Search Profile 2012 - ", "profile_genre_s_register": "", "profile_biography_s_register": "Test biography something", "mediacollection_name_s_register": "Media search in", "_yz_id": "1_profiles_idx_profiles_idx_041b20f8-59ac-4e1d-b870-22342e1b5e18_11", "_yz_rk": "041b20f8-59ac-4e1d-b870-22342e1b5e18", "_yz_rt": "profiles_idx", "_yz_rb": "profiles_idx" }, {..}...{..} { "profile_name_s_register": "000001", "profile_name_biography_s_register": "Search Profile 2012 - ", "profile_genre_s_register": "", "profile_biography_s_register": "Test biography something", "mediacollection_name_s_register": "Media search in", "_yz_id": "1_profiles_idx_profiles_idx_041b20f8-59ac-4e1d-b870-22342e1b5e18_11", "_yz_rk": "041b20f8-59ac-4e1d-b870-22342e1b5e18", "_yz_rt": "profiles_idx", "_yz_rb": "profiles_idx" } ] } }

But when i add sort option in php client using "withSortField", it is not returning any results.

$command = (new Command\Builder\Search\FetchObjects($riak))
                ->withIndexName($index)
                ->withQuery('profile_name_s_register:*')                
                ->withMaxRows(500)
                ->withStartRow(0)
                ->withSortField( 'sort=profile_name_s_register asc' );

            $response = $command->build()
                ->execute();

object(Basho\Riak\Command\Search\Response)[174] protected 'numFound' => int 0 protected 'docs' => array (size=0) empty protected 'success' => boolean true protected 'code' => int 400 protected 'message' => string '' (length=0)

I dumped the command variable and got the following response

ROOT_FOLDER/basho/riak/src/Riak.php:164: object(Basho\Riak\Command\Search\Fetch)[173] protected 'response' => null protected 'index_name' => string 'indxprofile' (length=12) protected 'method' => string 'GET' (length=3) protected 'parameters' => array (size=5) 'wt' => string 'json' (length=4) 'rows' => int 10 'start' => int 0 'q' => string ':_' (length=3) 'sort' => string 'profile_name_s_register' (length=23) protected 'bucket' => null protected 'riak' => object(Basho\Riak)[168] protected 'nodes' => array (size=1) 0 => object(Basho\Riak\Node)[170] ... protected 'config' => array (size=5) 'prefix' => string 'riak' (length=4) 'mapred_prefix' => string 'mapred' (length=6) 'index_prefix' => string 'buckets' (length=7) 'dns_server' => string '**' (length=7) 'max_connect_attempts' => int 3 protected 'activeNodeIndex' => int 0 protected 'api' => object(Basho\Riak\Api\Http)[169] protected 'requestBody' => string '' (length=0) protected 'responseHeaders' => array (size=0) ... protected 'responseBody' => string '' (length=0) protected 'statusCode' => int 0 protected 'connection' => null protected 'path' => string '' (length=0) protected 'query' => string '' (length=0) private 'options' => array (size=0) ... protected 'headers' => array (size=0) ... protected 'request' => string '' (length=0) protected 'response' => null protected 'command' => null protected 'node' => null protected 'success' => null protected 'error' => string '' (length=0) protected 'config' => array (size=5) ... protected 'inactiveNodes' => array (size=0) empty protected 'attempts' => int 0 protected 'verbose' => boolean false

christophermancini commented 8 years ago

Thanks for creating this issue @imaimai86 . I will be looking it over and try to determine a resolution as soon as possible.

christophermancini commented 8 years ago

Hi @imaimai86, sorry for the delay. I dug into it and I think I found your problem. When you are using the WithSortField() method, you are passing in the sort= as a prefix, which is handled for you automatically by the PHP client. If you simply pass in your field name and direction, it should work, e.g. profile_name_s_register asc.

To provide an example and ensure this works properly, I added a test to the test suite which you can see here: https://github.com/basho/riak-php-client/blob/develop/tests/functional/SearchOperationsTest.php#L181

imaimai86 commented 8 years ago

Hi,

I removed the "sort =" from the query, Now I am getting results but not sorted.

->withSortField( 'profile_name_s_register asc' );

Is there any additional configuration so that the sort will work in riak. I am getting sorted results using http client.