1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 15:22:41 +01:00

Use filtered query instead of filter in Elasticsearch

Summary:
The 'filter' works like this: Get all results matching query (all if there's no query), compute facets (if there are any) and then filter out the uninteresting results.
The 'filtered' query applies the filters when searching, not when processing results.
This is obviously not documented anywhere in the great Elasticsearch documentation.
http://stackoverflow.com/questions/14007078/performance-of-elastic-queries

We don't hit this problem very often as we usually use some query.

Test Plan: Searched for open documents using Elasticsearch, verified the sent JSON, verified results.

Reviewers: epriestley, wez

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D6643
This commit is contained in:
Jakub Vrana 2013-08-01 16:38:39 -07:00
parent 78f73e7d45
commit 6c7f36f6b8
2 changed files with 8 additions and 11 deletions

View file

@ -17,9 +17,7 @@ final class PhabricatorSearchSelectController
$user = $request->getUser();
$query = new PhabricatorSearchQuery();
$query_str = $request->getStr('query');
$matches = array();
$query->setQuery($query_str);
$query->setParameter('type', $this->type);

View file

@ -97,7 +97,7 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
$spec = array();
$filter = array();
if ($query->getQuery()) {
if ($query->getQuery() != '') {
$spec[] = array(
'field' => array(
'field.corpus' => $query->getQuery(),
@ -156,15 +156,14 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
if ($filter) {
$filter = array('filter' => array('and' => $filter));
if ($spec) {
$spec = array(
'query' => array(
'filtered' => $spec + $filter,
),
);
} else {
$spec = $filter;
if (!$spec) {
$spec = array('query' => array('match_all' => new stdClass()));
}
$spec = array(
'query' => array(
'filtered' => $spec + $filter,
),
);
}
if (!$query->getQuery()) {