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

EZP-26630: Support per-query raw filters #200

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
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