-
Notifications
You must be signed in to change notification settings - Fork 261
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
Add Atlas Search example #1147
Add Atlas Search example #1147
Conversation
c4618ec
to
e9bbf35
Compare
e1d54bd
to
9ea634c
Compare
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.
Should there be test for expected output, or is that intentionally excluded since it's redundant with our spec tests and not portable (although I suppose it could do the same check for an Atlas URI and skip accordingly)?
/** | ||
* This example demonstrates how to create a search index and perform a text search. | ||
* It requires a MongoDB Atlas M10+ cluster with Sample Dataset loaded. | ||
*/ |
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 like the idea of a comment header explaining the purpose of the example. This might be a good place to come up with some header copypasta that notes supported environment variables and/or CLI arguments (down the line, not in this PR).
edf25c8
to
5c8a818
Compare
It would be nice, but that would be very slow to run because it needs to load the sample dataset and the output depends of the state of the cluster: if the index already exists or not. |
Makes sense. I suggest making a note of this in the final commit so there's some record that it was intentionally omitted. |
5c8a818
to
099fe61
Compare
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 added a test with a lot of skip conditions.
if ($index->name === 'default') { | ||
echo '.'; | ||
|
||
return $index->queryable; |
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 is a boolean, but I could not document it in phpdoc. #1097 (comment)
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 see there's no Psalm error here. Is it worth casting this to a boolean and using bool
return type hint for the callback? OK to leave this as-is if it doesn't matter.
099fe61
to
aee4367
Compare
Test can run in CI with #1150 config. |
49c08a7
to
8714314
Compare
if ($index->name === 'default') { | ||
echo '.'; | ||
|
||
return $index->queryable; |
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 see there's no Psalm error here. Is it worth casting this to a boolean and using bool
return type hint for the callback? OK to leave this as-is if it doesn't matter.
tests/ExamplesTest.php
Outdated
$collection = $client->selectCollection('sample_airbnb', 'listingsAndReviews'); | ||
$count = $collection->estimatedDocumentCount(); | ||
if ($count === 0) { | ||
$this->markTestSkipped('Atlas Search examples require the sample_airbnb database with the listingsAndReviews collection'); |
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.
Do I assume correctly that this is for the benefit of running the test locally, and that it will most likely be skipped in CI because we don't load sample data?
I'm OK either way, but just wanted to ask.
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.
We added the @group atlas
, but I think I can insert some data to unit the collection in tests if it does not exist. We would benefit from having the test running in CI.
fb90306
to
ccb799b
Compare
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 loading some sample data for the benefit of CI.
98f0142
to
ef5f19d
Compare
foreach ($indexes as $index) { | ||
if ($index->name === 'default') { | ||
echo "The index already exists. Dropping it.\n"; | ||
$collection->dropSearchIndex($index->name); |
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.
Since this is idempotent, I can remove surrounding loop.
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.
In fact no, the error for NamespaceNotFound
is silenced, not the error for IndexNotFound
.
https://github.com/mongodb/specifications/blob/master/source/index-management/index-management.rst#namespacenotfound-errors
Follow-up #1097
The example requires an Atlas M10+ cluster with Sample data loaded. It creates an index and performs a search query.