-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
MongoDB Search Adapter #482
Comments
Of course, that's an excellent idea. Atlas Search is using a Lucene index next to a MongoDB database. You store BSON documents in a MongoDB collection, and they are asynchronously indexed into the search indexes. The search results are documents from the MongoDB collection. This is perfect to avoid manual replication between the main database and the search engine. It can also be used as a search engine on its own. In order to use MongoDB in a PHP project, you need to install the MongoDB Atlas Search server is available on Atlas Cloud (including with a forever-free cluster). For dev and test, we have as docker image. Example of configuration that I use: docker-composer.yaml. The Atlas search feature will land in the community edition of MongoDB in the coming months. You can play with MongoDB Search features using:
You can also check the Laravel Scout Engine for MongoDB. |
@GromNaN thank you for the quick response, the resources helps and the docker image is awesome we use docker compose file for the Github CI here nice that we could do that with the mongodb also. Some questions I have you maybe can quickly answer:
|
In MongoDB, the identifier field is always
To enforce strict mapping, you must set $collection->createSearchIndex(
[
'mappings' => [
'dynamic' => false,
'fields' => [
['rootField' => ['type' => '<field-type>']],
['nested.field.path' => ['type' => '<field-type>']],
// ...
],
],
],
); The dot notation is used for the path of nested fields (subdocuments) in query and index definition. Index and query field path is the same for lists and simple values (similar to ElasticSearch), the indexed field can contain a single value or a list of values.
MongoDB supports nested documents, you can insert documents like this: $collection->insertOne([
'_id' => 'using a string is possible',
'date' => new \MongoDB\BSON\UTCDateTime(new DateTime()),
'bool' => true,
'float' => 2.1,
'int' => 10,
'list_of_ints' => [1, 2, 3, 4],
'string' => 'Hello',
'subdocument' => ['foo' => 'bar'],
'list of subdocuments' => [
['_id' => new ObjectId(), 'foo' => 'bar'],
['_id' => new ObjectId(), 'foo' => 'baz'],
],
'bigint' => new \MongoDB\BSON\Int64('9007199254740991'),
]) Dates must be converted to
I would recommend using the
$collection->aggregate([
[
'$search' => [
'compound' => {
'must' => [[
'text' => [
'query' => 'varieties',
'path' => 'description',
],
]],
'mustNot' => [[
'text' => [
'query' => 'apples',
'path' => 'description',
],
]],
],
],
],
], ['typeMap' => ['root' => 'array', 'document' => 'array', 'array' => 'array']]); Also, I recommend using this |
As already mention in the Research Document MongoDB has a search feature, called
Atlas Search
: https://www.mongodb.com/products/platform/atlas-searchBeside our existing lists of Search Engine I think MongoDB would be also a interesting one, designed as a documented based database I think it could be a nice fit for SEAL.
Creating a new adapter should maybe be straight forward https://php-cmsig.github.io/search/cookbooks/create-own-adapter.html sadly I'm not familiar with mongodb ecosystem and how self hosted and atlas hosted version are differently and what would be keep in mind when implementing a search, if one adapter can support both atlas and self hosted or if atlas would be its own adapter.
Maybe @GromNaN or @alcaeus can support here how we can achieve maybe a mongodb adapter.
The text was updated successfully, but these errors were encountered: