From a00d8c99a0748c51f6ec54d6e322b726f4844596 Mon Sep 17 00:00:00 2001 From: Sebastian Blank Date: Wed, 21 Dec 2016 14:04:01 +0100 Subject: [PATCH] EZP-26804: Search with section id list filter --- classes/ezfezpsolrquerybuilder.php | 54 +++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/classes/ezfezpsolrquerybuilder.php b/classes/ezfezpsolrquerybuilder.php index 142702c9..bd5585e5 100644 --- a/classes/ezfezpsolrquerybuilder.php +++ b/classes/ezfezpsolrquerybuilder.php @@ -264,9 +264,10 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra } // Add section to query filter. - if ( $sectionID ) + $sectionLimitationFilter = $this->getSectionFilterQuery( $sectionID ); + if ( $sectionLimitationFilter !== null ) { - $filterQuery[] = eZSolr::getMetaFieldName( 'section_id' ) . ':' . $sectionID; + $filterQuery[] = $sectionLimitationFilter; } $languageFilterQuery = $this->buildLanguageFilterQuery(); @@ -1471,10 +1472,10 @@ protected function boostQuery() /** * Generate class query filter. * - * @param mixed eZContentClass id, identifier or list of ids. + * @param mixed $contentClassIdent eZContentClass id, identifier or list of ids. * * @return string Content class query filter. Returns null if invalid - * $contentClassIdent is provided. + * $contentClassIdent is provided. */ protected function getContentClassFilterQuery( $contentClassIdent ) { @@ -1529,6 +1530,51 @@ protected function getContentClassFilterQuery( $contentClassIdent ) return null; } + /** + * Generate section query filter. + * + * @param mixed $sectionIdent eZSection id or list of ids. + * + * @return string Section query filter. Returns null if invalid + * $sectionIdent is provided. + */ + protected function getSectionFilterQuery( $sectionIdent ) + { + if ( empty( $sectionIdent ) ) + { + return null; + } + + if ( is_array( $sectionIdent ) ) + { + $sectionQueryParts = array(); + foreach ( $sectionIdent as $sectionID ) + { + $sectionID = trim( $sectionID ); + if ( ctype_digit( $sectionID ) ) + { + $sectionQueryParts[] = eZSolr::getMetaFieldName( 'section_id' ) . ':' . $sectionID; + } + else + { + eZDebug::writeError( "Unknown section_id filtering parameter: $sectionID", __METHOD__ ); + } + } + + return implode( ' OR ', $sectionQueryParts ); + } + + $sectionIdent = trim( $sectionIdent ); + if ( ctype_digit( $sectionIdent ) ) + { + return eZSolr::getMetaFieldName( 'section_id' ) . ':' . $sectionIdent; + } + + eZDebug::writeError( 'No valid section id', __METHOD__ ); + + return null; + } + /** * Create policy limitation query. *