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-26804: Search with section id list filter #201

Merged
merged 1 commit into from Dec 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 50 additions & 4 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 @@ -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