Skip to content

Commit e0596cd

Browse files
committed
Merge branch 'eep_updates_ezfind_advanced'
2 parents 20c4c11 + 5bfa9c0 commit e0596cd

1 file changed

Lines changed: 87 additions & 51 deletions

File tree

modules/ezfind/index.php

Lines changed: 87 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ public function __construct()
4646

4747
$this->help = <<<EOT
4848
advanced
49-
eep ezfind advanced <statement> <fields to return> <filter> [--offset=## --limit=##]
49+
eep ezfind advanced <statement> <fields to return> <filter> [--offset=## --limit=## --show-complex=1 --output=xml|csv|json]
50+
51+
- Using --output requires the relevant queryResponseWriter
52+
to be enabled in ezfind/java/solr/conf/solrconfig.xml
53+
54+
Example: eep ezfind advanced 'Water*' 'meta_node_id_si,attr_title_s' 'meta_class_identifier_ms:article' --show-complex=1 --output=json
5055
5156
indexobject
5257
eep ezfind indexobject <object id>
@@ -79,101 +84,132 @@ public function __construct()
7984
//--------------------------------------------------------------------------
8085
private function advanced( $args, $additional )
8186
{
82-
8387
$parameters = array();
84-
88+
// set the query string
8589
if( isset( $args[3] ) )
8690
{
8791
$parameters['q'] = $args[3];
8892
}
8993
else
9094
{
91-
echo "Statement is required\n";
95+
echo "Query is required\n";
9296
return;
9397
}
94-
98+
// fields to list
9599
if( isset( $args[4] ) )
96100
{
97101
$parameters['fl'] = $args[4];
98102
}
99-
103+
// fields to query
100104
if( isset( $args[5] ) )
101105
{
102106
$parameters['fq'] = $args[5];
103107
}
104-
108+
// offset and limit
105109
if( isset( $additional['offset'] ) )
106110
{
107111
$parameters['start'] = $additional['offset'];
108112
}
109-
110113
if( isset( $additional['limit'] ) )
111114
{
112115
$parameters['rows'] = $additional['limit'];
113116
}
114-
117+
// output format
115118
if( isset( $additional['output'] ) && $additional['output'] == 'xml' )
116119
{
117120
$parameters['wt'] = 'xml';
118121
}
119-
120-
$query = array( 'baseURL' => false
121-
, 'request' => '/select'
122-
, 'parameters' => $parameters );
123-
124-
$search = eZFunctionHandler::execute( 'ezfind', 'rawSolrRequest', $query );
125122

126-
if( $search['response']['numFound'] > 0 )
123+
$showComplex = false;
124+
if( isset( $additional['show-complex'] ) )
127125
{
128-
if( isset( $additional['output'] ) && $additional['output'] == 'xml' )
126+
$showComplex = true;
127+
}
128+
129+
$responseWriter = 'php'; // default eZFind Solr QueryResponseWriter
130+
if( isset( $additional['output'] ) )
131+
{
132+
// xml, json, csv etc;
133+
// check /ezfind/java/solr/conf/solrconfig.xml for other valid/enabled queryResponseWriter
134+
$responseWriter = $additional['output'];
135+
}
136+
// run request directly to avoid hardcoded 'wt' parameter issue when using eZFunctionHandler
137+
$solr = new eZSolrBase( false );
138+
$search = $solr->rawSolrRequest( '/select', $parameters, $responseWriter );
139+
140+
if( isset( $search['response']['numFound'] ) && $search['response']['numFound'] > 0 && !isset( $additional['output'] ) )
141+
{
142+
$results = array();
143+
$header = array();
144+
foreach( $search['response']['docs'][0] as $index => $doc )
129145
{
130-
$xml = new SimpleXMLElement('<root/>');
131-
array_walk_recursive($search, array ($xml, 'addChild'));
132-
print $xml->asXML();
146+
$header[] = $index;
133147
}
134-
else
135-
{
136148

137-
$results = array();
138-
$header = array();
139-
foreach( $search['response']['docs'][0] as $index => $doc )
140-
{
141-
142-
$header[]=$index;
143-
144-
}
145-
146-
$results[]=$header;
147-
148-
149-
foreach( $search['response']['docs'] as $doc )
149+
$results[] = $header;
150+
$fieldListCount = count( explode( ',', $parameters['fl'] ) );
151+
foreach( $search['response']['docs'] as $doc )
152+
{
153+
$result = array();
154+
$resultCount = count( $doc );
155+
foreach( $doc as $attribute )
150156
{
151-
$result = array();
152-
foreach($doc as $attribute)
157+
if( is_array( $attribute ) )
153158
{
154-
if(is_array($attribute))
159+
if( $showComplex )
155160
{
156-
$result[] = 'array()';
161+
$result[] = implode( '¦', $attribute );
157162
}
158-
else if(is_object($attribute))
163+
else
159164
{
160-
$result[] = 'object()';
165+
$result[] = 'array()';
166+
}
167+
}
168+
else if( is_object( $attribute ) )
169+
{
161170

171+
if( $showComplex )
172+
{
173+
$result[] = implode( '¦', (array) $attribute );
162174
}
163175
else
164176
{
165-
$result[] = $attribute;
177+
$result[] = 'object()';
166178
}
167-
168-
}
169-
170-
$results[] = $result;
171-
179+
}
180+
else
181+
{
182+
$result[] = $attribute;
183+
}
172184
}
173-
174-
eep::printTable( $results, "list ezfind results" );
175-
}
176-
185+
186+
// Not all docs return all fields queried for.
187+
// Fix the results table display by adding placeholders for those cases
188+
if( $resultCount !== $fieldListCount )
189+
{
190+
$diff = $fieldListCount - $resultCount;
191+
for( $i = 0; $i < $diff; $i++ )
192+
{
193+
$result[] = 'no value';
194+
}
195+
}
196+
197+
$results[] = $result;
198+
}
199+
200+
eep::printTable( $results, "list ezfind results" );
201+
}
202+
else if( $search && isset( $additional['output'] ) && in_array( $additional['output'], array( 'xml', 'csv' ) ) )
203+
{
204+
echo $search[0];
205+
}
206+
else if ( $search && isset( $additional['output'] ) && $additional['output'] == 'json' )
207+
{
208+
// TODO: eZ is json_decode'ing requests made with wt=json before passing back the result set
209+
// figure out a better way around that
210+
//
211+
// In the meantime
212+
echo json_encode( $search ) . "\n";
177213
}
178214
else
179215
{

0 commit comments

Comments
 (0)