Skip to content

Commit

Permalink
Merge pull request #4 from doofinder/1653-adapt-query-params
Browse files Browse the repository at this point in the history
 #1653 remove ESfilters conversion
  • Loading branch information
JoeZ99 committed May 30, 2014
2 parents 6a0516b + ddf65e8 commit 3c13961
Showing 1 changed file with 0 additions and 62 deletions.
62 changes: 0 additions & 62 deletions lib/doofinder_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ public function query($query=null, $page=null, $options = array()){
$params['query_name'] = $dfResults->getProperty('query_name');
$params['filter'] = $filter;
}
$params['filter'] = $this->obtainESFilter(isset($params['filter'])?$params['filter']:null);
$dfResults = $this->apiCall($params);
$this->page = $dfResults->getProperty('page');
$this->total = $dfResults->getProperty('total');
Expand Down Expand Up @@ -440,67 +439,6 @@ public function setQueryName($queryName){
$this->queryName = $queryName;
}

/**
* obtainESFilter
*
* translate filter friendly format:
* array('color'=>array('blue','red'), 'price'=>array('from'=>33, 'to'=>99))
* to ES format:
* array('terms'=>array('color'=>array('blue','red')), 'numeric_range'=>array('price'=>array('from'=>33, 'to'=>99)))
*
* @param array filter friendly format
* @return array filter in ES format
*/
private function obtainESFilter($filter){

// translate filter to ES syntax
$numericRangeFilters = array();
$termsFilters = array();
$result = array();

if(!$filter)
{
return null;
}
foreach($filter as $filterName => $filterProperties)
{
switch($this->getFilterType($filterProperties))
{
case 'numericrange':
if(isset($filterProperties['from']) && !trim($filterProperties['from']))
{
unset($filterProperties['from']);
}
if(isset($filterProperties['to']) && !trim($filterProperties['to']))
{
unset($filterProperties['to']);
}
if(!count($filterProperties))
{
break;
}
$numericRangeFilters[$filterName] = $filterProperties;
$numericRangeFilters[$filterName]['include_upper']=true;
break;
case 'terms':
$termsFilters[$filterName] = $filterProperties;
break;
}
}

if($numericRangeFilters)
{
$result['numeric_range'] = $numericRangeFilters;
}

if($termsFilters)
{
$result['terms'] = $termsFilters;
}

return count($result) ? $result : null;
}

/**
* getFilterType
* obtain the filter type (i.e. 'terms' or 'numeric range' from its conditions)
Expand Down

0 comments on commit 3c13961

Please sign in to comment.