-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
PHPORM-28 Add Scout engine to index into MongoDB Search #3205
Conversation
fa3e0a9
to
12f3323
Compare
13ff6ec
to
4647cf0
Compare
Integration tests require an atlas or local-atlas cluster to run. |
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.
Leaving an incomplete round of feedback. We'll need to schedule some time to actually go through this PR together if you need a meaningful review, as a lot of it is over my head.
1b39753
to
95343b1
Compare
ee6edd2
to
3d030ba
Compare
69fe000
to
831fa21
Compare
7a0344c
to
c628969
Compare
9b74d41
to
a5739e0
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.
Update:
- Existing tests are not touched by the Scout tests. The service provider is registered only for the Scout tests and we use dedicated model classes.
- Sorting search results by
id
field as the order is not constant between index creation. - CI and compose configuration fixed to make atlas search container more resilient (even if it still randomly crashes).
- The mapping is dynamic (soft-delete field not added). Index definition to be made configurable in a follow-up ticket: PHPORM-268
.github/workflows/build-ci.yml
Outdated
@@ -11,6 +11,7 @@ jobs: | |||
name: "PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }} MongoDB ${{ matrix.mongodb }} ${{ matrix.mode }}" | |||
|
|||
strategy: | |||
fail-fast: false |
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.
Tests with Atlas fail randomly (more than 1/4 of tries fail). fail-fast interrupt other jobs before they are successful, making it impossible to get all the tests successful simultaneously.
@@ -63,6 +64,9 @@ jobs: | |||
until docker exec --tty mongodb mongosh 127.0.0.1:27017 --eval "db.runCommand({ ping: 1 })"; do | |||
sleep 1 | |||
done | |||
until docker exec --tty mongodb mongosh 127.0.0.1:27017 --eval "db.createCollection('connection_test') && db.getCollection('connection_test').createSearchIndex({mappings:{dynamic: true}})"; do |
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.
Ensure mongot is ready.
Move scout engine declaration to the main MongoDBServiceProvider
a6e2923
to
5c2c2e8
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.
Noted that most of my previous points were all addressed. Left a few more small things that you can address or ignore as you wish.
ports: | ||
- "27017:27017" | ||
healthcheck: | ||
test: echo 'db.runCommand("ping").ok' | mongosh mongodb:27017 --quiet | ||
test: mongosh --quiet --eval 'db.runCommand("ping").ok' |
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 assume this relies on mongosh
defaulting `localhost:27017"
@@ -65,6 +65,9 @@ jobs: | |||
until docker exec --tty mongodb mongosh 127.0.0.1:27017 --eval "db.runCommand({ ping: 1 })"; do | |||
sleep 1 | |||
done | |||
until docker exec --tty mongodb mongosh 127.0.0.1:27017 --eval "db.createCollection('connection_test') && db.getCollection('connection_test').createSearchIndex({mappings:{dynamic: true}})"; do |
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 docker-compose.yml
you removed the host/port from the mongosh
invocation. Should you do so here as well for consistency? I'm OK with either but 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.
I'll update it as part of PHPORM-287
@@ -17,7 +17,7 @@ | |||
</testsuite> | |||
</testsuites> | |||
<php> | |||
<env name="MONGODB_URI" value="mongodb://mongodb/"/> |
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.
Is the mongodb
hostname a sensible hostname here? In #3205 (comment) you mentioned removing it in favor of the default of localhost:27017
. I understand that you'd need to use an explicit value in this context, but I'd expect to see localhost:27017
instead of mongodb
in that case.
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 default localhost from the mongodb container, but from the other container, you need to specify the mongodb container name.
return 0; | ||
} | ||
|
||
return $results[0]->__count; |
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 seems tightly coupled to the $addFields
stage in performSearch()
. Pointing that out in case you'd like to do something about that.
I assume $results[0]
can be assumed to be a stdClass instance per the internal type map, but @param mixed $results
in the doc block doesn't tell us much. You might be able to address that with an internal assertion even though the method signature cannot be changed.
|
||
/** | ||
* Get the total count from a raw result returned by the engine. | ||
* This is an estimate if the count is larger than 1000. |
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.
A @see
reference to https://www.mongodb.com/docs/atlas/atlas-search/counting/ may be helpful here. You can also mention that this pertains to the pipeline created in performSearch()
since that's what ultimately determines this.
src/Scout/ScoutEngine.php
Outdated
// "filter" specifies conditions on exact values to match | ||
// "mustNot" specifies conditions on exact values that must not match | ||
// They don't contribute to the relevance score | ||
// https://www.mongodb.com/docs/atlas/atlas-search/compound/#options |
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.
@GromNaN: Pointing this out in case you lost track of this and agreed with leaving a comment above.
Fix PHPORM-28
Checklist