Expecting exact results when using contains clause in Oracle

风格不统一 提交于 2019-12-13 23:45:01

问题


I have a below contains clause query to get the best match queries. I have below two values in the table:

1. TRUSTS ACT 1973 and 
2. TRUST ACCOUNTS ACT 1973.

When I am searching using the below query with the string "TRUST ACT 1973", for this search the actual result comes as TRUST ACCOUNTS ACT 1973. But I am expecting the exact result as *TRUSTS ACT 1973*.

Query:

SELECT
    /*+first_rows(11) index(a fuzzy_leg_nm_idx)*/
    a.unique_legislation_id,
    a.legislation_name,
    a.jurisdiction,
    score(1) sc
  FROM AU_LEG_PARALLEL_FUZZY a  
    WHERE contains (legislation_name, 
    '<query> 
        <textquery lang="ENGLISH" grammar="CONTEXT"> '
         || '<progression>
                <seq>{TRUST} ACCUM {ACT} ACCUM {1973}</seq>
            </progression>
        </textquery>
        <score datatype="INTEGER" algorithm="COUNT"/>
     </query>', 1) > 0
ORDER BY score(1) DESC;

回答1:


Both records match the ACCUM query. Assuming that you used the default BASIC_LEXER with no word stemming TRUST ACCOUNTS ACT 1973 scores higher mostly because TRUST matches exactly to your query. If you change the query to {TRUSTS} ACCUM {ACT} ACCUM {1973} then TRUSTS ACT 1973 would get a higher score.

Depending on your requirements, you might want to consider a phrase search rather than ACCUM, e.g. CONTAINS(title, '{TRUSTS} {ACT} {1973}') > 0. In this case, the phrase has to match exactly to a record.



来源:https://stackoverflow.com/questions/41295922/expecting-exact-results-when-using-contains-clause-in-oracle

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