MongoDB fulltext search + workaround for partial word match

前端 未结 5 997
予麋鹿
予麋鹿 2021-02-05 03:51

Since it is not possible to find \"blueberry\" by the word \"blue\" by using a mongodb full text search, I want to help my users to complete the word \"blue\" to \"blueberry\".

5条回答
  •  北恋
    北恋 (楼主)
    2021-02-05 04:26

    A simple workaround I am doing right now is to break the text into individual chars stored as a text indexed array.

    Then when you do the $search query you simply break up the query into chars again.

    Please note that this only works for short strings say length smaller than 32 otherwise the indexing building process will take really long thus performance will be down significantly when inserting new records.

提交回复
热议问题