I am way overdue on my promise to show you how to make shards work. As I said before, shards in eZ Find do not work out of the box. In the code the $shardQuery
is built properly but the variable is never actually used after it is created. What I did to make this work is a simple if/else block inside the $queryHandler
switch. I am not submitting this as a pull request to eZ Find at the moment just because I do not like the way I made this work, I feel like there is a better way to do it. Nevertheless here is my code to make Shards work, I hope you enjoy and moreover I hope you suggest a better way to make the code work ;)
<?php
\\ezfezpsolrquerybuilder.php
switch ( $queryHandler )
{
case 'standard':
// @todo: this is more complicated
// build the query against all "text" like fields
// should take into account all the filter fields and class filters to shorten the query
// need to build: Solr q
if ( array_key_exists( 'fields', $boostFunctions ) )
{
if (false != $shardQuery) {
$handlerParameters = array ( 'q' => $this->buildMultiFieldQuery( $searchText, array_merge( $queryFields, $extraFieldsToSearch ), $boostFunctions['fields'] ),
'qt' => 'standard',
'shards' => $shardQuery);
}
else {
$handlerParameters = array ( 'q' => $this->buildMultiFieldQuery( $searchText, array_merge( $queryFields, $extraFieldsToSearch ), $boostFunctions['fields'] ),
'qt' => 'standard', );
}
}
else
{
if (false != $shardQuery) {
$handlerParameters = array ( 'q' => $this->buildMultiFieldQuery( $searchText, array_merge( $queryFields, $extraFieldsToSearch ) ),
'qt' => 'standard',
'shards' => $shardQuery);
}
else{
$handlerParameters = array ( 'q' => $this->buildMultiFieldQuery( $searchText, array_merge( $queryFields, $extraFieldsToSearch ) ),
'qt' => 'standard' );
}
}
break;
case 'simplestandard':
// not to do much, searching is against the default aggregated field
// only highlightfields
$highLightFields = array ( 'ezf_df_text' );
$handlerParameters = array ( 'q' => $searchText,
'qt' => 'standard',
'hl.usePhraseHighlighter' => 'true',
'hl.highlightMultiTerm' => 'true' );
break;
case 'ezpublish':
// the dismax based handler, just keywordss input, most useful for ordinary queries by users
// need to build: Solr q, qf, dismax specific parameters
default:
// ezpublish of course, this to not break BC and is the most "general"
// if another value is specified, it is supposed to be a dismax like handler
// with possible other tuning variables then the stock provided 'ezpublish' in solrconfi.xml
// remark it should be lowercase in solrconfig.xml!
if (false != $shardQuery) {
$handlerParameters = array ( 'q' => $searchText,
'qf' => implode( ' ', array_merge( $queryFields, $extraFieldsToSearch ) ),
'qt' => $queryHandler,
'shards' => $shardQuery );
} else {
$handlerParameters = array ( 'q' => $searchText,
'qf' => implode( ' ', array_merge( $queryFields, $extraFieldsToSearch ) ),
'qt' => $queryHandler );
}
}