通配符搜索是一种常见的文本搜索类型。在 Manticore 中,它是在字典级别进行的。默认情况下,普通表和 RT 表都使用一种名为 [dict] 的字典类型(参见 ../../Creating_a_table/NLP_and_tokenization/Low-level_tokenization.md#dict)。在这种模式下,单词以原样存储,因此启用通配符不会影响表的大小。当执行通配符搜索时,会在字典中查找所有可能扩展的通配符单词。这种扩展在查询时可能会导致计算问题,尤其是当扩展的单词提供许多扩展或具有巨大的命中列表时,特别是在通配符添加到单词开头和结尾的情况下。为了避免这些问题,可以使用 [expansion_limit](参见 ../../Server_settings/Searchd.md#expansion_limit)。
min_prefix_len = length
此设置确定要索引和搜索的最小单词前缀长度。默认情况下,它设置为 0,这意味着不允许前缀。
前缀允许通过 wordstart* 通配符进行通配符搜索。
例如,如果单词 "example" 使用 min_prefix_len=3 索引,则可以通过搜索 "exa"、"exam"、"examp" 和 "exampl" 以及完整的单词来找到它。
请注意,在 [dict]=crc 模式下,min_prefix_len 将会影响全文索引的大小,因为每个单词扩展都会额外存储。
Manticore 可以区分完美匹配的单词和前缀匹配,并在满足以下条件时将前者排名更高:
- [dict]=keywords(默认开启)
- [index_exact_words]=1(默认关闭)
- [expand_keywords]=1(也默认关闭)
请注意,如果使用 [dict]=crc 模式或上述任一选项禁用,则无法区分前缀和完整单词,也无法将完美匹配的单词排名更高。
当设置了 最小后缀长度 为正数时,最小前缀长度始终被视为 1。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) min_prefix_len = '3'POST /cli -d "
CREATE TABLE products(title text, price float) min_prefix_len = '3'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'min_prefix_len' => '3'
]);utilsApi.sql('CREATE TABLE products(title text, price float) min_prefix_len = \'3\'')await utilsApi.sql('CREATE TABLE products(title text, price float) min_prefix_len = \'3\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) min_prefix_len = \'3\'');utilsApi.sql("CREATE TABLE products(title text, price float) min_prefix_len = '3'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) min_prefix_len = '3'", true);utils_api.sql("CREATE TABLE products(title text, price float) min_prefix_len = '3'", Some(true)).await;table products {
min_prefix_len = 3
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}min_infix_len = length
min_infix_len 设置确定要索引和搜索的最小后缀前缀长度。它是可选的,默认值为 0,这意味着不允许后缀。最小允许的非零值为 2。
启用后,后缀允许使用如 start*、*end、*middle* 等术语模式进行通配符搜索。它还允许您禁用太短且搜索成本过高的通配符。
如果满足以下条件,Manticore 可以区分完美匹配的单词和后缀匹配,并将前者排名更高:
- [dict]=keywords(默认开启)
- [index_exact_words]=1(默认关闭)
- [expand_keywords]=1(也默认关闭)
请注意,如果使用 [dict]=crc 模式或上述任一选项禁用,则无法区分后缀和完整单词,因此无法将完美匹配的单词排名更高。
后缀通配符搜索的查询时间可能会有很大差异,这取决于子字符串实际扩展成多少关键词。像 *in* 或 *ti* 这样的短而频繁的音节可能会扩展成太多关键词,所有这些都需要匹配和处理。因此,为了启用子字符串搜索,通常会将 min_infix_len 设置为 2。为了限制来自太短通配符的搜索的影响,可能会将其设置得更高。
后缀必须至少为两个字符长,出于性能原因,*a* 类似的通配符是不允许的。
当 min_infix_len 设置为正数时,最小前缀长度 被视为 1。对于 [dict] 字段,前后缀不能同时启用。如果要在 [dict] 和其他字段中声明前缀字段 [prefix_fields],则禁止在同一列表中声明相同的字段。
如果 dict=keywords,除了通配符 * 外,还可以使用另外两个通配符字符:
?可匹配任何(一个)字符:t?st将匹配test,但不匹配teast%可匹配零个或一个字符:tes%将匹配tes或test,但不匹配testing
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) min_infix_len = '3'POST /cli -d "
CREATE TABLE products(title text, price float) min_infix_len = '3'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'min_infix_len' => '3'
]);utilsApi.sql('CREATE TABLE products(title text, price float) min_infix_len = \'3\'')await utilsApi.sql('CREATE TABLE products(title text, price float) min_infix_len = \'3\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) min_infix_len = \'3\'');utilsApi.sql("CREATE TABLE products(title text, price float) min_infix_len = '3'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) min_infix_len = '3'", true);utils_api.sql("CREATE TABLE products(title text, price float) min_infix_len = '3'", Some(true)).await;table products {
min_infix_len = 3
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}prefix_fields = field1[, field2, ...]
prefix_fields 设置用于在 dict=crc 模式下限制前缀索引到特定的全文字段。默认情况下,所有字段都在前缀模式下进行索引,但因为前缀索引可能会影响索引和搜索性能,所以可能需要将其限制在某些字段上。
要将前缀索引限制到特定字段,请使用 prefix_fields 设置,后跟逗号分隔的字段名列表。如果未设置 prefix_fields,则所有字段将在前缀模式下进行索引。
- CONFIG
table products {
prefix_fields = title, name
min_prefix_len = 3
dict = crcinfix_fields = field1[, field2, ...]
infix_fields 设置允许您指定一个列表的全文字段,以限制中缀索引。此设置仅适用于 dict=crc,是可选的,默认情况下所有字段都在中缀模式下进行索引。 此设置类似于 prefix_fields,但它允许您将中缀索引限制到特定字段。
- CONFIG
table products {
infix_fields = title, name
min_infix_len = 3
dict = crcmax_substring_len = length
max_substring_len 指令设置了前缀或中缀搜索时要索引的最大子字符串长度。此设置是可选的,默认值为 0(即索引所有可能的子字符串)。它仅适用于 dict。
默认情况下,在 dict 中,子字符串索引会将所有可能的子字符串作为单独的关键字进行索引,这可能会导致一个过于庞大的全文索引。因此,max_substring_len 指令允许跳过那些几乎永远不会被搜索的太长的子字符串。
例如,一个包含 10,000 篇博客文章的测试表在不同设置下的磁盘空间使用量如下:
- 基线:6.4 MB(没有子字符串)
- min_prefix_len = 3:24.3 MB(3.8 倍)
- min_prefix_len = 3,max_substring_len = 8:22.2 MB(3.5 倍)
- min_prefix_len = 3,max_substring_len = 6:19.3 MB(3.0 倍)
- min_infix_len = 3:94.3 MB(14.7 倍)
- min_infix_len = 3,max_substring_len = 8:84.6 MB(13.2 倍)
- min_infix_len = 3,max_substring_len = 6:70.7 MB(11.0 倍)
因此,限制最大子字符串长度可以节省 10-15% 的表大小。
在使用 dict=keywords 模式时,子字符串长度不会影响性能。因此,此指令在此情况下是不适用的,并且有意禁止。然而,如果需要,你仍然可以在应用程序代码中限制你要搜索的子字符串的长度。
- CONFIG
table products {
max_substring_len = 12
min_infix_len = 3
dict = crcexpand_keywords = {0|1|exact|star}
此设置扩展关键字及其精确形式和/或星号。支持的值包括:
- 1 - 扩展为精确形式和带有星号的形式。例如,
running将变为(running | *running* | =running) exact- 仅增加关键字的精确形式。例如,running将变为(running | =running)star- 通过在其周围添加星号来增加关键字。例如,running将变为(running | *running*)此设置是可选的,默认值为 0(关键字不扩展)。
启用 expand_keywords 特性的表中的查询内部会进行扩展:如果表是在前缀或中缀索引启用的情况下构建的,每个关键字都会被替换为其自身和相应的前缀或中缀(带星号)的析取。如果表是在启用了词干提取和 index_exact_words 的情况下构建的,精确形式也会被添加。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) expand_keywords = '1'POST /cli -d "
CREATE TABLE products(title text, price float) expand_keywords = '1'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'expand_keywords' => '1'
]);utilsApi.sql('CREATE TABLE products(title text, price float) expand_keywords = \'1\'')await utilsApi.sql('CREATE TABLE products(title text, price float) expand_keywords = \'1\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) expand_keywords = \'1\'');utilsApi.sql("CREATE TABLE products(title text, price float) expand_keywords = '1'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) expand_keywords = '1'", true);utils_api.sql("CREATE TABLE products(title text, price float) expand_keywords = '1'", Some(true)).await;table products {
expand_keywords = 1
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}扩展查询自然会花费更长时间完成,但可能会提高搜索质量,因为具有精确形式匹配的文档通常应该比具有词干或中缀匹配的文档排名更高。
请注意,现有的查询语法无法模拟这种扩展,因为内部扩展工作在关键字级别,并且会在短语或群集操作符内扩展关键字(这通过查询语法是不可能实现的)。请参阅示例以及 expand_keywords 如何影响搜索结果权重,以及如何通过不需要添加星号的方式找到“runsy”:
- expand_keywords_enabled
- expand_keywords_disabled
mysql> create table t(f text) min_infix_len='2' expand_keywords='1' morphology='stem_en';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> insert into t values(1,'running'),(2,'runs'),(3,'runsy');
Query OK, 3 rows affected (0.00 sec)
mysql> select *, weight() from t where match('runs');
+------+---------+----------+
| id | f | weight() |
+------+---------+----------+
| 2 | runs | 1560 |
| 1 | running | 1500 |
| 3 | runsy | 1500 |
+------+---------+----------+
3 rows in set (0.01 sec)
mysql> drop table t;
Query OK, 0 rows affected (0.01 sec)
mysql> create table t(f text) min_infix_len='2' expand_keywords='exact' morphology='stem_en';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> insert into t values(1,'running'),(2,'runs'),(3,'runsy');
Query OK, 3 rows affected (0.00 sec)
mysql> select *, weight() from t where match('running');
+------+---------+----------+
| id | f | weight() |
+------+---------+----------+
| 1 | running | 1590 |
| 2 | runs | 1500 |
+------+---------+----------+
2 rows in set (0.00 sec)mysql> create table t(f text) min_infix_len='2' morphology='stem_en';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> insert into t values(1,'running'),(2,'runs'),(3,'runsy');
Query OK, 3 rows affected (0.00 sec)
mysql> select *, weight() from t where match('runs');
+------+---------+----------+
| id | f | weight() |
+------+---------+----------+
| 1 | running | 1500 |
| 2 | runs | 1500 |
+------+---------+----------+
2 rows in set (0.00 sec)
mysql> drop table t;
Query OK, 0 rows affected (0.01 sec)
mysql> create table t(f text) min_infix_len='2' morphology='stem_en';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> insert into t values(1,'running'),(2,'runs'),(3,'runsy');
Query OK, 3 rows affected (0.00 sec)
mysql> select *, weight() from t where match('running');
+------+---------+----------+
| id | f | weight() |
+------+---------+----------+
| 1 | running | 1500 |
| 2 | runs | 1500 |
+------+---------+----------+
2 rows in set (0.00 sec)expansion_limit = number
单个通配符展开的最大关键词数。详情见 这里。
停用词是在索引和搜索过程中被忽略的词语,通常是因为它们的频率高且对搜索结果的贡献较低。
Manticore Search 默认会对停用词应用 stemming,这可能导致不理想的结果,但可以使用 stopwords_unstemmed 来关闭此功能。
小型停用词文件存储在表头中,嵌入文件的大小有限制,由 embedded_limit 选项定义。
停用词不会被索引,但会影响关键词的位置。例如,如果 "the" 是一个停用词,文档 1 包含短语 "in office",而文档 2 包含短语 "in the office",搜索 "in office" 作为精确短语时,只会返回第一个文档,即使第二个文档中的 "the" 被跳过作为停用词。此行为可以通过 stopword_step 指令进行修改。
stopwords=path/to/stopwords/file[ path/to/another/file ...]
stopwords 设置是可选的,默认为空。它允许您指定一个或多个停用词文件的路径,用空格分隔。所有文件都将被加载。在实时模式下,仅允许使用绝对路径。
停用词文件格式是简单的纯文本,使用 UTF-8 编码。文件数据将根据 charset_table 设置进行分词,因此您可以使用与索引数据相同的分隔符。
当 ngram_len 索引处于活动状态时,由 ngram_chars 中字符组成的停用词本身会被分词为 N-gram。因此,每个单独的 N-gram 都会成为单独的停用词。例如,使用 ngram_len=1 和合适的 ngram_chars,停用词 test 将被解释为 t、e、s、t 四个不同的停用词。
停用词文件可以手动或半自动创建。indexer 提供了一种模式,可以创建表的频率字典,按关键词频率排序。该字典中的顶级关键词通常可以用作停用词。有关详细信息,请参阅 --buildstops 和 --buildfreqs 开关。该字典中的顶级关键词通常可以用作停用词。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) stopwords = '/usr/local/manticore/data/stopwords.txt /usr/local/manticore/data/stopwords-ru.txt /usr/local/manticore/data/stopwords-en.txt'POST /cli -d "
CREATE TABLE products(title text, price float) stopwords = '/usr/local/manticore/data/stopwords.txt stopwords-ru.txt stopwords-en.txt'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'stopwords' => '/usr/local/manticore/data/stopwords.txt stopwords-ru.txt stopwords-en.txt'
]);utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'/usr/local/manticore/data/stopwords.txt /usr/local/manticore/data/stopwords-ru.txt /usr/local/manticore/data/stopwords-en.txt\'')await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'/usr/local/manticore/data/stopwords.txt /usr/local/manticore/data/stopwords-ru.txt /usr/local/manticore/data/stopwords-en.txt\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'/usr/local/manticore/data/stopwords.txt /usr/local/manticore/data/stopwords-ru.txt /usr/local/manticore/data/stopwords-en.txt\'');utilsApi.sql("CREATE TABLE products(title text, price float) stopwords = '/usr/local/manticore/data/stopwords.txt /usr/local/manticore/data/stopwords-ru.txt /usr/local/manticore/data/stopwords-en.txt'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) stopwords = '/usr/local/manticore/data/stopwords.txt /usr/local/manticore/data/stopwords-ru.txt /usr/local/manticore/data/stopwords-en.txt'", true);utils_api.sql("CREATE TABLE products(title text, price float) stopwords = '/usr/local/manticore/data/stopwords.txt /usr/local/manticore/data/stopwords-ru.txt /usr/local/manticore/data/stopwords-en.txt'", Some(true)).await;table products {
stopwords = /usr/local/manticore/data/stopwords.txt
stopwords = stopwords-ru.txt stopwords-en.txt
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}或者,您可以使用 Manticore 自带的默认停用词文件。目前有 50 种语言的停用词可用。以下是它们的完整别名列表:
- af - 阿非利卡语
- ar - 阿拉伯语
- bg - 保加利亚语
- bn - 孟加拉语
- ca - 加泰罗尼亚语
- ckb- 库尔德语
- cz - 捷克语
- da - 丹麦语
- de - 德语
- el - 希腊语
- en - 英语
- eo - 世界语
- es - 西班牙语
- et - 爱沙尼亚语
- eu - 巴斯克语
- fa - 波斯语
- fi - 芬兰语
- fr - 法语
- ga - 爱尔兰语
- gl - 加利西亚语
- hi - 印地语
- he - 希伯来语
- hr - 克罗地亚语
- hu - 匈牙利语
- hy - 亚美尼亚语
- id - 印度尼西亚语
- it - 意大利语
- ja - 日语
- ko - 韩语
- la - 拉丁语
- lt - 立陶宛语
- lv - 拉脱维亚语
- mr - 马拉地语
- nl - 荷兰语
- no - 挪威语
- pl - 波兰语
- pt - 葡萄牙语
- ro - 罗马尼亚语
- ru - 俄语
- sk - 斯洛伐克语
- sl - 斯洛文尼亚语
- so - 索马里语
- st - 索托语
- sv - 瑞典语
- sw - 斯瓦希里语
- th - 泰语
- tr - 土耳其语
- yo - 约鲁巴语
- zh - 中文
- zu - 祖鲁语
例如,要在配置文件中使用意大利语的停用词,请添加以下行:
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) stopwords = 'it'POST /cli -d "
CREATE TABLE products(title text, price float) stopwords = 'it'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'stopwords' => 'it'
]);utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'it\'')await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'it\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'it\'');utilsApi.sql("CREATE TABLE products(title text, price float) stopwords = 'it'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) stopwords = 'it'", true);utils_api.sql("CREATE TABLE products(title text, price float) stopwords = 'it'", Some(true)).await;table products {
stopwords = it
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}如果需要使用多种语言的停用词,应列出所有别名,用逗号(RT 模式)或空格(plain 模式)分隔:
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) stopwords = 'en, it, ru'POST /cli -d "
CREATE TABLE products(title text, price float) stopwords = 'en, it, ru'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'stopwords' => 'en, it, ru'
]);utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en, it, ru\'')await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en, it, ru\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en, it, ru\'');utilsApi.sql("CREATE TABLE products(title text, price float) stopwords = 'en, it, ru'", true);utilsApi.sql("CREATE TABLE products(title text, price float) stopwords = 'en, it, ru'", true);utils_api.sql("CREATE TABLE products(title text, price float) stopwords = 'en, it, ru'", Some(true)).await;table products {
stopwords = en it ru
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}stopwords_list = 'value1; value2; ...'
设置 stopwords_list 允许您直接在 CREATE TABLE 语句中指定停用词。它仅支持在 RT 模式 中。
值必须用分号(;)分隔。如果需要使用分号作为字面字符,必须用反斜杠(\;)转义。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
CREATE TABLE products(title text, price float) stopwords_list = 'a; the'POST /cli -d "
CREATE TABLE products(title text, price float) stopwords_list = 'a; the'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'stopwords_list' => 'a; the'
]);utilsApi.sql('CREATE TABLE products(title text, price float) stopwords_list = \'a; the\'')await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords_list = \'a; the\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords_list = \'a; the\'');utilsApi.sql("CREATE TABLE products(title text, price float) stopwords_list = 'a; the'", true);utilsApi.sql("CREATE TABLE products(title text, price float) stopwords_list = 'a; the'", true);utils_api.sql("CREATE TABLE products(title text, price float) stopwords_list = 'a; the'", Some(true)).await;stopword_step={0|1}
在 停用词 上的 position_increment 设置是可选的,允许的值为 0 和 1,默认值为 1。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) stopwords = 'en' stopword_step = '1'POST /cli -d "
CREATE TABLE products(title text, price float) stopwords = 'en' stopword_step = '1'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'stopwords' => 'en, it, ru',
'stopword_step' => '1'
]);utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en\' stopword_step = \'1\'')await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en\' stopword_step = \'1\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en\' stopword_step = \'1\'');utilsApi.sql("CREATE TABLE products(title text, price float) stopwords = \'en\' stopword_step = \'1\'", true);utilsApi.sql("CREATE TABLE products(title text, price float) stopwords = \'en\' stopword_step = \'1\'", true);utils_api.sql("CREATE TABLE products(title text, price float) stopwords = \'en\' stopword_step = \'1\'", Some(true)).await;table products {
stopwords = en
stopword_step = 1
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}stopwords_unstemmed={0|1}
在词干提取之前或之后应用停用词。可选,默认值为 0(在词干提取之后应用停用词过滤器)。
默认情况下,停用词本身会被词干提取,然后应用于词干提取(或任何其他形态处理)后的标记。这意味着当 stem(token) 等于 stem(stopword) 时,标记会被停止。这种默认行为可能导致意外结果,当标记被错误地词干提取为被停止的根时。例如,“Andes”可能会被词干提取为“and”,所以当“and”是停用词时,“Andes”也会被跳过。
但是,您可以通过启用 stopwords_unstemmed 指令来更改此行为。启用后,停用词会在词干提取之前应用(因此应用于原始词形),当标记等于停用词时,标记会被跳过。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) stopwords = 'en' stopwords_unstemmed = '1'POST /cli -d "
CREATE TABLE products(title text, price float) stopwords = 'en' stopwords_unstemmed = '1'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'stopwords' => 'en, it, ru',
'stopwords_unstemmed' => '1'
]);utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en\' stopwords_unstemmed = \'1\'')await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en\' stopwords_unstemmed = \'1\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en\' stopwords_unstemmed = \'1\'');utilsApi.sql("CREATE TABLE products(title text, price float) stopwords = \'en\' stopwords_unstemmed = \'1\'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) stopwords = \'en\' stopwords_unstemmed = \'1\'", true);utils_api.sql("CREATE TABLE products(title text, price float) stopwords = \'en\' stopwords_unstemmed = \'1\'", Some(true)).await;table products {
stopwords = en
stopwords_unstemmed = 1
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}词形转换是在通过 字符集表 规则对传入文本进行分词之后应用的。它们本质上允许你将一个词替换为另一个词。通常,这用于将不同的词形转换为一个标准形式(例如,将所有变体如 "walks"、"walked"、"walking" 转换为标准形式 "walk")。它也可以用于实现 词干提取 的例外情况,因为词干提取不会应用于在 forms 列表中找到的词。
wordforms = path/to/wordforms.txt
wordforms = path/to/alternateforms.txt
wordforms = path/to/dict*.txt
词形转换字典。可选,缺省为空。
词形转换字典在索引和搜索期间都用于规范化传入的词。因此,当涉及到 普通表 时,需要旋转表以获取词形转换文件中的更改。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) wordforms = '/var/lib/manticore/wordforms.txt' wordforms = '/var/lib/manticore/alternateforms.txt /var/lib/manticore/dict*.txt'POST /cli -d "
CREATE TABLE products(title text, price float) wordforms = '/var/lib/manticore/wordforms.txt' wordforms = '/var/lib/manticore/alternateforms.txt' wordforms = '/var/lib/manticore/dict*.txt'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'wordforms' => [
'/var/lib/manticore/wordforms.txt',
'/var/lib/manticore/alternateforms.txt',
'/var/lib/manticore/dict*.txt'
]
]);utilsApi.sql('CREATE TABLE products(title text, price float) wordforms = \'/var/lib/manticore/wordforms.txt\' wordforms = \'/var/lib/manticore/alternateforms.txt\' wordforms = \'/var/lib/manticore/dict*.txt\'')await utilsApi.sql('CREATE TABLE products(title text, price float) wordforms = \'/var/lib/manticore/wordforms.txt\' wordforms = \'/var/lib/manticore/alternateforms.txt\' wordforms = \'/var/lib/manticore/dict*.txt\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float)wordforms = \'/var/lib/manticore/wordforms.txt\' wordforms = \'/var/lib/manticore/alternateforms.txt\' wordforms = \'/var/lib/manticore/dict*.txt\'');utilsApi.sql("CREATE TABLE products(title text, price float) wordforms = '/var/lib/manticore/wordforms.txt' wordforms = '/var/lib/manticore/alternateforms.txt' wordforms = '/var/lib/manticore/dict*.txt'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) wordforms = '/var/lib/manticore/wordforms.txt' wordforms = '/var/lib/manticore/alternateforms.txt' wordforms = '/var/lib/manticore/dict*.txt'", true);utils_api.sql("CREATE TABLE products(title text, price float) wordforms = '/var/lib/manticore/wordforms.txt' wordforms = '/var/lib/manticore/alternateforms.txt' wordforms = '/var/lib/manticore/dict*.txt'", Some(true)).await;table products {
wordforms = /var/lib/manticore/wordforms.txt
wordforms = /var/lib/manticore/alternateforms.txt
wordforms = /var/lib/manticore/dict*.txt
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}Manticore 的词形转换支持旨在良好处理大型字典。它们对索引速度有中等影响;例如,一个包含 100 万个条目的字典会使全文索引变慢约 1.5 倍。搜索速度完全不受影响。额外的 RAM 影响大致等于字典文件的大小,并且字典在表之间共享。例如,如果为 10 个不同的表指定了相同的 50 MB 词形转换文件,额外的 searchd RAM 使用量将约为 50 MB。
字典文件应采用简单的纯文本格式。每一行应包含源词和目标词形式,使用 UTF-8 编码,并用“大于”符号分隔。加载文件时将应用来自 字符集表 的规则。因此,如果你不修改 charset_table,你的词形转换将不区分大小写,类似于你的其他全文索引数据。以下是文件内容的示例:
- Example
walks > walk
walked > walk
walking > walk有一个名为 Spelldump 的捆绑实用程序,可以帮助你创建 Manticore 可读的字典文件格式。该实用程序可以从 OpenOffice 捆绑的 ispell 或 MySpell 格式的源 .dict 和 .aff 字典文件中读取。
你可以将多个源词映射到一个目标词。该过程发生在标记上,而不是源文本上,因此忽略空格和标记的差异。
你可以使用 => 符号代替 >。还允许使用注释(以 # 开头)。最后,如果一行以波浪号(~)开头,词形转换将在形态学之后应用,而不是之前(注意在这种情况下仅支持单个源词和目标词)。
- Example
core 2 duo > c2d
e6600 > c2d
core 2duo => c2d # Some people write '2duo' together...
~run > walk # Along with stem_en morphology enabled replaces 'run', 'running', 'runs' (and any other words that stem to just 'run') to 'walk'如果你需要将 >、= 或 ~ 作为普通字符使用,可以通过在每个字符前加上反斜杠(\)来转义它们。> 和 = 应该以这种方式转义。以下是一个示例:
- Example
a\> > abc
\>b > bcd
c\=\> => cde
\=\>d => def
\=\>a \> f \> => foo
\~g => bar你可以指定多个目标形式:
- Example
s02e02 > season 2 episode 2
s3 e3 > season 3 episode 3你可以指定多个文件,而不仅仅是一个文件。可以使用通配符作为模式,所有匹配的文件将按简单升序处理:
在 RT 模式下,仅允许使用绝对路径。
如果使用多字节代码页且文件名包含非拉丁字符,结果顺序可能不是完全按字母顺序排列。如果在多个文件中找到相同的词形转换定义,后者将被使用并覆盖之前的定义。
- SQL
- Config
create table tbl1 ... wordforms='/tmp/wf*'
create table tbl2 ... wordforms='/tmp/wf, /tmp/wf2'wordforms=/tmp/wf
wordforms=/tmp/wf2
wordforms=/tmp/wf_new*wordforms_list = 'source-form > destination-form; ...'
wordforms_list 设置允许你在 CREATE TABLE 语句中直接指定词形转换。它仅在 RT 模式 中支持。
值必须用分号(;)分隔。由于词形转换可能包含 > 或 => 作为分隔符,以及可能的其他特殊字符,请确保如果分号是形式本身的一部分(例如 \;),则转义分号。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
CREATE TABLE products(title text, price float) wordforms_list = 'walks > walk; walked > walk'POST /cli -d "
CREATE TABLE products(title text, price float) wordforms_list = 'walks > walk; walked > walk'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'wordforms_list' => 'walks > walk; walked > walk'
]);utilsApi.sql('CREATE TABLE products(title text, price float) wordforms_list = \'walks > walk; walked > walk\'')await utilsApi.sql('CREATE TABLE products(title text, price float) wordforms_list = \'walks > walk; walked > walk\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) wordforms_list = \'walks > walk; walked > walk\'');utilsApi.sql("CREATE TABLE products(title text, price float) wordforms_list = 'walks > walk; walked > walk'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) wordforms_list = 'walks > walk; walked > walk'", true);utils_api.sql("CREATE TABLE products(title text, price float) wordforms_list = 'walks > walk; walked > walk'", Some(true)).await;异常(也称为同义词)允许将一个或多个标记(包括通常会被排除的字符的标记)映射到一个关键字。它们与 wordforms 类似,因为它们也执行映射,但有一些重要的区别。
与 wordforms 的差异简要总结如下:
| 异常 | 词形 |
|---|---|
| 区分大小写 | 不区分大小写 |
| 可以使用不在 charset_table 中的特殊字符 | 完全遵守 charset_table |
| 在大型词典中性能较差 | 设计用于处理数百万条目 |
exceptions = path/to/exceptions.txt
标记异常文件。可选,默认为空。 在 RT 模式下,仅允许使用绝对路径。
预期的文件格式是纯文本,每行一个异常。行格式如下:
source-form => destination-form
示例文件:
at & t => at&t
AT&T => AT&T
Standarten Fuehrer => standartenfuhrer
Standarten Fuhrer => standartenfuhrer
MS Windows => ms windows
Microsoft Windows => ms windows
C++ => cplusplus
c++ => cplusplus
C plus plus => cplusplus
\=\>abc\> => abc
此处的所有形式都是区分大小写的,不会被 charset_table 规则处理。因此,使用上面的示例异常文件,at&t 文本将被标记为两个关键字 at 和 t,因为是小写字母。另一方面,AT&T 将精确匹配并生成一个 AT&T 关键字。
如果需要将 > 或 = 作为普通字符使用,可以通过在每个字符前加上反斜杠 (\) 来转义它们。这两种字符都应以这种方式转义。
请注意目标形式的关键字:
- 总是被解释为一个单个词
- 既区分大小写又区分空格
在上面的示例中,ms windows 查询将不匹配包含 MS Windows 文本的文档。该查询将被解释为两个关键字的查询,ms 和 windows。MS Windows 的映射是一个单关键字 ms windows,中间有空格。另一方面,standartenfuhrer 将检索包含 Standarten Fuhrer 或 Standarten Fuehrer 内容的文档(完全像这样大写),或者关键字本身的任何大小写变体,例如 staNdarTenfUhreR。(它不会捕获 standarten fuhrer,因为大小写敏感,该文本不匹配任何列出的异常,并被索引为两个独立的关键字。)
源形式列表中的空格很重要,但其数量不重要。源形式列表中的任何数量的空格都将匹配索引文档或查询中的任何其他数量的空格。例如,AT & T 源形式将匹配 AT & T 文本,无论源形式部分和索引文本中的空格数量如何。因此,这种文本将被索引为一个特殊的关键字 AT&T,感谢示例中的第一个条目。
异常还允许捕获特殊字符(这些字符是通用 charset_table 规则的例外;因此得名)。假设通常你不希望将 + 视为有效字符,但仍希望能够搜索某些例外,例如 C++。上面的示例将做到这一点,完全独立于表中包含哪些字符以及不包含哪些字符。
当使用 plain table 时,需要旋转表以合并异常文件中的更改。在实时表的情况下,更改仅适用于新文档。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) exceptions = '/usr/local/manticore/data/exceptions.txt'POST /cli -d "
CREATE TABLE products(title text, price float) exceptions = '/usr/local/manticore/data/exceptions.txt'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'exceptions' => '/usr/local/manticore/data/exceptions.txt'
]);utilsApi.sql('CREATE TABLE products(title text, price float) exceptions = \'/usr/local/manticore/data/exceptions.txt\'')await utilsApi.sql('CREATE TABLE products(title text, price float) exceptions = \'/usr/local/manticore/data/exceptions.txt\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) exceptions = \'/usr/local/manticore/data/exceptions.txt\'');utilsApi.sql("CREATE TABLE products(title text, price float) exceptions = '/usr/local/manticore/data/exceptions.txt'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) exceptions = '/usr/local/manticore/data/exceptions.txt'", true);utils_api.sql("CREATE TABLE products(title text, price float) exceptions = '/usr/local/manticore/data/exceptions.txt'", Some(true)).await;table products {
exceptions = /usr/local/manticore/data/exceptions.txt
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}exceptions_list = 'source-form => destination-form; ...'
exceptions_list 设置允许您在 CREATE TABLE 语句中直接指定异常。它仅支持 RT 模式。
值必须用分号 (;) 分隔。由于异常可能包含 > 或 => 作为分隔符,并且可能包含其他特殊字符,请确保如果分号是形式本身的一部分(例如 \;),则转义分号。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
CREATE TABLE products(title text, price float) exceptions_list = 'at & t => at&t; MS Windows => ms windows'POST /cli -d "
CREATE TABLE products(title text, price float) exceptions_list = 'at & t => at&t; MS Windows => ms windows'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'exceptions_list' => 'at & t => at&t; MS Windows => ms windows'
]);utilsApi.sql('CREATE TABLE products(title text, price float) exceptions_list = \'at & t => at&t; MS Windows => ms windows\'')await utilsApi.sql('CREATE TABLE products(title text, price float) exceptions_list = \'at & t => at&t; MS Windows => ms windows\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) exceptions_list = \'at & t => at&t; MS Windows => ms windows\'');utilsApi.sql("CREATE TABLE products(title text, price float) exceptions_list = 'at & t => at&t; MS Windows => ms windows'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) exceptions_list = 'at & t => at&t; MS Windows => ms windows'", true);utils_api.sql("CREATE TABLE products(title text, price float) exceptions_list = 'at & t => at&t; MS Windows => ms windows'", Some(true)).await;