Skip to content

Commit

Permalink
Initial version of query plugin mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
paulborgermans committed Apr 22, 2015
1 parent a24aa70 commit c2efb2a
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
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 );
}

?>
34 changes: 34 additions & 0 deletions classes/queryplugins/ezftestqueryplugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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 )
{
if ( strpos( $queryParams['q'], 'article' ) !== FALSE )
{
$queryParams['fq'][]='meta_class_identifier_ms:article';
//remove the filter value from the query string
$queryParams['q'] = str_ireplace('article', '', $queryParams['q']);
}
}
}
25 changes: 25 additions & 0 deletions search/plugins/ezsolr/ezsolr.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,31 @@ 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))
{
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 );
}
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
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 c2efb2a

Please sign in to comment.