I am using Apache Solr Engine to provide suggestions to the user based on the input keyword.
I have a json response in the following format.
{
"suggest": {
"mySuggester": {
"A Ga": {
"numFound": 2,
"suggestions": [
{
"term": "<b>A Ga</b>me of Thrones",
"weight": 0,
"payload": "Book"
},
{
"term": "<b>A Ga</b>teway to Heaven",
"weight": 0,
"payload": "Book"
}]
}
}
}
}
The Key A Gais user input, that is, based on this key, the suggestions are provided. Now Solr returns this JSON which is stored in my $response variable in php and the key A Ga is contained in the variable $inp.
In my code, there is a line which is,
$noOfSuggestions = $response->suggest->mySuggester->$inp->numFound;
I am getting a cannot access empty property error at this line. Is my usage of $inp correct?
Thanks!
EDIT: This is var_dump($response);
object(Apache_Solr_Response)#60 (5) { ["_response":protected]=> object(Apache_Solr_HttpTransport_Response)#50 (5) { ["_statusCode":"Apache_Solr_HttpTransport_Response":private]=> int(200) ["_statusMessage":"Apache_Solr_HttpTransport_Response":private]=> string(2) "OK" ["_mimeType":"Apache_Solr_HttpTransport_Response":private]=> string(10) "text/plain" ["_encoding":"Apache_Solr_HttpTransport_Response":private]=> string(5) "UTF-8" ["_responseBody":"Apache_Solr_HttpTransport_Response":private]=> string(511) "{"responseHeader":{"status":0,"QTime":2},"suggest":{"mySuggester":{"A Ga":{"numFound":2,"suggestions":[{"term":"A Game of Thrones","weight":0,"payload":"Book"},{"term":"A Gateway to Heaven","weight":0,"payload":"Book"}]}}}} " } ["_isParsed":protected]=> bool(false) ["_parsedData":protected]=> NULL ["_createDocuments":protected]=> bool(true) ["_collapseSingleValueArrays":protected]=> bool(true) }
$response->suggest->mySuggester->{$inp}->numFound;(note the curly braces). If not, can you post avar_dump?$responseis a lot more than the example you show on top.var_dump():object(Apache_Solr_Response)...