Closed Daotin closed 1 year ago
Hi @Daotin , If I understand correctly, what you want is prefix search:
const miniSearch = shallowRef(
new MiniSearch({
idField: "name",
fields: ["album", "lrc"],
storeFields: ["name", "lrc"],
searchOptions: {
prefix: true, // prefix search, “foo” matches “foobar”
fuzzy: true // fuzzy search, “foo” matches “fox”
},
extractField: (document, fieldName) => {
if (Array.isArray(document[fieldName])) {
return document[fieldName].join(" ");
} else {
return document[fieldName];
}
},
})
)
Does this meet your needs?
Hi @lucaong, Maybe I didn't express clearly. for example, a string like 你转身向背
, when I search 转身
( The Key words in the middle of the whole sentence), I hope to be able to match. So, probably not the prefix search
.
Ah, I see. Then unfortunately MiniSearch by default does not offer this feature. The options allow to:
foo
matches foobar
)Fuzzy search, also called typo-tolerance: it matches strings within a given Levenshtein distance from the query.
Searching in the middle of a word is generally not possible, but there are some strategies that can work. One possibility is to split each word in all its suffixes, and use prefix search, like explained here. The index would get bigger, but search would match also in the middle of words.
I hope this helps :)
Here is a quick example of what I mean: https://jsbin.com/poloselexa/1/edit?js,console
In the example, I use processTerm
to index all suffixes of length > 3 of each term, then apply prefix search. This results in matching also partial terms in the middle of words.
OK. It works! Thank you and Have a great day. 😀
Great to hear it helped :)
Hi, I have a problem, can you help me. Thanks.
my doc is:
when I search
倒视镜里的世界
, it can be matched. But when I search倒视镜
, It will not be match.So, How can it be matched when searching for
倒视镜
? Finally, I want to achieve the effect of full-text search.Part of the code is as follows (using Vue3):
Appreciate your help, Thanks :-)