Skip to content

Commit

Permalink
Organize distinct extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed Sep 4, 2024
1 parent 96d54cc commit 303dbac
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,24 @@ def apply_extra(self, extras):
if extras:
extras = extras.split('|')
for x in extras:
if x == 'distinct-situations':
if x == 'distinct-situations-exact':
if 'cards' in self.q:
self.q['cards'].setdefault('aggs', {})['situations'] = {
self.q['cards'].setdefault('aggs', {})['situations_exact'] = {
'terms': {
'field': f'situations.id',
'size': 1000
}
}
self.extract_agg = True
if x == 'distinct-responses-exact':
if 'cards' in self.q:
self.q['cards'].setdefault('aggs', {})['responses_exact'] = {
'terms': {
'field': f'responses.id',
'size': 1000
}
}
self.extract_agg = True
if x == 'distinct-responses':
if 'cards' in self.q:
min_score = self.q['cards'].get('min_score', 0)
Expand Down Expand Up @@ -110,13 +119,13 @@ def apply_extra(self, extras):
}
}
self.extract_agg = True
if x == 'distinct-responses-only':
if x == 'distinct-situations':
if 'cards' in self.q:
min_score = self.q['cards'].get('min_score', 0)
if min_score > 0:
self.q['cards'].setdefault('aggs', {})['responses'] = {
self.q['cards'].setdefault('aggs', {})['situations'] = {
'terms': {
'field': f'responses.id',
'field': f'situations.id',
'size': 1000
},
'aggs': {
Expand All @@ -128,9 +137,9 @@ def apply_extra(self, extras):
},
}
else:
self.q['cards'].setdefault('aggs', {})['responses'] = {
self.q['cards'].setdefault('aggs', {})['situations'] = {
'terms': {
'field': f'responses.id',
'field': f'situations.id',
'size': 1000
}
}
Expand Down

0 comments on commit 303dbac

Please sign in to comment.