Skip to content

Commit

Permalink
search lambda: add "freeform" action
Browse files Browse the repository at this point in the history
  • Loading branch information
nl0 committed Mar 9, 2021
1 parent 542514e commit 9c5d846
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* [Added] Populate package name with username prefix ([#2016](https://github.com/quiltdata/quilt/pull/2016))
* [Added] Link from bucket overview page to bucket settings ([#2022](https://github.com/quiltdata/quilt/pull/2022))
* [Added] Folder to package dialog ([#2040](https://github.com/quiltdata/quilt/pull/2040))
* [Added] Search lambda: `freeform` action ([#2087](https://github.com/quiltdata/quilt/pull/2087))
* [Changed] Tree view for files in package update dialog ([#1989](https://github.com/quiltdata/quilt/pull/1989))
* [Changed] Lambda indexing retry logic to not fail content extraction ([#2007](https://github.com/quiltdata/quilt/pull/2007))
* [Changed] Number of retries per ES and S3 failure in indexing Lambda ([#1987](https://github.com/quiltdata/quilt/pull/1987))
Expand Down
4 changes: 4 additions & 0 deletions lambdas/search/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ def lambda_handler(request):
'hits.total',
'aggregations.objects.buckets.latest.hits.hits._source',
)
elif action == 'freeform':
body = user_body
size = user_size
_source = user_source
else:
return make_json_response(400, {"title": "Invalid action"})

Expand Down
38 changes: 38 additions & 0 deletions lambdas/search/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,41 @@ def _callback(request):
resp = lambda_handler(event, None)
assert resp['statusCode'] == 200
assert json.loads(resp['body']) == ES_STATS_RESPONSES['all_gz']

def test_freeform(self):
"""test freeform querying"""
resp = {'RESP': True}
body = {'query': {'match_all': {}}}
query = {
'action': 'freeform',
'index': 'idx1,idx2',
'_source': 'false',
'size': 0,
'from': 0,
'body': body,
'filter_path': 'hits',
}
url = 'https://www.example.com:443/idx1,idx2/_search?' + urlencode({
'_source': 'false', # must match JSON; False will fail match_querystring
'size': 0,
'from': 0,
'filter_path': 'hits',
'terminate_after': 10000,
})

def _callback(request):
assert json.loads(request.body) == body
return 200, {}, resp

self.requests_mock.add_callback(
responses.GET,
url,
callback=_callback,
content_type='application/json',
match_querystring=True,
)

event = self._make_event(query)
resp = lambda_handler(event, None)
assert resp['statusCode'] == 200
assert resp['body'] == resp

0 comments on commit 9c5d846

Please sign in to comment.