Search for similar words using an index

落花浮王杯 提交于 2019-12-22 11:11:48

问题


I need to search over a DB table using some kind of fuzzy search like the one from oracle and using indexes since I do not want a table scan(there is a lot of data).

I want to ignore case, language special stuff(ñ, ß, ...) and special characters like _, (), -, etc...

Search for "maria (cool)" should get "maria- COOL" and "María_Cool" as matches.
Is that possible in Oracle in some way?

About the case, I think it can be solved created the index directly in lower case and searching always lower-cased. But I do not know how to solve the special chars stuff.
I thought about storing the data without special chars in a separated column and searching on that returning the real one, but I am not 100% sure where that is the perfect solution.

Any ideas?


回答1:


Maybe UTL_MATCH can help.

But you can also create a function based index on, lets say, something like this:

regexp_replace(your_column, '[^0-9a-zA-Z]+', ' ')

And try to match like this:

...
WHERE regexp_replace(your_column, '[^0-9a-zA-Z]+', ' ') = 
      regexp_replace('maria (cool)' , '[^0-9a-zA-Z]+', ' ')

Here is a sqlfiddle demo It's not complete, but can be a start



来源:https://stackoverflow.com/questions/16336295/search-for-similar-words-using-an-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!