15.1. 基本介绍

目前lxdb采用分词+倒排表的方式实现全文检索,目前支持3中分词类型StandardAnalyzer,ik,Hanlp,w4,pinyin,s2t,t2s,ngram 适用于texttext数组数据类型
注:(pinyin:拼音分词 s2t:简->繁 t2s:繁->)
具体的分词效果访问如下地址验证http://x.x.x.x:1210/token

15.2. 建表与设置分词

CREATE FOREIGN TABLE fulltext(
hashstr text,
 txt1 text OPTIONS(token 'ik'), 
txt2 text OPTIONS(token 'Hanlp'),
txt3 text OPTIONS(token 'ngram23'),--从2~3
txt4 text OPTIONS(token 'w4')  
) SERVER lxdb options(store 'is');

15.3. 创建分片

select create_distributed_table('fulltext', 'hashstr','hash','default',2);

15.4. 插入数据

INSERT INTO fulltext(hashstr,txt1,txt2,txt3,txt4) VALUES 
('1111','中华人民共和国', '中华人民共和国', '中华人民共和国','a1b1c1');
INSERT INTO fulltext(hashstr,txt1,txt2,txt3,txt4) VALUES 
('1111','辽宁省沈阳市', '辽宁省沈阳市', '辽宁省沈阳市','a2b2c2');
INSERT INTO fulltext(hashstr,txt1,txt2,txt3,txt4) VALUES 
('1111','江苏省南京市', '江苏省南京市', '江苏省南京市','a3');

15.5. 执行查询

select * from fulltext  where txt1 like '人民'  limit 10;
select * from fulltext  where txt1 like '中华%人民'  limit 10;
select * from fulltext  where txt1 like '南京'  limit 10;
select * from  fulltext where txt4 like 'a2b2';

15.6. 基于词偏移量的like

常规like匹配,在分词的场景下是不能保证词与词之间的先后顺序的,我们可以通过store 'ip'这种设置,来保证检索到的词的先后顺序

  1. 使用限制
    1).目前只支持四元分词-w4

    2).只支持在like中使用,等值匹配依然是无顺序的
  1. 表例子(结合了后面的copy用法)
CREATE FOREIGN TABLE fulltext_ip(
hashstr text,
txt1 text OPTIONS(token 'ik'), 
txt2 text OPTIONS(token 'Hanlp'),
txt3 text OPTIONS(token 'StandardAnalyzer'),
txt4 text OPTIONS(token 'w4' **,store 'isp'**) ,
copyall_1 text OPTIONS(token 'w4' **,store 'isp'**)
) SERVER lxdb options(store 'is');
  1. 插入数据
INSERT INTO fulltext_ip(hashstr,txt1,txt2,txt3,txt4) VALUES ('1111','辽宁省沈阳市', '辽宁省沈阳市', '辽宁省沈阳市','aaaaaaabbbbbbbb');
INSERT INTO fulltext_ip(hashstr,txt1,txt2,txt3,txt4) VALUES 
('1111','辽宁省沈阳市', '辽宁省沈阳市', '辽宁省沈阳市','cccccccabdddddddd');
  1. 查询例子
select * from  fulltext_ip where txt4 like 'bbbb%aaaa';--进行先后顺序验证搜索不到结果
select * from  fulltext_ip where txt4 = 'bbbb*aaaa';--不进行顺序验证,能搜索到结果
select * from  fulltext_ip where txt4 like 'ccccdddd'; --cccc与dddd中间不能有其他词
select * from  fulltext_ip where txt4 = 'ccccdddd';--分词后cccc与dddd中间有其他词,等值不管
select * from  fulltext_ip where txt4 like 'ccccabdddd'; --完全连续的词语是可以检索的
Copyright © luxindb.com 2020 all right reserved修改时间: 2022-12-05 17:26:33

results matching ""

    No results matching ""