Skip to content

Commit

Permalink
Merge pull request #201 from datafactory/EZP-26804
Browse files Browse the repository at this point in the history
EZP-26804: Search with section id list filter
  • Loading branch information
andrerom authored Dec 22, 2017
2 parents 1d20767 + a00d8c9 commit 9d3334d
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions classes/ezfezpsolrquerybuilder.php
Original file line number Diff line number Diff line change
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 @@ -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 )
{
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 9d3334d

Please sign in to comment.