Skip to content

Instantly share code, notes, and snippets.

@freshjones
Created April 16, 2015 11:54
Show Gist options
  • Select an option

  • Save freshjones/5378ea75609e3fc9cc8a to your computer and use it in GitHub Desktop.

Select an option

Save freshjones/5378ea75609e3fc9cc8a to your computer and use it in GitHub Desktop.
query override for search api solr direct parse to combine single and multi parsing options
$query = $call_args['query'];
if(!strlen($query)) return;
$q = strtolower($query);
$qArray = explode(" ", trim($q, ' "') );
$segments = array();
$count = 0;
foreach($qArray AS $key => $value)
{
if($value != 'and')
{
$segments[$count][] = $value;
} else {
$count++;
}
}
if(!empty($segments))
{
$qSegements = array();
foreach($segments AS $key => $values)
{
$qSegements[] = '"' . implode(' ', $values) . '"';
}
if (!empty($qSegements))
{
$qString = implode(' AND ', $qSegements);
}
}
$call_args['query'] = isset($qString) ? $qString : $query;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment