Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2015 15:14
What would you like to do?
Example of how to aggregate with filtering using Elastica
$queryString = new QueryString($_GET['q']);
$isoTerm = new Term();
$apeterm = new Term();
$andFilter = new BoolAnd();
$filter = new Filtered(
/*new Range('published', array(
'from' => '2012-01-01 00:00:00',
'to' => '2013-01-01 00:00:00',
$query = new Query($filter);
Copy link

The documentation for Elastica has no examples of how to this. The logic is this:

  1. create a QueryString with the actual search text
  2. create more filter(s) of type Term with the facets selected, here an film speed (ISO) of 4000 and an aperture of 2.7
  3. create a BoolAnd boolean and filter, and add the above filters to it
  4. create a Filtered object filtering the original query string with the and filter
  5. create the Query object

In the case of step 4) and there only being one filter, simply add that and skip the creation of the Boolean And filter. In the case of no facets chosen simply do not add the filter parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment