From 95ccbe8f3418a72a01abdde538866e49bc6cb393 Mon Sep 17 00:00:00 2001 From: Peter Keung Date: Fri, 18 Nov 2016 23:30:13 -0800 Subject: [PATCH] EZP-26630: Support per-query raw filters --- classes/ezfezpsolrquerybuilder.php | 16 +++++++++++++++- classes/ezfmodulefunctioncollection.php | 6 ++++-- modules/ezfind/function_definition.php | 6 +++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/classes/ezfezpsolrquerybuilder.php b/classes/ezfezpsolrquerybuilder.php index 142702c9..a725c2d4 100644 --- a/classes/ezfezpsolrquerybuilder.php +++ b/classes/ezfezpsolrquerybuilder.php @@ -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( ) * ); * * For full facet description, see facets design document. @@ -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'] ); @@ -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 ); diff --git a/classes/ezfmodulefunctioncollection.php b/classes/ezfmodulefunctioncollection.php index be308534..dd693be2 100644 --- a/classes/ezfmodulefunctioncollection.php +++ b/classes/ezfmodulefunctioncollection.php @@ -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, @@ -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 ) ); } diff --git a/modules/ezfind/function_definition.php b/modules/ezfind/function_definition.php index c631d10c..c10382bb 100644 --- a/modules/ezfind/function_definition.php +++ b/modules/ezfind/function_definition.php @@ -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',