Exemplo n.º 1
0
def autocomplete(request):
    import pprint

    test = Search([], "abc xyz def action")
    response = pprint.pformat([[obj.__str__() for obj in l] for l in test.autoComplete(10)])

    return HttpResponse(response)
Exemplo n.º 2
0
    def get(self, request):
        query =  request.GET.getlist('query')

        try:
            search = Search.fromJSON(query)     
        except ValueError as e:
            return HttpResponseBadRequest("Bad request: %s" % e)

        completed = search.autoComplete(10) # TODO remove magic number

        result_list = [[block.as_list() for block in suggestion] for suggestion in completed]

        return self.render_to_response(result_list)