elasticsearch/elasticsearch-dsl-py — pull request #15 by dcwatson (2014-09-06 01:01:08+00:00)
Title: Allow customization of response and result classes

This provides a hook to ultimately customize the result creation process. If someone really wanted access to the Response from each Result, they could do something like:

```
class CustomResult (Result):
def __init__(self, doc, response):
super(CustomResult, self).__init__(doc)
self.response = response

@property
def percentile(self):
return self._meta.score / self.response.hits.max_score

class CustomResponse (Response):
def result_factory(self, doc):
return CustomResult(doc, self)
```

And then either call `execute` with a `response_class`:

```
r = Search().execute(response_class=CustomResponse)
```

or specify the response class on the Search itself:

```
s = Search().response_class(CustomResponse)
```

But it would also allow for simpler customizations like overriding `__str__` or adding computed properties directly to results.