MongoDB order result by more content in fields

I have a collection that contain data like

{
    "_id": {
        "$oid": "610b5c978e82a1738333dfc1"
    },
    "title": "What is Lorem Ipsum?",
    "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry",
    "body": "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, Unknown printer galley of type and scrambled it to make a type specimen book."
}

{
    "_id": {
        "$oid": "610b5fa2c96a6958dc654881"
    },
    "title": "Where does it come from? book",
    "description": "It was popularised in the 1960s with the release of Letraset sheets book",
    "body": "Contrary to popular belief, Lorem Ipsum random text. It has roots in a piece of classical Latin literature from 45 BC making it over 2000 years old. Book"
}

{
    "_id": {
        "$oid": "610b5fa2c96a6958dc654881"
    },
    "title": "Why do we use it? Magic",
    "description": "It is a long established fact that a reader will be distracted. Magic",
    "body": "The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using, making it look like readable English. Magic"
}

{
    "_id": {
        "$oid": "610b5fa7c96a6958dc654884"
    },
    "title": "Magic Where can I get some?",
    "description": "Magic There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration",
    "body": "If you are going to use magic Lorem Ipsum, you need to be sure there isn't anything hidden in the middle of text. All the Lorem Ipsum generators on the Internet"
}

I want to search for a word and find in all table but my problem I don’t know how to order them by the object that has the word used in more fields

Example if I search for book the first result should be the second object because the second object has the word book in title and description and in body so he should be the first one. If I search for Magic the first result should be the 3rd and the 4th object because the last two object has Magic in title, description and body

I mean the 1st will be the object that has the word in all fields the second will be the one with the word in two fields and last one will be the object that has the word in only one fields

I tried my code like :

$query->where(['or', ['like', 'title', $key ], ['like', 'description', $key ], ['like', 'body', $key ]])->all();

I would do a nested AND & OR condition. The 1st nest will be AND of all 3 and the result will be multiplied by say 1000. The 2nd will be 3 AND conditions for all combinations with each having a weight of 100. The last will be 3 individual conditions. All of these ANDs (counting about 7 in all) will then need to be summed and/or ORd together. Now, as you can imagine I have not worked this out to give you the exact answer. It may need a set of queries/counts rather than just one complex one.

how can I use this mongodb query on Yii

db.articles.find( { $text: { $search: "coffee" } } )

this query is working on mongo on my terminal
I did :

$collection = Yii::$app->mongodb->getCollection('mydata');
        $result = $collection->find([
            [
                '$text' => [
                    '$search' => $key,
                ]
            ]
        ]);

The query I copy it from : https://docs.mongodb.com/manual/reference/operator/query/text/
I get this error :

TypeError

strtoupper(): Argument #1 ($string) must be of type string, array given

I can try to answer this, but have not used MongoDB. Looking at the API reference Class yii\mongodb\Collection - find() method it appears you have to provide 1 to 3 array arguments. It appears you may have provided a nested array for the 1st argument. I think the 1st argument should be of the form

['status' => 1, 'type' => 2]

Look at this Stackoverflow answer for reference.

is not working I don’t even have status and type on my table

That was just an example. You may have to substitute with the columns in your table you need to filter.

thank you but is not what I’m looking for my search is that the query search in all fields and return the object that have more scor of the word i’m looking for
what you did is find where status = 1 and type = 2
but what I’m looking for is where all field %keyword% and sort by more score
like in the documents