New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement attributesToRetrieve for getObjects method #273
Conversation
* | ||
* @return mixed | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function getObjects($objectIDs) | ||
public function getObjects($objectIDs, $attributesToRetrieve = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should ask for an array of strings like we do for the other methods.
The documentation is bad for some of the other methods, we say we expect comma separated values where we are actually accepting arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to be consistent with getObject
method where we take comma-separated string.
Definitely not something I'd approve and I'd definitely rather accept array
, but for me consistency has higher priority right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arg, I just tested and it doesn't work with an array in the 'getObject' method.
I would:
- Make sure we support arrays in both
getObject
andgetObjects
- Change docbloc and documentation to array
- Keep backward compat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, can you review @rayrutjes?
src/AlgoliaSearch/Index.php
Outdated
@@ -210,12 +214,14 @@ public function getObject($objectID, $attributesToRetrieve = null) | |||
* Get several objects from this index. | |||
* | |||
* @param array $objectIDs the array of unique identifier of objects to retrieve | |||
* @param array $attributesToRetrieve (optional) if set, contains the list of attributes to retrieve as a string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change the docblock here to 'array of strings' en not mention the 'separated by ,' anymore
@@ -224,6 +230,15 @@ public function getObjects($objectIDs) | |||
$requests = array(); | |||
foreach ($objectIDs as $object) { | |||
$req = array('indexName' => $this->indexName, 'objectID' => $object); | |||
|
|||
if ($attributesToRetrieve) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail if empty array is provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct behavior. Empty array = all attributes are fetched
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not the current behaviour. Empty string returns only objectIDs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the API behavior for getObject
endpoint. For getObjects
API returns all attributes on empty string/array.
4b4ccb6
to
a4dd529
Compare
LGTM! |
* chore(ci): skip spreading if generated/main does not exist * chore: update implementation of gitBranchExists
Fixes #258