forked from ezsystems/ezfind
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mugoweb/query-module-view
Query module view
- Loading branch information
Showing
4 changed files
with
230 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{* | ||
INPUT | ||
data : form data | ||
result : solr search result | ||
*} | ||
{def | ||
$solr_fields_meta = array( | ||
'meta_guid_ms', | ||
'meta_installation_id_ms', | ||
'meta_name_t', | ||
'meta_owner_name_ms', | ||
'meta_id_si', | ||
'meta_current_version_si', | ||
'meta_remote_id_ms', | ||
'meta_class_identifier_ms', | ||
'meta_main_node_id_si', | ||
'meta_modified_dt', | ||
'meta_published_dt', | ||
'meta_main_url_alias_ms', | ||
'meta_main_path_string_ms', | ||
'meta_object_states_si', | ||
) | ||
$solr_fields_attr = array( 'attr_publish_date_dt' ) | ||
$solr_fields_other = array( 'timestamp', 'ezf_sp_words', 'ezf_df_text' ) | ||
$formats = array( 'php', 'json', 'csv' ) | ||
} | ||
|
||
<div> | ||
<form method="post" action={'ezfind/query'|ezurl()}> | ||
|
||
<label>Query:(<a target="_blank" href="http://wiki.apache.org/solr/QueryParametersIndex">?</a>)</label> | ||
|
||
<table> | ||
<tr> | ||
<td>q</td> | ||
<td> | ||
<textarea name="data[query]" type="text" style="width: 600px; height: 100px;">{$data[ 'query' ]}</textarea> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>format</td> | ||
<td> | ||
<select name="data[format]"> | ||
{foreach $formats as $format} | ||
<option {if eq( $format, $data.format )}selected="selected"{/if}>{$format}</option> | ||
{/foreach} | ||
</select> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>offset</td> | ||
<td><input type="text" name="data[offset]" value="{$data.offset}" /></td> | ||
</tr> | ||
<tr> | ||
<td>limit</td> | ||
<td><input type="text" name="data[limit]" value="{$data.limit}" /></td> | ||
</tr> | ||
<tr> | ||
<td>sort</td> | ||
<td><input type="text" name="data[sort]" value="{$data.sort}" /></td> | ||
</tr> | ||
<tr> | ||
<td>Fields</td> | ||
<td> | ||
<select size="12" name="data[fields][]" multiple="multiple"> | ||
<optgroup label="Meta"> | ||
{foreach $solr_fields_meta as $solr_field} | ||
<option value="{$solr_field}" {if $data.fields|contains( $solr_field )}selected="selected"{/if}> | ||
{$solr_field} | ||
</option> | ||
{/foreach} | ||
</optgroup> | ||
<optgroup label="Attribute"> | ||
{foreach $solr_fields_attr as $solr_field} | ||
<option value="{$solr_field}" {if $data.fields|contains( $solr_field )}selected="selected"{/if}> | ||
{$solr_field} | ||
</option> | ||
{/foreach} | ||
</optgroup> | ||
<optgroup label="Others"> | ||
{foreach $solr_fields_other as $solr_field} | ||
<option value="{$solr_field}" {if $data.fields|contains( $solr_field )}selected="selected"{/if}> | ||
{$solr_field} | ||
</option> | ||
{/foreach} | ||
</optgroup> | ||
</select> | ||
</td> | ||
</tr> | ||
</table> | ||
|
||
<input type="submit" value="submit" name="submit" /> | ||
</form> | ||
</div> | ||
|
||
{if $result} | ||
<div> | ||
<pre style="max-width: 1200px; overflow-x: scroll"> | ||
{$result} | ||
</pre> | ||
</div> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
$tpl = eZTemplate::factory(); | ||
$result = ''; | ||
$module = $Params[ 'Module' ]; | ||
$formats = array( 'php', 'json', 'csv' ); | ||
$field_list = array(); | ||
$data = array( | ||
'limit' => 10, | ||
'offset' => 0, | ||
'query' => '', | ||
'format' => 'php', | ||
'fields' => array(), | ||
); | ||
|
||
if( isset( $_REQUEST[ 'submit' ] ) ) | ||
{ | ||
$solr = new eZSolrBase(); | ||
|
||
$data = array_replace_recursive( $data, $_REQUEST[ 'data' ] ); | ||
|
||
$format = 'php'; | ||
|
||
$params = array( | ||
'q' => '*', | ||
'fl' => '*', | ||
); | ||
|
||
if( $data[ 'query' ] ) | ||
{ | ||
$params[ 'q' ] = $data[ 'query' ]; | ||
} | ||
if( in_array( $data[ 'format' ], $formats ) ) | ||
{ | ||
$format = $data[ 'format' ]; | ||
} | ||
if( $format == 'csv' && $params[ 'q' ] && $data[ 'fields' ] ) | ||
{ | ||
$params[ 'fl' ] = $data[ 'fields' ]; | ||
} | ||
if( $data[ 'limit' ] ) | ||
{ | ||
$params[ 'rows' ] = $data[ 'limit' ]; | ||
} | ||
if( $data[ 'offset' ] ) | ||
{ | ||
$params[ 'start' ] = $data[ 'limit' ]; | ||
} | ||
if( $data[ 'sort' ] ) | ||
{ | ||
$params[ 'sort' ] = $data[ 'sort' ]; | ||
} | ||
|
||
$result = $solr->rawSearch( $params ); | ||
|
||
$result = print_r( formatData( $result, $format, $data[ 'fields' ] ), true ); | ||
} | ||
|
||
$tpl->setVariable( 'data', $data ); | ||
$tpl->setVariable( 'result', $result ); | ||
|
||
$Result = array(); | ||
$Result['content'] = $tpl->fetch( "design:ezfind/query.tpl" ); | ||
$Result['left_menu'] = "design:ezfind/backoffice_left_menu.tpl"; | ||
$Result['path'] = array( array( 'url' => false, | ||
'text' => ezpI18n::tr( 'extension/ezfind', 'eZFind' ) ), | ||
array( 'url' => false, | ||
'text' => ezpI18n::tr( 'extension/ezfind', 'Query' ) ) ); | ||
|
||
/* | ||
* functions | ||
*/ | ||
|
||
function formatData( $data, $format, $fields ) | ||
{ | ||
switch( $format ) | ||
{ | ||
case 'csv': | ||
{ | ||
$resultData = $data[ 'response' ][ 'docs' ]; | ||
|
||
$csvData = fopen('php://temp/maxmemory:'. (5*1024*1024), 'r+'); | ||
fputcsv( $csvData, $fields ); | ||
|
||
foreach( $resultData as $row ) | ||
{ | ||
$csvRow = array(); | ||
foreach( $fields as $id ) | ||
{ | ||
$value = $row[ $id ]; | ||
// flatten arrays | ||
if( is_array( $value ) ) | ||
{ | ||
$value = implode( '::', $value ); | ||
} | ||
$csvRow[] = $value; | ||
} | ||
|
||
fputcsv( $csvData, $csvRow ); | ||
} | ||
|
||
// reset pointer | ||
rewind( $csvData ); | ||
|
||
$data = stream_get_contents( $csvData ); | ||
} | ||
break; | ||
|
||
case 'json': | ||
{ | ||
$data = json_encode( $data ); | ||
} | ||
break; | ||
} | ||
|
||
return $data; | ||
} |