Forums / Extensions / eZ Find / Solr JSon query from ez module view

Solr JSon query from ez module view

Author Message

H-Works Agency

Wednesday 09 June 2010 2:30:45 am

Hi guys,

What is the cleanest way to fetch solr data, in built-in json format, from php code inside an ezpublish module view ?

For now i use :

"

$solrSearch = new eZSolr();

$search = $solrSearch->search( $query, $params );

"

Thank everyone !

Technically it works but $search will be an array. Of course i could manipulate this array to outpout a formatted json string but is there something simpler & quicker ?

For exemple could i use this function which seems to operate at a lower level :

"

$solrSearch = new eZSolreZSolrBase();

$solrSearch->rawSolrRequest($request);

"

EZP is Great

Carlos Revillo

Wednesday 09 June 2010 3:11:55 am

Manipulate the array seems the best choice to me. Could be as simple as

echo json_encode( $search )

Paul Borgermans

Wednesday 09 June 2010 8:57:02 am

When using the eZSolrBase->rawSolrRequest function you can issue a third parameter which specifies the response format ... which can be json instead of the default "php" (which is a PHP array)

 eZSolrBase->rawSolrRequest($request, $params, 'json')

That saves the json_encode step

The same is true when you use the rawSearch method (where the response format is the second argument)

hth

Paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans