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;
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}
thenTRUSTS 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.