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

Field list logic moved into dedicated function #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 83 additions & 48 deletions classes/ezfezpsolrquerybuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,28 +445,7 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra
// Document transformer fields since eZ Find 5.4
$docTransformerFields = array( '[elevated]' );

$fieldsToReturnString = eZSolr::getMetaFieldName( 'guid' ) . ' ' . eZSolr::getMetaFieldName( 'installation_id' ) . ' ' .
eZSolr::getMetaFieldName( 'main_url_alias' ) . ' ' . eZSolr::getMetaFieldName( 'installation_url' ) . ' ' .
eZSolr::getMetaFieldName( 'id' ) . ' ' . eZSolr::getMetaFieldName( 'main_node_id' ) . ' ' .
eZSolr::getMetaFieldName( 'language_code' ) . ' ' . eZSolr::getMetaFieldName( 'name' ) .
' score ' . eZSolr::getMetaFieldName( 'published' ) . ' ' . eZSolr::getMetaFieldName( 'path_string' ) . ' ' .
eZSolr::getMetaFieldName( 'main_path_string' ) . ' ' . eZSolr::getMetaFieldName( 'is_invisible' ) . ' ' .
implode( ' ', $docTransformerFields) . ' ' .
implode( ' ', $extraFieldsToReturn );

if ( ! $asObjects )
{
if ( empty( $fieldsToReturn ))
{
// @todo: needs to be refined with Solr supporting globbing in fl argument, otherwise requests will be to heavy for large fields as for example binary file content
$fieldsToReturnString = 'score, *';
}
else
{
$fieldsToReturnString .= ' ' . implode( ' ', $fieldsToReturn);
}

}
$fieldsToReturnString = $this->getFieldList( $asObjects, $fieldsToReturn, $docTransformerFields, $extraFieldsToReturn );

$searchResultClusterParamList = array( 'clustering' => 'true');
$searchResultClusterParamList = $this->buildSearchResultClusterQuery($searchResultClusterParams);
Expand Down Expand Up @@ -640,9 +619,9 @@ protected function buildBoostFunctions( $boostFunctions = null, &$handlerParamet
}
switch ( $handlerParameters['qt'] )
{
case 'ezpublish' :
{
// The edismax based handler which takes its own boost parameters
case 'ezpublish' :
{
// The edismax based handler which takes its own boost parameters
// Push the boost expression in the 'bf' parameter, if it is not empty.
//
// for the fields to boost, modify the qf parameter for edismax
Expand Down Expand Up @@ -684,18 +663,18 @@ protected function buildBoostFunctions( $boostFunctions = null, &$handlerParamet
}

return $boostReturnArray;
} break;

default:
{
// Simplestandard or standard search handlers.
// Append the boost expression to the 'q' parameter.
// Alter the $handlerParameters array ( passed as reference )
// @TODO : Handle query-time field boosting through the buildMultiFieldQuery() method.
// Requires a modified 'heuristic' mode.
$boostString = implode( ' ', $processedBoostFunctions['functions'] );
} break;

default:
{
// Simplestandard or standard search handlers.
// Append the boost expression to the 'q' parameter.
// Alter the $handlerParameters array ( passed as reference )
// @TODO : Handle query-time field boosting through the buildMultiFieldQuery() method.
// Requires a modified 'heuristic' mode.
$boostString = implode( ' ', $processedBoostFunctions['functions'] );
$handlerParameters['q'] .= ' _val_:' . trim( $boostString );
} break;
} break;
}
return array();
}
Expand Down Expand Up @@ -855,20 +834,76 @@ public function buildMoreLikeThis( $queryType, $query, $params = array() )
'mlt.boost' => $boostmlt, // boost the highest ranking terms
//'mlt.qf' => implode( ' ', $queryFields ),
'mlt.fl' => implode( ' ', $queryFields ),
'fl' =>
eZSolr::getMetaFieldName( 'guid' ) . ' ' . eZSolr::getMetaFieldName( 'installation_id' ) . ' ' .
eZSolr::getMetaFieldName( 'main_url_alias' ) . ' ' . eZSolr::getMetaFieldName( 'installation_url' ) . ' ' .
eZSolr::getMetaFieldName( 'id' ) . ' ' . eZSolr::getMetaFieldName( 'main_node_id' ) . ' ' .
eZSolr::getMetaFieldName( 'language_code' ) . ' ' . eZSolr::getMetaFieldName( 'name' ) .
' score ' . eZSolr::getMetaFieldName( 'published' ) . ' ' .
eZSolr::getMetaFieldName( 'path_string' ) . ' ' . eZSolr::getMetaFieldName( 'is_invisible' ),
'fl' => $this->getFieldList( true ),
'fq' => $filterQuery,
'wt' => 'php' ),
$facetQueryParamList );

return $queryParams;
}

/**
* @param bool $asObjects
* @param null $fieldsToReturn
* @param null $docTransformerFields
* @param null $extraFieldsToReturn
* @return string
*/
protected function getFieldList(
$asObjects = true,
$fieldsToReturn = null,
$docTransformerFields = null,
$extraFieldsToReturn = null
)
{
$return = '';

if( $asObjects )
{
$fields = array(
eZSolr::getMetaFieldName( 'guid' ),
eZSolr::getMetaFieldName( 'installation_id' ),
eZSolr::getMetaFieldName( 'main_url_alias' ),
eZSolr::getMetaFieldName( 'installation_url' ),
eZSolr::getMetaFieldName( 'id' ),
eZSolr::getMetaFieldName( 'main_node_id' ),
eZSolr::getMetaFieldName( 'language_code' ),
eZSolr::getMetaFieldName( 'name' ),
eZSolr::getMetaFieldName( 'published' ),
eZSolr::getMetaFieldName( 'path_string' ),
eZSolr::getMetaFieldName( 'main_path_string' ),
eZSolr::getMetaFieldName( 'is_invisible' ),
'score',
);

if( !empty( $docTransformerFields ) )
{
$fields += $docTransformerFields;
}

if( !empty( $extraFieldsToReturn ) )
{
$fields += $extraFieldsToReturn;
}

$return = implode( ' ', $fields );
}
else
{
if ( empty( $fieldsToReturn ))
{
// @todo: needs to be refined with Solr supporting globbing in fl argument, otherwise requests will be to heavy for large fields as for example binary file content
$return = 'score, *';
}
else
{
$return .= ' ' . implode( ' ', $fieldsToReturn );
}
}

return $return;
}

/**
* Build sort parameter based on params provided.
* @todo specify dedicated sorting fields
Expand Down Expand Up @@ -1484,7 +1519,7 @@ protected function boostQuery()
*/
protected function getContentClassFilterQuery( $contentClassIdent )
{
if ( empty( $contentClassIdent ) )
if ( empty( $contentClassIdent ) )
{
return null;
}
Expand All @@ -1510,10 +1545,10 @@ protected function getContentClassFilterQuery( $contentClassIdent )
$classQueryParts[] = eZSolr::getMetaFieldName( 'contentclass_id' ) . ':' . $class->attribute( 'id' );
}
}
else
{
eZDebug::writeError( "Unknown class_id filtering parameter: $classID", __METHOD__ );
}
else
{
eZDebug::writeError( "Unknown class_id filtering parameter: $classID", __METHOD__ );
}
}

return implode( ' OR ', $classQueryParts );
Expand Down