Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better building of highlighting parameters #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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