Skip to content

Commit

Permalink
EZP-26630: Support per-query raw filters
Browse files Browse the repository at this point in the history
  • Loading branch information
peterkeung committed Dec 22, 2017
1 parent 20f281e commit 95ccbe8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
16 changes: 15 additions & 1 deletion classes/ezfezpsolrquerybuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public function buildMultiFieldQuery( $searchText, $solrFields = array(), $boost
* 'searchfields', array ( 'myfield1, 'myfield2', ... )
* 'returnfields', array ( 'myfield1, 'myfield2', ... )
* 'rawfilterlist, array ( 'foreignfield:a', '(foreignfield:b AND otherfield:c)', ... )
* )
* ),
* 'RawFilter' => array( <raw_filter> )
* );
* </code>
* For full facet description, see facets design document.
Expand Down Expand Up @@ -179,6 +180,7 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra
}

// check if filter parameter is indeed an array, and set it otherwise
// By default, multiple filters are combined with "AND" to send to Solr
if ( isset( $params['Filter']) && ! is_array( $params['Filter'] ) )
{
$params['Filter'] = array( $params['Filter'] );
Expand Down Expand Up @@ -292,6 +294,18 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra
}
}

// Add per-query raw filters
// Check if raw filter parameter is indeed an array, and set it otherwise
// By default, multiple filters are combined with "AND" to send to Solr
if ( isset( $params['RawFilter']) && ! is_array( $params['RawFilter'] ) )
{
$params['RawFilter'] = array( $params['RawFilter'] );
}
if ( $params['RawFilter'] )
{
$filterQuery = array_merge( $filterQuery, $params['RawFilter'] );
}

// Build and get facet query prameters.
$facetQueryParamList = $this->buildFacetQueryParamList( $params );

Expand Down
6 changes: 4 additions & 2 deletions classes/ezfmodulefunctioncollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ public function getFilterParameters()
* @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 array Raw filter parameters
*
* @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() )
$enableElevation = true, $forceElevation = false, $publishDate = null, $distributedSearch = null, $fieldsToReturn = null, $searchResultClustering = null, $extendedAttributeFilter = array(), $rawFilters = null )
{
$solrSearch = new eZSolr();
$params = array( 'SearchOffset' => $offset,
Expand All @@ -105,7 +106,8 @@ public function search( $query, $offset = 0, $limit = 10, $facets = null,
'DistributedSearch' => $distributedSearch,
'FieldsToReturn' => $fieldsToReturn,
'SearchResultClustering' => $searchResultClustering,
'ExtendedAttributeFilter' => $extendedAttributeFilter );
'ExtendedAttributeFilter' => $extendedAttributeFilter,
'RawFilter' => $rawFilters );
return array( 'result' => $solrSearch->search( $query, $params ) );
}

Expand Down
6 changes: 5 additions & 1 deletion modules/ezfind/function_definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@
array ( 'name' => 'extended_attribute_filter',
'type' => 'array',
'required' => false,
'default' => array() )) );
'default' => array() ),
array( 'name' => 'raw_filter',
'type' => 'array',
'required' => false,
'default' => null ) ) );


$FunctionList['getDefaultSearchFacets'] = array( 'name' => 'getDefaultSearchFacets',
Expand Down

0 comments on commit 95ccbe8

Please sign in to comment.