在网上找了一些资料,做了些测试。对应多个字段的oracle全文检索有些疑问。
exec ctx_ddl.create_preference ('my_lexer', 'chinese_vgram_lexer');
exec ctx_ddl.create_preference('result_datastore', 'MULTI_COLUMN_DATASTORE');
exec ctx_ddl.set_attribute('result_datastore', 'columns', 'investigationplace,protector');
这是我做的测试,investigationplace,protector 是某个表的2个字段
创建索引:
CREATE INDEX ctx_idx_subject ON scene_investigation_lw(investigationplace) INDEXTYPE IS ctxsys.CONTEXT PARAMETERS('DATASTORE ctxsys.result_datastore lexer my_lexer')
查询:
select * from scene_investigation_lw where contains(investigationplace,'中国')>0
目前的查询结果是or,基本相当于
select * from scene_investigation_lw where investigationplace like '%中国%' or protector like '%中国%'
首先想确认下是不是这样?因为查出来的记录数不一样,貌似用like的多了几十条
另外怎么能变成 and 就是 investigationplace like '%中国%' and protector like '%中国%'
难道要在2个字段分别做索引吗???
------解决方法--------------------------------------------------------
问:我有一张表记录着雇员的名称和住址,我想在这两列中查找某个单词是否存在这两个列之一。
答:方法1,在雇员名称和住址上建立两个ConText索引。查询:
SELECT *
FROM emp
WHERE contains (ename, 'biti') > 0
OR contains (address, 'biti') > 0;
方法2, 定制
n Only CTXSYS is allowed to create preferences for the MULTI_COLUMN_DATASTORE type. Any other user who attempts to create a MULTI_COLUMN_DATASTORE preference receives an error.so it run on ctxsys schema
CREATE TABLE mc(id NUMBER PRIMARY KEY, NAME VARCHAR2(10), address VARCHAR2(80))
/
INSERT INTO mc
VALUES (1, 'John Smith', '123 Main Street biti');
EXEC ctx_ddl.create_preference('mymds', 'MULTI_COLUMN_DATASTORE');
EXEC ctx_ddl.set_attibute('mymds', 'columns', 'name, address');
CREATE INDEX mc_idx ON mc(NAME) INDEXTYPE IS ctxsys.CONTEXT PARAMETERS('datastore mymds')
/
SELECT *
FROM mc
WHERE contains (name, 'biti') > 0;