I have a client who’s asked me to modify their search form based on a particular condition. I’ve got the skeleton of a basic plugin below, but am not sure how to proceed with the search_sql
filter. They need to detect if a search query matches a certain phrase and then, if so, limit the search to certain fields, and, if not, proceed with a standard keyword search. Any advice would be appreciated. Thanks – E
<?php
class CustomSearchPlugin extends Omeka_Plugin_AbstractPlugin
{
protected $_filters = array(
'search_form_default_query_type',
'search_query_types',
);
protected $_hooks = array(
'search_sql'
);
public function filterSearchFormDefaultQueryType($searchQueryType){
$searchQueryType='custom';
return $searchQueryType;
}
public function filterSearchQueryTypes($queryTypes)
{
$newType=array('custom'=>__('Default'));
$reordered=array_merge($newType,$queryTypes);
$queryTypes=$reordered;
return $queryTypes;
}
public function hookSearchSql($args)
{
$params = $args['params'];
if ('custom' == $params['query_type']) {
if ($params['query'] == 'some phrase'){
// search only select fields
// ???
}else{
// do a keyword search
// ???
}
}
}
}