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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 29 2025 14:43:17
Script start
Timing: Jan 29 2025 14:43:17
Module start 'layout'
Timing: Jan 29 2025 14:43:17
Module start 'content'
Timing: Jan 29 2025 14:43:17
Module end 'content'
Timing: Jan 29 2025 14:43:17
Script end

Main resources:

Total runtime0.0337 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0080 588.2813151.2266
Module start 'layout' 0.00810.0050 739.507836.6797
Module start 'content' 0.01300.0191 776.187591.3750
Module end 'content' 0.03210.0016 867.562533.9922
Script end 0.0337  901.5547 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00247.2437140.0002
Check MTime0.00113.3290140.0001
Mysql Total
Database connection0.00082.471810.0008
Mysqli_queries0.006519.244530.0022
Looping result0.00000.074210.0000
Template Total0.00113.210.0011
Template load0.00082.513510.0008
Template processing0.00020.622510.0002
Override
Cache load0.00061.733410.0006
General
dbfile0.008023.752180.0010
String conversion0.00000.033240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs