Mongoose fuzzy query questions, ask code friends for help

problem description

for example, take the World Foreign language School as an example. When you use mongoose"s $regex for fuzzy matching, you can match when you enter keywords such as the world and foreign languages, but when you enter keywords that skip words in the middle of the world, you can"t match

.

the environmental background of the problems and what methods you have tried

problems encountered when doing full-text search

related codes

/ / Please paste the code text below (do not replace the code with pictures)

if(filter.s){
    condition.school = { $regex: filter.s };
}

what result do you expect? What is the error message actually seen?

expected result: input outside the world can match to the World Foreign language School
error message: no error message, but no match


this has something to do with the way you write your regular expression. To achieve your goal, you need to do some extra strategies.

  1. use input for direct matching. If there is no match to proceed to the second step
  2. disassemble the input source, such as "out of the world". It can be divided into worlds and outsiders. The regular search is the world * outside the world

there are many third-party libraries available for disassembly input. You can disassemble

according to nouns and verbs.
Menu