Commit 43912094 authored by Aaron Wells's avatar Aaron Wells Committed by Robert Lyon
Browse files

Patching search/elasticsearch to work with elasticsearch 0.9 and 1.5

Bug 1384498: Query->set_filter() uses a "post_filter" param, which
isn't supported in Elasticsearch 0.9. But if we use a \Query\Filtered,
it works in both versions.

Change-Id: Ie82edb35740a390b89c19a430fea36a4abf6b69f
parent 2455c049
......@@ -1227,14 +1227,14 @@ class ElasticsearchPseudotype_all
$elasticaQuery = new \Elastica\Query();
$elasticaQuery->setFrom($offset);
$elasticaQuery->setLimit($limit);
$elasticaQuery->setQuery($elasticaQueryString);
$elasticaFilterAnd = new \Elastica\Filter\BoolAnd();
// Apply ACL filters
$elasticaFilterACL = new ElasticsearchFilterAcl($USER);
$elasticaFilterAnd->addFilter($elasticaFilterACL);
$elasticaQuery->setFilter($elasticaFilterAnd);
$elasticaFilteredQuery = new \Elastica\Query\Filtered($elasticaQueryString, $elasticaFilterAnd);
$elasticaQuery->setQuery($elasticaFilteredQuery);
// Define a new facet: mainFacetTerm - WARNING: don't forget to apply the same filter to the facet
$elasticaFacet = new \Elastica\Facet\Terms('mainFacetTerm');
......@@ -1263,10 +1263,12 @@ class ElasticsearchPseudotype_all
$elasticaFilterType = new \Elastica\Filter\Term(array('mainfacetterm' => $result['selected']));
$elasticaFilterAnd->addFilter($elasticaFilterType);
$elasticaQuery->setFilter($elasticaFilterAnd);
$elasticaFilteredQuery = new \Elastica\Query\Filtered($elasticaQueryString, $elasticaFilterAnd);
$elasticaQuery->setQuery($elasticaFilteredQuery);
// Define a new facet: secFacetTerm - WARNING: don't forget to apply the same filter to the facet
$elasticaFacet = new \Elastica\Facet\Terms('secFacetTerm');
$elasticaFacet = new \Elastica\Facet\Terms('secFacetTerm');
$elasticaFacet->setField('secfacetterm');
$elasticaFacet->setOrder('count');
$elasticaFacet->setFilter($elasticaFilterAnd);
......@@ -1319,7 +1321,8 @@ class ElasticsearchPseudotype_all
$elasticaFilterAnd->addFilter($elasticaFilterLicense);
}
$elasticaQuery->setFilter($elasticaFilterAnd);
$elasticaFilteredQuery = new \Elastica\Query\Filtered($elasticaQueryString, $elasticaFilterAnd);
$elasticaQuery->setQuery($elasticaFilteredQuery);
$elasticaResultSet = $elasticaIndex->search($elasticaQuery);
$elasticaResults = $elasticaResultSet->getResults();
$result['count'] = $elasticaResultSet->getTotalHits();
......
......@@ -420,7 +420,8 @@ class ElasticsearchType_artefact extends ElasticsearchType
$elasticaFilterACL = new ElasticsearchFilterAcl($USER);
$elasticaFilterAnd->addFilter($elasticaFilterACL);
$elasticaQuery->setFilter($elasticaFilterAnd);
$elasticaFilteredQuery = new \Elastica\Query\Filtered(null, $elasticaFilterAnd);
$elasticaQuery->setQuery($elasticaFilteredQuery);
$elasticaResultSet = $elasticaIndex->search($elasticaQuery);
$elasticaResults = $elasticaResultSet->getResults();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment