Have a lot of unnecessary results using contains() method in my query. Don't tell me to use like or something else. It is hardcoded and couldn't be changed.
Asked
Active
Viewed 1.1e+01k times
19
-
can i pass any params into contains to narrow search results to exact result – Artsiom Anisimau Mar 12 '10 at 07:25
-
Select * from blabla where contains(dFullText, "car") – Artsiom Anisimau Mar 12 '10 at 07:40
2 Answers
23
Contains is used on text fields that have a 'CONTEXT Index', which indexes a text field for searching. The standard usage is like this (using the score
operator to display what is returned from the contains
clause based on the 1 in contains
matching the 1 in score
):
SELECT score(1), value
FROM table_name
WHERE CONTAINS(textField, 'searchString', 1) > 0;
For data like this in table table_name
value | textField
-------|-----------------------------------------------
A | 'Here is searchString. searchString again.'
B | 'Another string'
C | 'Just one searchString'
That query would return
2 A
1 C
So contains is similiar to like, but will count how many times a string occurs in a text field. I couldn't find a resource using Contains the way it is used in the query you posted, but I think that would return rows where dFullText
has at least one instance of car
in it, or the equivalent of this sql:
Select * from blabla where dFullText like "%car%"
Here is another source.

rosscj2533
- 9,195
- 7
- 39
- 56
-
-
2@Rene, yes they are different. `Contains()` counts how many times a string occurs in a text field and would return that number. `instr()` searches for a string in a field (or other string) and returns the index of the first search string found (or 0 if it's not found). See examples of `instr()` at http://www.techonthenet.com/oracle/functions/instr.php – rosscj2533 Mar 22 '10 at 17:22
1
See this example from oracle.com
declare
rowno number := 0;
begin
for c1 in (SELECT SCORE(1) score, title FROM news
WHERE CONTAINS(text, 'oracle', 1) > 0
ORDER BY SCORE(1) DESC)
loop
rowno := rowno + 1;
dbms_output.put_line(c1.title||': '||c1.score);
exit when rowno = 10;
end loop;
end;

Padmarag
- 7,067
- 1
- 25
- 29