Hi everyone,
I'm building a faceted navigation with Elastica, and it's not easy - maybe I'm doing it wrong?
Let's say I have documents like this:
{
title: "Hi there",
text: "Lipsum",
author: "Damien"
}
{
title: "Hi there 2",
text: "Lipsum 2",
author: "Damien"
}
{
title: "Hi there 3",
text: "Lipsum 3",
author: "Robert"
}
I have this search:
$elasticaQueryString = new Elastica\Query\QueryString("Hi");
$elasticaQuery = new Elastica\Query();
$elasticaQuery->setQuery($elasticaQueryString);
$facets = array();
$elasticaFacet = new \Elastica\Facet\Terms('author');
$elasticaFacet->setField('author');
$elasticaFacet->setSize(10);
$facets[] = $elasticaFacet;
// More facets here...
$elasticaQuery->setFacets($facets);
$search = new \Elastica\Search($this->getClient());
$search->setQuery($elasticaQuery);
The result is fine. And I get a Facet "author" with two terms, Damien (2) and Robert (1).
Now, what's happen if my user select the Facet "author" of value "Damien"? I want to apply this facet value to my request,
but there is no way to do it?
Seem's to me that there is no way to actually set as "selected value" to a Facet?
How I do it is quite painful:
// Depending on my query string, I retrieve the facet:
$filter = new \Elastica\Filter\Terms($facet->getParam('field'), array($term));
and then I transform my Query to a Filtered Query:
$elasticaQuery->setQuery(new Elastica\Query\Filtered($elasticaQueryString, $filter));
This only works for Term facets, and I don't want to map the Facets types to Query types manually!
Does Elastica could do that?
How do you apply a selected Facet to a query?
This is a lot of questions,
I hope I have explained it well :)
Also, it's for a Symfony project, I'm quite sure this kind of feature is a must have for search,
I'm very surprised to find so low resources about Faceted navigation for ElasticSearch...
Have a nice weekend!
Damien