使用特定字母在完整搜索列中搜索
Search inside full search column using certain letters
我想使用特定字母在完整搜索栏中进行搜索,我的意思是:
select "Name","Country","_score" from datatable where match("Country", 'China');
Returns 很多行,没问题。我的问题是,如何搜索例如:
select "Name","Country","_score" from datatable where match("Country", 'Ch');
我想看看,中国,智利等等
我认为 match_type phrase_prefix 可以作为答案,但我不知道如何使用(正确的语法)。
如果您只需要匹配字符串列的开头,则不需要全文分析列。您可以改用 LIKE operator,例如:
cr> create table names_table (name string, country string);
CREATE OK (0.840 sec)
cr> insert into names_table (name, country) values ('foo', 'China'), ('bar','Chile'), ('foobar', 'Austria');
INSERT OK, 3 rows affected (0.049 sec)
cr> select * from names_table where country like 'Ch%';
+---------+------+
| country | name |
+---------+------+
| Chile | bar |
| China | foo |
+---------+------+
SELECT 2 rows in set (0.037 sec)
匹配谓词支持不同类型using match_type [with (match_parameter = [value])]
.
因此在您的示例中使用 phrase_prefix
匹配类型:
select "Name","Country","_score" from datatable where match("Country", 'Ch') using phrase_prefix;
给你想要的结果。
请参阅 match predicate
文档:https://crate.io/docs/en/latest/sql/fulltext.html?#match-predicate
我想使用特定字母在完整搜索栏中进行搜索,我的意思是:
select "Name","Country","_score" from datatable where match("Country", 'China');
Returns 很多行,没问题。我的问题是,如何搜索例如:
select "Name","Country","_score" from datatable where match("Country", 'Ch');
我想看看,中国,智利等等
我认为 match_type phrase_prefix 可以作为答案,但我不知道如何使用(正确的语法)。
如果您只需要匹配字符串列的开头,则不需要全文分析列。您可以改用 LIKE operator,例如:
cr> create table names_table (name string, country string);
CREATE OK (0.840 sec)
cr> insert into names_table (name, country) values ('foo', 'China'), ('bar','Chile'), ('foobar', 'Austria');
INSERT OK, 3 rows affected (0.049 sec)
cr> select * from names_table where country like 'Ch%';
+---------+------+
| country | name |
+---------+------+
| Chile | bar |
| China | foo |
+---------+------+
SELECT 2 rows in set (0.037 sec)
匹配谓词支持不同类型using match_type [with (match_parameter = [value])]
.
因此在您的示例中使用 phrase_prefix
匹配类型:
select "Name","Country","_score" from datatable where match("Country", 'Ch') using phrase_prefix;
给你想要的结果。
请参阅 match predicate
文档:https://crate.io/docs/en/latest/sql/fulltext.html?#match-predicate