Skip to content

Commit

Permalink
EZP-26804 - eZ Find search with section id list filter
Browse files Browse the repository at this point in the history
  • Loading branch information
blankse committed Dec 21, 2016
1 parent 20f281e commit d089c0c
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions classes/ezfezpsolrquerybuilder.php
Expand Up @@ -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();
Expand Down Expand Up @@ -1529,6 +1530,53 @@ protected function getContentClassFilterQuery( $contentClassIdent )
return null;
}

/**
* Generate section query filter.
*
* @param mixed 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 ( empty( $sectionID ) )
{
continue;
}
if ( (int)$sectionID . '' == $sectionID . '' )
{
$sectionQueryParts[] = eZSolr::getMetaFieldName( 'section_id' ) . ':' . $sectionID;
}
else
{
eZDebug::writeError( "Unknown section_id filtering parameter: $sectionID", __METHOD__ );
}
}

return implode( ' OR ', $sectionQueryParts );
}
elseif ( (int)$sectionIdent . '' == $sectionIdent . '' )
{
return eZSolr::getMetaFieldName( 'section_id' ) . ':' . $sectionIdent;
}

eZDebug::writeError( 'No valid section id', __METHOD__ );

return null;
}

/**
* Create policy limitation query.
*
Expand Down

0 comments on commit d089c0c

Please sign in to comment.