def es_search_cmd(query, pages=1, log=log):
    from kitsune.sumo.tests import LocalizingClient
    from kitsune.sumo.urlresolvers import reverse

    client = LocalizingClient()

    output = []
    output.append('Search for: %s' % query)
    output.append('')

    data = {'q': query, 'format': 'json'}
    url = reverse('search')

    # The search view shows 10 results at a time. So we hit it few
    # times---once for each page.
    for pageno in range(pages):
        pageno = pageno + 1
        data['page'] = pageno
        resp = client.get(url, data)
        if resp.status_code != 200:
            output.append('ERROR: %s' % resp.content)
            break

        else:
            content = json.loads(resp.content)
            results = content[u'results']

            for mem in results:
                output.append(u'%4d  %5.2f  %-10s  %-20s' % (
                              mem['rank'], mem['score'], mem['type'],
                              mem['title']))

            output.append('')

    for line in output:
        log.info(line.encode('ascii', 'ignore'))
Simulates a front page search
dataset/ETHPy150Open mozilla/kitsune/kitsune/search/es_utils.py/es_search_cmd