Skip to content

Commit

Permalink
Initial version of query plugin mechanism including optional fetch fu…
Browse files Browse the repository at this point in the history
…nction parameters
  • Loading branch information
paulborgermans committed May 4, 2015
1 parent a24aa70 commit b6e6869
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 5 deletions.
6 changes: 4 additions & 2 deletions classes/ezfmodulefunctioncollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getFilterParameters()
public function search( $query, $offset = 0, $limit = 10, $facets = null,
$filters = null, $sortBy = null, $classID = null, $sectionID = null,
$subtreeArray = null, $ignoreVisibility = null, $limitation = null, $asObjects = true, $spellCheck = null, $boostFunctions = null, $queryHandler = 'ezpublish',
$enableElevation = true, $forceElevation = false, $publishDate = null, $distributedSearch = null, $fieldsToReturn = null, $searchResultClustering = null, $extendedAttributeFilter = array() )
$enableElevation = true, $forceElevation = false, $publishDate = null, $distributedSearch = null, $fieldsToReturn = null, $searchResultClustering = null, $extendedAttributeFilter = array(), $pluginParameters = array() )
{
$solrSearch = new eZSolr();
$params = array( 'SearchOffset' => $offset,
Expand All @@ -105,7 +105,9 @@ public function search( $query, $offset = 0, $limit = 10, $facets = null,
'DistributedSearch' => $distributedSearch,
'FieldsToReturn' => $fieldsToReturn,
'SearchResultClustering' => $searchResultClustering,
'ExtendedAttributeFilter' => $extendedAttributeFilter );
'ExtendedAttributeFilter' => $extendedAttributeFilter,
'PluginParameters' => $pluginParameters,
);
return array( 'result' => $solrSearch->search( $query, $params ) );
}

Expand Down
26 changes: 26 additions & 0 deletions classes/queryplugins/ezfquerysearchplugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* File containing Search Query Plugin Interface
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
* @package ezfind
*/

/**
* Description of ezfQuerySearchPlugin.
* Interface that Query PLugins should implement.
* The plugin code checks for the correct implementation.
*
*/
interface ezfQuerySearchPlugin
{
/**
* @var array $queryParams
*/
public function modify( &$queryParams, $pluginParams = array() );
}

?>
39 changes: 39 additions & 0 deletions classes/queryplugins/ezftestqueryplugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/

/**
* Description of ezftestqueryplugin
*
* This test plugin simply looks up if the string 'article' is present in the query
* provided by the user and if so, adds a class filter to type article
*
* @author paul
*
*/
class ezfTestQueryPlugin implements ezfQuerySearchPlugin
{

/**
*
* @param mixed $queryParams
*/
public function modify( &$queryParams, $pluginParams = array() )
{
// To test plugin parameters in legacy templates, add to the search hash array:
// 'plugin_parameters', hash( 'TestPlugin', hash( 'ClassIdentifier', 'folder' ) )
// and add 'folder' as one of the search keywords or any other class identifier that may be fit

$classIdentifier = isset($pluginParams['TestPlugin']['ClassIdentifier']) ? $pluginParams['TestPlugin']['ClassIdentifier'] : 'article';
if ( strpos( $queryParams['q'], $classIdentifier ) !== FALSE )
{
$queryParams['fq'][]='meta_class_identifier_ms:' . $classIdentifier;
//remove the filter value from the query string
$queryParams['q'] = str_ireplace( $classIdentifier, '', $queryParams['q']) ;
}
}
}
6 changes: 5 additions & 1 deletion modules/ezfind/function_definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@
array ( 'name' => 'extended_attribute_filter',
'type' => 'array',
'required' => false,
'default' => array() )) );
'default' => array() ),
array ( 'name' => 'plugin_parameters',
'type' => 'array',
'required' => false,
'default' => array() ) ));


$FunctionList['getDefaultSearchFacets'] = array( 'name' => 'getDefaultSearchFacets',
Expand Down
29 changes: 28 additions & 1 deletion search/plugins/ezsolr/ezsolr.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,33 @@ function search( $searchText, $params = array(), $searchTypes = array() )

eZDebug::createAccumulator( 'Engine time', 'eZ Find' );
eZDebug::accumulatorStart( 'Engine time' );

// Since 2015-04-12 PBo : query time plugins
$generalSearchPlugins = $this->FindINI->variable('QueryPlugins', 'Search');
if (!empty($generalSearchPlugins))
{
$pluginParameters = isset( $params['PluginParameters'] ) ? $params['PluginParameters'] : array();
foreach ($generalSearchPlugins as $pluginClassString)
{
if (!class_exists($pluginClassString))
{
eZDebug::writeError("Unable to find the PHP class '$pluginClassString' defined for query time plugins for eZ Find", __METHOD__);
continue;
}
$plugin = new $pluginClassString;
if ($plugin instanceof ezfQuerySearchPlugin)
{
$plugin->modify( $queryParams, $pluginParameters );
eZDebugSetting::writeDebug( 'extension-ezfind-query', $queryParams, 'Query plugin modified parameters sent to Solr backend' );
}
else
{
eZDebug::writeError("Provided plugin '$pluginClassString' is not of the correct type: ezfQuerySearchPlugin", __METHOD__);
continue;
}
}
}

$resultArray = $coreToUse->rawSearch( $queryParams );
eZDebug::accumulatorStop( 'Engine time' );
}
Expand Down Expand Up @@ -1380,7 +1407,7 @@ static function engineText()
$extensionInfo = ezpExtension::getInstance( 'ezfind' )->getInfo();
return ezpI18n::tr(
'ezfind',
'eZ Find %version search plugin &copy; 1999-2014 eZ Systems AS, powered by Apache Solr 4.7.0',
'eZ Find %version search plugin &copy; 1999-2014 eZ Systems AS, powered by Apache Solr 4.10.1',
null,
array( '%version' => $extensionInfo['version'] )
);
Expand Down
6 changes: 5 additions & 1 deletion settings/ezfind.ini
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,8 @@ FiltersList[geodist]=eZFindGeoDistExtendedAttributeFilter

[QueryBoost]
RawBoostQueries[]
#RawBoostQueries[]=meta_class_identifier_ms:folder^10
#RawBoostQueries[]=meta_class_identifier_ms:folder^10

[QueryPlugins]
Search[]
//Search[]=ezfTestQueryPlugin

0 comments on commit b6e6869

Please sign in to comment.