Reputation: 12877
For fields with a unique name, you can just do doc.field('prop').value
, but when you try to do that with a field with a name that occurs multiple times, you get
ValueError: Must have exactly one field with name prop, but found 3.
I've looked through the source of the Document class, but I couldn't find a method that returns a list of values associated with fields of a given name. Is there a good way to do that?
To be clear, I'm trying to do this with a Document, not a ScoredDocument.
Upvotes: 0
Views: 108
Reputation: 12877
When looking through the source code, I ignored any methods that started with underscores, because most of them were either private, or methods like __eq__
. I clearly shouldn't have done that, because the document class implements __get__
, so if a document has multiple fields named 'prop', you can do the following to get all its values:
values = [field.value for field in doc['prop']]
Upvotes: 2