Closed mathieubellon closed 10 years ago
Can you give me a little more context? Which SearchResult class is getting used? Are you getting back some MappingType subclass or tuples or dicts or what?
I built my query and fired it with results = s.all()
I then throwed results
(dict object) to my template.
While iterating through results
django throw me back errors stating that underscored method are not allowed.
Hacking your code at https://github.com/mozilla/elasticutils/blob/master/elasticutils/__init__.py#L1825 and deleting the underscore "solved" the "issue".
Again I might not code this correctly and underscore methods are here for a reason.
@robhudson @jezdez So we use underscores to reduce the likelihood of name clashes between fields in the document and methods on the object and these "metadata" bits. I'm loathe to just remove the underscores. I really want access to the "metadata" bits to be obvious, simple and easy to deal with, but also reduce the likelihood of hard-to-diagnose problems.
I think possible options here might be something like:
meta_id
, meta_highlight
, ... It's still possible to have a clash, but maybe the likelihood is very remote it's not an issue?eu_metadata
or es_metadata
or something like that. Then we reduce the clash to one possible name.{{ my_result|eumeta:"highlight" }}
?Do any of these appeal to you? Are there better options?
Also, I think this is worth fixing for 0.9.
Of the 3 I like 2 the best... whatever you name it. Would we also keep the attributes on the object and add the dict in addition?
We could but I think I'm inclined to either do one or the other and not both if only to reduce unneeded complexity.
I'm toying with an es_meta "object" that has the things as attributes. So then you can do:
{{ obj.es_meta.highlight }}
I think that works pretty well, it's very unlikely that "es_meta" will be a field in the document (we need to document that, but I'm not sure where the best place for that would be--maybe troubleshooting?), and I think it meets all our requirements.
However, we use obj._id
in a lot of places, so I'm inclined to have the id available as obj._id
as well as in the es_meta object as obj.es_meta.id
.
Does that sound icky? If it does, I'll just update the Elasticutils code.
Trying to get highlighted fields from SearchResult object I successfully get them in a Django View following the doc (http://elasticutils.readthedocs.org/en/latest/api.html#elasticutils.S.highlight)
Problem is in Django template : methods with underscore are not allowed.
Should I use a custom template filter/tag for accessing the method ? Does not sound great doesn't it ?