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

Allowing fetch function to control highlighting, highlighting disabled by default #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 15 additions & 9 deletions classes/ezfezpsolrquerybuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,22 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra
$enableElevation = isset( $params['EnableElevation'] ) ? $params['EnableElevation'] : true;
$distributedSearch = isset( $params['DistributedSearch'] ) ? $params['DistributedSearch'] : false;
$fieldsToReturn = isset( $params['FieldsToReturn'] ) ? $params['FieldsToReturn'] : array();
$highlightParams = isset( $params['HighLightParams'] ) ? $params['HighLightParams'] : array();
$searchResultClusterParams = isset( $params['SearchResultClustering'] ) ? $params['SearchResultClustering'] : array();
$extendedAttributeFilter = isset( $params['ExtendedAttributeFilter'] ) ? $params['ExtendedAttributeFilter'] : array();

// Handling highlighting parameters
$highlightParams = array(
'hl' => $eZFindIni->variable( 'HighLighting', 'Enabled' ),
'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' ),
);
if( isset( $params[ 'HighLightParams' ] ) && !empty( $params[ 'HighLightParams' ] ) )
{
$highlightParams = array_merge( $highlightParams, $params[ 'HighLightParams' ] );
}

// distributed search option
// @since ezfind 2.2
Expand Down Expand Up @@ -305,7 +317,7 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra
//the array_unique below is necessary because attribute identifiers are not unique .. and we get as
//much highlight snippets as there are duplicate attribute identifiers
//these are also in the list of query fields (dismax, ezpublish) request handlers
$queryFields = array_unique( $this->getClassAttributes( $contentClassID, $contentClassAttributeID, $fieldTypeExcludeList ) );
$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.
Expand Down Expand Up @@ -472,23 +484,17 @@ 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'
),
$highlightParams,
$facetQueryParamList,
$spellCheckParamList,
$boostFunctionsParamList,
$elevateParamList,
$searchResultClusterParamList
);


if( isset( $extendedAttributeFilter['id'] ) && isset( $extendedAttributeFilter['params'] ) )
{
//single filter
Expand Down
69 changes: 54 additions & 15 deletions classes/ezfmodulefunctioncollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,57 @@ public function getFilterParameters()
/**
* Search function
*
* @param string Query string
* @param int Offset
* @param int Limit
* @param array Facet definition
* @param array Filter parameters
* @param array Sort by parameters
* @param mixed Content class ID or list of content class IDs
* @param array list of subtree limitation node IDs
* @param boolean $enableElevation Controls whether elevation should be enabled or not
* @param boolean $forceElevation Controls whether elevation is forced. Applies when the srt criteria is NOT the default one ( 'score desc' ).
* @param string $query Query string
* @param int $offset Offset
* @param int $limit Limit
* @param array $facets Facet definition
* @param array $filters Filter parameters
* @param array $sortBy Sort by parameters
* @param mixed $classID Content class ID or list of content class IDs
* @param null $sectionID
* @param array $subtreeArray List of subtree limitation node IDs
* @param null $ignoreVisibility
* @param null $limitation
* @param bool $asObjects
* @param null $spellCheck
* @param null $boostFunctions
* @param string $queryHandler
* @param bool $enableElevation Controls whether elevation should be enabled or not
* @param bool $forceElevation Controls whether elevation is forced. Applies when the srt criteria is NOT the default one ( 'score desc' ).
* @param null $publishDate
* @param null $distributedSearch
* @param null $fieldsToReturn
* @param null $searchResultClustering
* @param array $extendedAttributeFilter
* @param bool $highlighted Controls whether highlighting is enabled or not
*
* @return array Search result
*/
public function search( $query, $offset = 0, $limit = 10, $facets = null,
$filters = null, $sortBy = null, $classID = null, $sectionID = null,
$subtreeArray = null, $ignoreVisibility = null, $limitation = null, $asObjects = true, $spellCheck = null, $boostFunctions = null, $queryHandler = 'ezpublish',
$enableElevation = true, $forceElevation = false, $publishDate = null, $distributedSearch = null, $fieldsToReturn = null, $searchResultClustering = null, $extendedAttributeFilter = array() )
public function search(
$query,
$offset = 0,
$limit = 10,
$facets = null,
$filters = null,
$sortBy = null,
$classID = null,
$sectionID = null,
$subtreeArray = null,
$ignoreVisibility = null,
$limitation = null,
$asObjects = true,
$spellCheck = null,
$boostFunctions = null,
$queryHandler = 'ezpublish',
$enableElevation = true,
$forceElevation = false,
$publishDate = null,
$distributedSearch = null,
$fieldsToReturn = null,
$searchResultClustering = null,
$extendedAttributeFilter = array(),
$highlighted = false
)
{
$solrSearch = new eZSolr();
$params = array( 'SearchOffset' => $offset,
Expand All @@ -105,7 +139,12 @@ public function search( $query, $offset = 0, $limit = 10, $facets = null,
'DistributedSearch' => $distributedSearch,
'FieldsToReturn' => $fieldsToReturn,
'SearchResultClustering' => $searchResultClustering,
'ExtendedAttributeFilter' => $extendedAttributeFilter );
'ExtendedAttributeFilter' => $extendedAttributeFilter,
'HighLightParams' => array(
'hl' => $highlighted ? 'true': 'false'
),
);

return array( 'result' => $solrSearch->search( $query, $params ) );
}

Expand Down
4 changes: 3 additions & 1 deletion design/ezdemo/templates/content/search.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
'filter', $filterParameters,
'publish_date', $dateFilter,
'spell_check', array( true() ),
'search_result_clustering', hash( 'clustering', false() ) )
'search_result_clustering', hash( 'clustering', false() ),
'highlighted', true()
)
)}
{set $search_result=$search['SearchResult']}
{set $search_count=$search['SearchCount']}
Expand Down
8 changes: 7 additions & 1 deletion modules/ezfind/function_definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@
array ( 'name' => 'extended_attribute_filter',
'type' => 'array',
'required' => false,
'default' => array() )) );
'default' => array() ),
array ( 'name' => 'highlighted',
'type' => 'boolean',
'required' => false,
'default' => false ),
)
);


$FunctionList['getDefaultSearchFacets'] = array( 'name' => 'getDefaultSearchFacets',
Expand Down
2 changes: 1 addition & 1 deletion settings/ezfind.ini
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ BoostTerms=true
# true or false to enable or disable the highlighting
# will be passed in hl parameter of the query Solr
# http://wiki.apache.org/solr/HighlightingParameters#hl
Enabled=true
Enabled=false
# highlight only matched fields or not
# will be passed in hl.requireFieldMatch of the Solr query
# http://wiki.apache.org/solr/HighlightingParameters#hl.requireFieldMatch
Expand Down