From 69435e44cdd12cb81e1be85161f4372b06c0f4c1 Mon Sep 17 00:00:00 2001 From: Philipp Kamps Date: Tue, 9 Apr 2019 09:57:00 -0400 Subject: [PATCH] Field list logic moved into dedicated function --- classes/ezfezpsolrquerybuilder.php | 131 ++++++++++++++++++----------- 1 file changed, 83 insertions(+), 48 deletions(-) diff --git a/classes/ezfezpsolrquerybuilder.php b/classes/ezfezpsolrquerybuilder.php index 8c3b93c9..ea448cbf 100644 --- a/classes/ezfezpsolrquerybuilder.php +++ b/classes/ezfezpsolrquerybuilder.php @@ -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); @@ -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 @@ -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(); } @@ -855,13 +834,7 @@ 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 ); @@ -869,6 +842,68 @@ public function buildMoreLikeThis( $queryType, $query, $params = array() ) 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 @@ -1484,7 +1519,7 @@ protected function boostQuery() */ protected function getContentClassFilterQuery( $contentClassIdent ) { - if ( empty( $contentClassIdent ) ) + if ( empty( $contentClassIdent ) ) { return null; } @@ -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 );