Skip to content

Commit

Permalink
avoid sending *any* hl parameter to solr when not required & make it …
Browse files Browse the repository at this point in the history
…easy to extend hl param build in subclasses
  • Loading branch information
Gaetano Giunta committed Mar 18, 2018
1 parent a681433 commit bc9db6d
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions classes/ezfezpsolrquerybuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,6 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra
//these are also in the list of query fields (dismax, ezpublish) request handlers
$queryFields = array_unique( $this->getClassAttributes( $contentClassID, $contentClassAttributeID, $fieldTypeExcludeList ) );

//highlighting only in the attributes, otherwise the object name is repeated in the highlight, which is already
//partly true as it is mostly composed of one or more attributes.
//maybe we should add meta data to the index to filter them out.

$highLightFields = $queryFields;

//@since eZ Find 2.3
//when dedicated attributes are searched for, don't add meta-fields to the $queryfields list
if ( !$contentClassAttributeID )
Expand Down Expand Up @@ -386,12 +380,8 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra

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' );
'qt' => 'standard' );
break;
case 'ezpublish':
// the dismax based handler, just keywordss input, most useful for ordinary queries by users
Expand Down Expand Up @@ -461,6 +451,7 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra
$searchResultClusterParamList = $this->buildSearchResultClusterQuery($searchResultClusterParams);
eZDebugSetting::writeDebug( 'extension-ezfind-query', $searchResultClusterParamList, 'Cluster params' );

$highlightParamList = $this->buildHighlightParameters( $queryHandler, $queryFields );

$queryParams = array_merge(
$handlerParameters,
Expand All @@ -472,23 +463,16 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra
'version' => '2.2',
'fl' => $fieldsToReturnString,
'fq' => $filterQuery,
'hl' => $eZFindIni->variable( 'HighLighting', 'Enabled' ),
'hl.fl' => implode( ' ', $highLightFields ),
'hl.snippets' => $eZFindIni->variable( 'HighLighting', 'SnippetsPerField' ),
'hl.fragsize' => $eZFindIni->variable( 'HighLighting', 'FragmentSize' ),
'hl.requireFieldMatch' => $eZFindIni->variable( 'HighLighting', 'RequireFieldMatch' ),
'hl.simple.pre' => $eZFindIni->variable( 'HighLighting', 'SimplePre' ),
'hl.simple.post' => $eZFindIni->variable( 'HighLighting', 'SimplePost' ),
'wt' => 'php'
),
$highlightParamList,
$facetQueryParamList,
$spellCheckParamList,
$boostFunctionsParamList,
$elevateParamList,
$searchResultClusterParamList
);


if( isset( $extendedAttributeFilter['id'] ) && isset( $extendedAttributeFilter['params'] ) )
{
//single filter
Expand Down Expand Up @@ -565,6 +549,39 @@ protected function buildLanguageFilterQuery()
return $languageFilterString;
}

protected function buildHighlightParameters( $queryHandler, $queryFields )
{
$highlightParamList = array();
$eZFindIni = eZINI::instance( 'ezfind.ini' );

if ( $eZFindIni->variable( 'HighLighting', 'Enabled' ) == 'true' ) {
$highlightParamList = array(
'hl' => 'true',
'hl.snippets' => $eZFindIni->variable( 'HighLighting', 'SnippetsPerField' ),
'hl.fragsize' => $eZFindIni->variable( 'HighLighting', 'FragmentSize' ),
'hl.requireFieldMatch' => $eZFindIni->variable( 'HighLighting', 'RequireFieldMatch' ),
'hl.simple.pre' => $eZFindIni->variable( 'HighLighting', 'SimplePre' ),
'hl.simple.post' => $eZFindIni->variable( 'HighLighting', 'SimplePost' ),
);
switch ( $queryHandler )
{
case 'simplestandard':
$highlightParamList['hl.fl'] = 'ezf_df_text';
$highlightParamList['hl.usePhraseHighlighter'] = 'true';
$highlightParamList['hl.highlightMultiTerm'] = 'true';
break;
default:
// highlighting only in the attributes, otherwise the object name is repeated in the highlight, which is already
// partly true as it is mostly composed of one or more attributes.
// maybe we should add meta data to the index to filter them out.
$highlightParamList['hl.fl'] = implode( ' ', $queryFields );
break;
}
}

return $highlightParamList;
}

/**
* @since eZ Find 2.0
*
Expand Down

0 comments on commit bc9db6d

Please sign in to comment.