Skip to content

Commit

Permalink
Merge pull request mozilla-services#3388 from mozilla/revert-3385-rev…
Browse files Browse the repository at this point in the history
…ert-3384-1282529-boolean-filter-supersearch

cancel mission revert command, rerevert
  • Loading branch information
lonnen authored Jul 13, 2016
2 parents 6cc2a96 + eea6624 commit 97d77ec
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
10 changes: 8 additions & 2 deletions socorro/external/es/supersearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

import datetime
import re
from elasticsearch_dsl import Search, A, F, Q

from elasticsearch.exceptions import NotFoundError
from elasticsearch_dsl import A, F, Q, Search

from socorrolib.lib import (
BadArgumentError,
MissingArgumentError,
datetimeutil,
)

from socorro.external.es.super_search_fields import SuperSearchFields
from socorro.middleware.search_common import SearchBase
from socorrolib.lib import datetimeutil


BAD_INDEX_REGEX = re.compile('\[\[(.*)\] missing\]')
Expand Down Expand Up @@ -305,6 +307,10 @@ def get(self, **kwargs):
elif param.operator == '__null__':
filter_type = 'missing'
args['field'] = name
elif param.operator == '__true__':
filter_type = 'term'
filter_value = True
args['field'] = name
elif param.operator == '@':
filter_type = 'regexp'
if field_data['has_full_version']:
Expand Down
3 changes: 3 additions & 0 deletions socorro/middleware/search_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* '>' -> 'greater'
* '<' -> 'lower'
* '__null__' -> 'is null'
* '__true__' -> 'is true'
* '!' -> 'not' (prefix)
Note: the order of operators matters, largest operators should be first.
Expand All @@ -37,13 +38,15 @@
"""
OPERATOR_NOT = '!'
OPERATORS_BASE = ['']
OPERATORS_BOOL = ['__true__']
OPERATORS_STRING = ['__null__', '=', '~', '$', '^', '@']
OPERATORS_NUMBER = ['>=', '<=', '<', '>']
OPERATORS_MAP = {
'str': OPERATORS_STRING + OPERATORS_BASE,
'int': OPERATORS_NUMBER + OPERATORS_BASE,
'date': OPERATORS_NUMBER,
'datetime': OPERATORS_NUMBER,
'bool': OPERATORS_BOOL,
'enum': OPERATORS_BASE,
'default': OPERATORS_BASE,
}
Expand Down
16 changes: 12 additions & 4 deletions socorro/unittest/external/es/test_supersearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,19 @@ def test_get_with_bool_operators(self):
'Accessibility': True,
},
)
self.index_crash(
processed_crash={
'date_processed': self.now,
},
raw_crash={
# Missing value should also be considered as "false".
},
)
self.refresh_index()

# Test the "has terms" operator.
res = self.api.get(
accessibility='true', # is true
accessibility='__true__', # is true
_columns=['accessibility'],
)

Expand All @@ -444,12 +452,12 @@ def test_get_with_bool_operators(self):
ok_(hit['accessibility'])

res = self.api.get(
accessibility='f', # is false
accessibility='!__true__', # is false
_columns=['accessibility'],
)

eq_(res['total'], 1)
eq_(len(res['hits']), 1)
eq_(res['total'], 2)
eq_(len(res['hits']), 2)
ok_(not res['hits'][0]['accessibility'])

@minimum_es_version('1.0')
Expand Down
4 changes: 2 additions & 2 deletions webapp-django/crashstats/supersearch/form_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ def to_python(self, value):
if value is None:
return None
if str(value).lower() in ('__true__', 'true', 't', '1', 'y', 'yes'):
return 'true'
return 'false'
return '__true__'
return '!__true__'

0 comments on commit 97d77ec

Please sign in to comment.