Modify Search Parameters Using search_sql Hook

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
			// ???
		}
        }
    }      
}

I ended up doing something like this after I realized that the fields are not delineated in the fulltext search…

public function hookSearchSql($args)
{
	$params = $args['params'];
	if ('custom' == $params['query_type']) {
		if ($params['query'] == 'AUTHORNAME'){
			$select = $args['select'];
			$select->where('`text` NOT REGEXP ?', 'AUTHORNAME Archival Library');
		}
	}	
}      

This worked (more or less) in my particular case, since we were trying to avoid cluttering up the search results for a particular Author whose name also appears in the Source field for many other unrelated records.

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.