Open jontroncoso opened 8 years ago
I was able to get to the sort field by overloading the newFromHitBuilder
method on my model:
/* App\Location.php */
use ElasticquentTrait {
newFromHitBuilder as elasticquentNewFromHitBuilder;
}
...
public function newFromHitBuilder($hit = array())
{
if(!empty($hit['sort']))$hit['fields']['sort'] = $hit['sort'];
return $this->elasticquentNewFromHitBuilder($hit);
}
I technically got around this so you can close this if you like. But you might want to make this functionality more accessible. If so, feel free to to leave this open.
I don't think that this should be a configuration option.
It is preferred that configuration options of the library do not change the functionality. This way, you can be sure that calling a method will always work as expected.
Maybe a new method that returns all of the data as newFromHitBuilder
currently does, except it merges in the data from _source
after all the other values have been merged into another array?
I'm running into the same problem. Without @jontroncoso 's work-around it is currently not possible to get the computed distance on distance sort (thanks for the work-around!) :)
Creating a method that returns all data would be a great addition and add more flexibility to the "power user".
I have a model with this mapping:
I'm using this query:
I get raw documents that look like:
however, when using elasticquent, everything that's not in
_source
is not accessible. Custom getters exist for_score
, but nothing else. It would be great if we could get the entire document as above, rather than a stripped down version. Especially since I would much rather prefer to useLocation::complexSearch($search)->toJson()
rather than iterating through each row and using something like->documentSort()
in a loop.Maybe we can leverage
/config/elasticquent.php
to create an option to simply return the raw data?If this interests you, I can create a PR. I just might do this anyway, since I need this functionality for a project.