E
E
EugeneMedvedev2021-05-21 17:26:53
Mongoose
EugeneMedvedev, 2021-05-21 17:26:53

How to do approximate MongoDB lookup?

I wonder if it's possible to do an approximate search without using regex.

My request is below. I would like to do a quick search for documents by partial match. At least not in terms of content and titles, but only in terms of titles.

I feel like I've stumbled across something like this before. There were percentage points of coincidence and the conclusion was repelled by percentage. I'm interested in this thing, because I couldn't find it again. Although I may have dreamed about it))

For example, so that when you query "Definite integrals", such documents with titles as "how to solve these integrals" are displayed. Conventionally, there is a 30% match due to 1/2 of the query string + an extra letter, which means that you can display it, but somewhere at the end of the list. I think there are those who will understand what I am trying to explain.

In general, I only recently discovered aggregate, until this case, find was enough for me. A handy thing and I wouldn’t be surprised if it has the mechanism I need, or at least a similar one.

.aggregate([
            {$skip: Number(10*((Number(req.query.page) <= 0 ? 0 : req.query.page - 1)))},
            {$limit: 10},
            {
                $project:{
                    answers:{$size:"$answers"},
                    title: "$title",
                    subscribers: {$size:"$subscribers"},
                    creator: "$creator",
                    tags: "$tags",
                    rate: "$rate",
                    timestamp: "$timestamp",
                    index: "$index"
            } 
        }])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2021-05-21
@firedragon

Try this
https://dev.to/djnitehawk/mongodb-fuzzy-text-searc...
However, it's better to use special search engines like Sphinx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question