简体   繁体   中英

Oracle SQL fuzzy search for words in a varchar column

We have an Address table with a lot of columns.

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:

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?

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. I have used Oracle Text/InterMedia (CTXSYS), to enable searching PDF/DOC files stored in BLOBs. 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. See the link below to help get you started:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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