Telen Stanley Telen Stanley - 11 days ago 5
PHP Question

PHP curl_setopt() is not returning the exact result_array from SOLR

I am using PHP cURL for retrieving the search result array from Solr.

- cURL Version : 7.47.1


the below code is searching for total shops in a particular city.
please see my code..

$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, "http://localhost:8983/solr/Search/select?q=searchshop%3A*&fq=" . $encode_fq_city . "&wt=php&fl=LoginInfoId");
curl_setopt($ch1, CURLOPT_HEADER, false);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
$shop = curl_exec($ch1);
curl_close($ch1);

print_r($shop);


I do
print_r
the
$shop_arr
array and the result is showing only the 10 records. the actual Solr
result_array
contains 14 records.

also attaching the result array..

[response] => Array
(
[numFound] => 14
[start] => 0
[docs] => Array
(
[0] => Array
(
[LoginInfoId] => 246
)

[1] => Array
(
[LoginInfoId] => 230
)

[2] => Array
(
[LoginInfoId] => 236
)

[3] => Array
(
[LoginInfoId] => 217
)

[4] => Array
(
[LoginInfoId] => 241
)

[5] => Array
(
[LoginInfoId] => 219
)

[6] => Array
(
[LoginInfoId] => 239
)

[7] => Array
(
[LoginInfoId] => 231
)

[8] => Array
(
[LoginInfoId] => 232
)

[9] => Array
(
[LoginInfoId] => 257
)

)

)


The result is showing
[numfound]=14
but only results 10 records.

is there any mistake in my scenario to get the
result_array
from Solr to PHP ?

is it a cURL Bug?

Answer

Solr by default returns 10 documents:

rows

This parameter is used to paginate results from a query. It specify the maximum number of documents from the complete result set to return to the client for every request. You can consider it as the maximum number of result appear in the page.

The default value is "10", which is used if the parameter is not specified. If you want to tell Solr to return all possible results from the query without an upper bound, specify rows to be 10000000 or some other ridiculously large value that is higher than the possible number of rows that are expected.

So add to your query a rows parameter, for example rows=100:

curl_setopt($ch1, CURLOPT_URL, "http://localhost:8983/solr/Search/select?q=searchshop%3A*&fq=" . $encode_fq_city . "&wt=php&fl=LoginInfoId&rows=100");

References:

Comments