2017-12-20 4 views
0

は私がまさに「私の好きなもの」正確なフレーズの検索には、Oracle DBにCONTAINS句

SELECT TestColl.tID, TestMetavalues.* 
FROM TestColl, TestMetavalues 
WHERE TestColl.tID=TestMetavalues.tID 
AND ((CONTAINS(TestFullText,'(My favorite thing)') > 0)) ; 

しかし、上記のクエリを持っていた行が返されたフレーズと一致する行を返すことを期待以下のクエリを持っていますTestFullText

私はクエリが正確な「私の好きなもの」

を持っている行だけを表示したい - 唯一の「私の好きなもの」とも「お気に入り」を持っていた行

テーブルTestCollは、AA BLOB列を持っています

これを行うには?

私はこれらのソリューションを試みたが、運

Expecting exact results when using contains clause in Oracle

search criteria difference between Like vs Contains() in oracle

答えて

1

はこの試してみてくださいません:私は、クエリは正確を持つ行のみを表示したい

SELECT TestColl.tID, TestMetavalues.* 
FROM TestColl, TestMetavalues 
WHERE TestColl.tID=TestMetavalues.tID 
AND TestColl.TestFullText LIKE '%My favorite thing%' ; 
0

を「私のお気に入り」

それがそうなら、あなたは、実際には、そのためのシンプルな

SELECT TestColl.tID, TestMetavalues.* 
FROM TestColl, TestMetavalues 
WHERE TestColl.tID = TestMetavalues.tID 
    AND TestFullText = 'My favorite thing'; 

なぜあなたが使用するOracle Textのを望んでいませんか?

0

ドメインインデックスがそのように機能しません。私たちはソーステキストのキーワードを索引付けしているので、実際には「私のお気に入り」を格納することはありません。「私」と「お気に入り」と「物」などを格納します。

しかし、あなたはまだので、ドメイン索引は258個の候補行に私たちを降り、その後、追加のLIKEがに私たちを降り例えば

SQL> create table t (x varchar2(1000)); 

Table created. 

SQL> 
SQL> insert into t values ('These are my medium stuff'); 

1 row created. 

SQL> insert into t values ('These are stuff I hate'); 

1 row created. 

SQL> insert into t values ('These are other things'); 

1 row created. 

SQL> insert into t values ('These are semi FAVORITE things'); 

1 row created. 

SQL> insert into t select * from t; 

4 rows created. 

SQL> insert into t select * from t; 

8 rows created. 

SQL> insert into t select * from t; 

16 rows created. 

SQL> insert into t select * from t; 

32 rows created. 

SQL> insert into t select * from t; 

64 rows created. 

SQL> insert into t select * from t; 

128 rows created. 

SQL> insert into t select * from t; 

256 rows created. 

SQL> insert into t select * from t; 

512 rows created. 

SQL> -- 
SQL> -- our special rows 
SQL> -- 
SQL> insert into t values ('These are a few of My Favorite Things'); 

1 row created. 

SQL> insert into t values ('Some other of My Favorite Things'); 

1 row created. 

SQL> 
SQL> create index ix on t (x) 
    2 indextype is ctxsys.context; 

Index created. 

SQL> 
SQL> exec dbms_stats.gather_table_stats('','T') 

PL/SQL procedure successfully completed. 

SQL> 
SQL> set autotrace on explain 
SQL> select count(*) from t 
    2 where CONTAINS(x,'My Favorite Things') > 0; 

    COUNT(*) 
---------- 
     258 

1 row selected. 


Execution Plan 
---------------------------------------------------------- 
Plan hash value: 2114225437 

------------------------------------------------------------------------- 
| Id | Operation  | Name | Rows | Bytes | Cost (%CPU)| Time  | 
------------------------------------------------------------------------- 
| 0 | SELECT STATEMENT |  |  1 | 26 |  1 (0)| 00:00:01 | 
| 1 | SORT AGGREGATE |  |  1 | 26 |   |   | 
|* 2 | DOMAIN INDEX | IX | 130 | 3380 |  1 (0)| 00:00:01 | 
------------------------------------------------------------------------- 

Predicate Information (identified by operation id): 
--------------------------------------------------- 

    2 - access("CTXSYS"."CONTAINS"("X",'My Favorite Things')>0) 

SQL> 
SQL> select * from t 
    2 where CONTAINS(x,'My Favorite Things') > 0 
    3 and x like '%My Favorite Things%'; 

X 
---------------------------------------------------------------------------------------------------- 
These are a few of My Favorite Things 
Some other of My Favorite Things 

2 rows selected. 


Execution Plan 
---------------------------------------------------------- 
Plan hash value: 1339481741 

------------------------------------------------------------------------------------ 
| Id | Operation     | Name | Rows | Bytes | Cost (%CPU)| Time  | 
------------------------------------------------------------------------------------ 
| 0 | SELECT STATEMENT   |  |  6 | 156 |  3 (0)| 00:00:01 | 
|* 1 | TABLE ACCESS BY INDEX ROWID| T |  6 | 156 |  3 (0)| 00:00:01 | 
|* 2 | DOMAIN INDEX    | IX |  |  |  1 (0)| 00:00:01 | 
------------------------------------------------------------------------------------ 

Predicate Information (identified by operation id): 
--------------------------------------------------- 

    1 - filter("X" LIKE '%My Favorite Things%' AND "X" IS NOT NULL) 
    2 - access("CTXSYS"."CONTAINS"("X",'My Favorite Things')>0) 

SQL> 
SQL> 

、初期のフィルタリング機構としてインデックスを使用することによって利益を得ることができます私たちが望む2列。