Skip to content

Commit

Permalink
index query limit: ensure 'limit' is correctly applied to XmlQueryInd…
Browse files Browse the repository at this point in the history
…exSource, fixes ukwa/ukwa-pywb#49 (#523)
  • Loading branch information
ikreymer committed Nov 22, 2019
1 parent 3068080 commit 0be8452
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pywb/warcserver/index/indexsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ def load_index(self, params):
raise BadRequestException('matchType={0} is not supported'.format(matchType=matchType))

try:
limit = params.get('limit')
if limit:
query = 'limit: {0} '.format(limit) + query

# OpenSearch API requires double-escaping
# TODO: add option to not double escape if needed
query_url = self.query_api_url + '?q=' + quote_plus(query + quote_plus(url))
Expand Down
11 changes: 10 additions & 1 deletion pywb/warcserver/index/test/test_xmlquery_indexsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
import pytest


query_url = None


# ============================================================================
def mock_get(self, url):
string = ''
global query_url
query_url = url
if quote_plus(XmlQueryIndexSource.EXACT_QUERY) in url:
if quote_plus(quote_plus('http://example.com/some/path')) in url:
string = URL_RESPONSE_2
Expand Down Expand Up @@ -65,12 +70,14 @@ def do_query(self, params):

@patch('pywb.warcserver.index.indexsource.requests.sessions.Session.get', mock_get)
def test_exact_query(self):
res, errs = self.do_query({'url': 'http://example.com/'})
res, errs = self.do_query({'url': 'http://example.com/', 'limit': 100})

expected = """\
com,example)/ 20180112200243 example.warc.gz
com,example)/ 20180216200300 example.warc.gz"""
assert(key_ts_res(res) == expected)
assert(errs == {})
assert query_url == 'http://localhost:8080/path?q=limit%3A+100+type%3Aurlquery+url%3Ahttp%253A%252F%252Fexample.com%252F'


@patch('pywb.warcserver.index.indexsource.requests.sessions.Session.get', mock_get)
Expand All @@ -82,6 +89,8 @@ def test_exact_query_2(self):
assert(key_ts_res(res) == expected)
assert(errs == {})

assert query_url == 'http://localhost:8080/path?q=type%3Aurlquery+url%3Ahttp%253A%252F%252Fexample.com%252Fsome%252Fpath'


@patch('pywb.warcserver.index.indexsource.requests.sessions.Session.get', mock_get)
def test_prefix_query(self):
Expand Down

0 comments on commit 0be8452

Please sign in to comment.