2017-01-22 27 views
1

我想使用Levenshtein和Im寻找一些例子。 我已阅读文档,但我不知道如何实现它。 我试图建立自己的分析仪,但每次使用它都会崩溃。crate.io FULLTEXT SEARCH模糊

这里是我follwed文档: https://crate.io/docs/reference/sql/fulltext.html

示例表:

CREATE TABLE IF NOT EXISTS "test"."accounts" (
    "customer_name" STRING INDEX USING FULLTEXT WITH (
     analyzer = 'standard' 
    ), 
"customer_no" STRING, 
    PRIMARY KEY ("customer_no") 
) 


INSERT INTO "test"."accounts" 
(customer_name, customer_no) 
VALUES('Walmart','C00001'); 

我的目标是寻找沃尔玛和沃尔玛回报。

回答

2

您在本示例中使用的标准分析器会将搜索词'wal-mart'(由于连字符)拆分为两个令牌 - 'wal'和'mart'。因为这可能不是你想要的所描述的使用情况下,我会建议添加自定义的分析,如:

create ANALYZER lowercase_keyword (
    TOKENIZER keyword, 
    TOKEN_FILTERS (
     lowercase 
    ) 
); 

这将索引字,因为它是 - 除了把它变成小写。

然后创建一个表与新创建的分析仪,并添加一些数据:

CREATE TABLE IF NOT EXISTS "test"."accounts" (
    "customer_name" STRING INDEX USING FULLTEXT WITH (
     analyzer = 'lowercase_keyword' 
    ), 
"customer_no" STRING, 
    PRIMARY KEY ("customer_no") 
); 

INSERT INTO "test"."accounts" (customer_name, customer_no) VALUES ('Walmart', 'C00001'), ('Wal-mart', 'C00002'), ('wal-mart', 'C00003'), ('wal- mart’, ’C00004'); 

现在下面的回报“沃尔玛”,“沃尔玛”和“沃尔玛”给出的查询:

select customer_name from test.accounts where match(customer_name, 'walmart') using best_fields with (fuzziness=1); 

如果模糊度为2,查询将会返回'沃尔玛'。