简体   繁体   English

Oracle SQL模糊搜索varchar列中的单词

[英]Oracle SQL fuzzy search for words in a varchar column

We have an Address table with a lot of columns. 我们有一个包含很多列的Address表。

Example schema 模式范例

Address: 地址:

Id | ADDR_LN1      | ADDR_LN2  | ADDR_LN3
---------------------------------------
1  | 3330 Scott st | Suite 300 | Houston TX 77058

The user searches for text say using 3 input fields: 用户使用3个输入字段搜索要说的文字:

Textinput1: 3330 Scott Street
Textinput2: Room 300  //
Textinput3: Houston tx

For the user this is a correct format and he starts searching for what he needs. 对于用户来说,这是一种正确的格式,他开始搜索所需内容。 How do I use the select statement so that it returns the row that is available in the DB? 如何使用select语句,使其返回数据库中可用的行?

I've tried similar to following ( Consider case insensitive for now ) but does not seem right at the performance point of view. 我尝试了类似于以下内容的操作( 现在考虑不区分大小写 ),但从性能角度来看似乎不正确。 Could some one point me to the right direction? 有人能指出我正确的方向吗?

select  * 
    from address addr 
    where addr.addr_ln1 like '%3330 Scott street%'
        and (
            addr.addr_ln2 like '%room 300%' 
            or addr.addr_ln2 like '%300%'
        )
        and addr.addr_ln3 like '%houston tx%'

The oft neglected Oracle SOUNDEX function might be worth a try for "fuzzy"(ish) matching. 经常被忽略的Oracle SOUNDEX函数可能值得尝试进行“模糊”匹配。 I have used Oracle Text/InterMedia (CTXSYS), to enable searching PDF/DOC files stored in BLOBs. 我使用了Oracle Text / InterMedia(CTXSYS)来搜索存储在BLOB中的PDF / DOC文件。 So again, there might be scope there, whereby you hold a column CLOB which is all the text concatenated (trigger maintained?), then index this via CTXSYS, then you'll be able to use the CONTAINS command in the WHERE clause. 再次,这里可能存在作用域,即您拥有一列CLOB,该行将所有文本串联起来(触发了吗?),然后通过CTXSYS对其进行索引,然后您就可以在WHERE子句中使用CONTAINS命令。 See the link below to help get you started: 请参阅下面的链接以帮助您入门:

http://docs.oracle.com/cd/B28359_01/text.111/b28303/quicktour.htm#i1008390 http://docs.oracle.com/cd/B28359_01/text.111/b28303/quicktour.htm#i1008390

Warning though, since the search relies on the index being up to date, we found the only reliable way to ensure it was was to run the ctxsys.ctx_ddl.sync_index when the document was uploaded as part of the transaction. 但是警告,由于搜索依赖于最新的索引,因此,我们发现确保索引唯一可靠的方法是在文档作为事务的一部分上载时运行ctxsys.ctx_ddl.sync_index。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM