停用词是在索引和搜索过程中被忽略的词语,通常是因为它们的频率高且对搜索结果的贡献较低。
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
- JSON
- Config
create table tbl1 ... wordforms='/tmp/wf*'
create table tbl2 ... wordforms='/tmp/wf, /tmp/wf2'POST /sql?mode=raw -d "create table tbl1 ... wordforms='/tmp/wf*'"
POST /sql?mode=raw -d "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;词形处理预处理器可以在索引过程中应用于单词,以规范化同一单词的不同形式并改进分词。例如,英语词干提取器可以将 "dogs" 和 "dog" 规范化为 "dog",从而使得这两个关键词的搜索结果相同。
Manticore 有四种内置的词形处理预处理器:
- 词形还原器:将单词还原为其词根或词形。例如,"running" 可以还原为 "run","octopi" 可以还原为 "octopus"。请注意,某些单词可能有多个对应的词根形式。例如,"dove" 可以是 "dive" 的过去式,也可以是名词“鸽子”的意思,如 "A white dove flew over the cuckoo's nest." 在这种情况下,词形还原器可以生成所有可能的词根形式。
- 词干提取器:通过删除或替换某些已知的后缀将单词还原为词干。生成的词干可能不是有效的单词。例如,Porter 英语词干提取器将 "running" 还原为 "run",将 "business" 还原为 "busi"(不是有效单词),并且不会还原 "octopi"。
- 语音算法:将单词替换为语音代码,即使单词不同但语音接近,这些代码也相同。
- 分词算法:将文本拆分为单词。目前仅适用于中文。
morphology = morphology1[, morphology2, ...]
morphology 指令指定应用于索引单词的词形处理预处理器列表。这是一个可选设置,默认情况下不应用任何预处理器。
Manticore 提供了以下内置的词形处理预处理器:
- 英语、俄语和德语的词形还原器
- 英语、俄语、阿拉伯语和捷克语的词干提取器
- SoundEx 和 MetaPhone 语音算法
- 中文分词算法
- 还有超过 15 种其他语言 的 Snowball(libstemmer)词干提取器也提供支持。
词形还原器需要使用 .pak 格式的词典文件,这些文件可以通过 manticore-language-packs 包安装或 从 Manticore 网站下载。在后一种情况下,词典需要放在 lemmatizer_base 指定的目录中。
此外,可以使用 lemmatizer_cache 设置通过使用更多 RAM 来加快词形还原速度,该设置会为未压缩的词典缓存分配更多内存。
中文分词可以使用 ICU 或 Jieba(需要 manticore-language-packs 包)。这两种库提供的分词精度比 n-gram 更高,但速度稍慢。charset_table 必须包含所有中文字符,这可以通过 cont、cjk 或 chinese 字符集实现。当设置 morphology=icu_chinese 或 morphology=jieba_chinese 时,文档首先会通过 ICU 或 Jieba 进行预处理。然后,分词器根据 charset_table 处理结果,最后应用 morphology 选项中的其他词形处理程序。只有包含中文的部分会传递给 ICU/Jieba 进行分词,而其他部分可以通过不同的方式修改,例如不同的词形处理或 charset_table。
内置的英语和俄语词干提取器比其 libstemmer 对应版本更快,但可能会产生略微不同的结果。
Soundex 实现与 MySQL 一致。Metaphone 实现基于 Double Metaphone 算法,并索引主代码。
要使用 morphology 选项,请指定一个或多个内置选项,包括:
- none:不进行任何词形处理
- lemmatize_ru - 应用俄语词形还原器并选择一个词根形式
- lemmatize_uk - 应用乌克兰语词形还原器并选择一个词根形式
- lemmatize_en - 应用英语词形还原器并选择一个词根形式
- lemmatize_de - 应用德语词形还原器并选择一个词根形式
- lemmatize_ru_all - 应用俄语词形还原器并索引所有可能的词根形式
- lemmatize_uk_all - 应用乌克兰语词形还原器并索引所有可能的词根形式
- lemmatize_en_all - 应用英语词形还原器并索引所有可能的词根形式
- lemmatize_de_all - 应用德语词形还原器并索引所有可能的词根形式
- stem_en - 应用 Porter 英语词干提取器
- stem_ru - 应用 Porter 俄语词干提取器
- stem_enru - 应用 Porter 英语和俄语词干提取器
- stem_cz - 应用捷克语词干提取器
- stem_ar - 应用阿拉伯语词干提取器
- soundex - 将关键词替换为其 SOUNDEX 代码
- metaphone - 将关键词替换为其 METAPHONE 代码
- icu_chinese - 使用 ICU 进行中文文本分词
- jieba_chinese - 使用 Jieba 进行中文文本分词(需要
manticore-language-packs包) - libstemmer_* 。有关详细信息,请参阅 支持的语言列表
可以指定多个词干提取器,用逗号分隔。它们将按照列出的顺序应用于传入的单词,一旦其中一个词干提取器修改了单词,处理就会停止。此外,当启用 wordforms 功能时,单词会首先在词形字典中查找。如果字典中有匹配项,将完全不应用词干提取器。wordforms 可用于实现词干提取的例外情况。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) morphology = 'stem_en, libstemmer_sv'POST /cli -d "CREATE TABLE products(title text, price float) morphology = 'stem_en, libstemmer_sv'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'morphology' => 'stem_en, libstemmer_sv'
]);utilsApi.sql('CREATE TABLE products(title text, price float) morphology = \'stem_en, libstemmer_sv\'')await utilsApi.sql('CREATE TABLE products(title text, price float) morphology = \'stem_en, libstemmer_sv\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) morphology = \'stem_en, libstemmer_sv\'');utilsApi.sql("CREATE TABLE products(title text, price float) morphology = 'stem_en, libstemmer_sv'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) morphology = 'stem_en, libstemmer_sv'", true);utils_api.sql("CREATE TABLE products(title text, price float) morphology = 'stem_en, libstemmer_sv'", Some(true)).await;table products {
morphology = stem_en, libstemmer_sv
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}morphology_skip_fields = field1[, field2, ...]
用于跳过形态学预处理的字段列表。可选,默认为空(对所有字段应用预处理器)。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, name text, price float) morphology_skip_fields = 'name' morphology = 'stem_en'POST /cli -d "
CREATE TABLE products(title text, name text, price float) morphology_skip_fields = 'name' morphology = 'stem_en'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'morphology_skip_fields' => 'name',
'morphology' => 'stem_en'
]);utilsApi.sql('CREATE TABLE products(title text, price float) morphology_skip_fields = \'name\' morphology = \'stem_en\'')await utilsApi.sql('CREATE TABLE products(title text, price float) morphology_skip_fields = \'name\' morphology = \'stem_en\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) morphology_skip_fields = \'name\' morphology = \'stem_en\'');utilsApi.sql("CREATE TABLE products(title text, price float) morphology_skip_fields = 'name' morphology = 'stem_en'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) morphology_skip_fields = 'name' morphology = 'stem_en'", true);utils_api.sql("CREATE TABLE products(title text, price float) morphology_skip_fields = 'name' morphology = 'stem_en'", Some(true)).await;table products {
morphology_skip_fields = name
morphology = stem_en
type = rt
path = tbl
rt_field = title
rt_field = name
rt_attr_uint = price
}min_stemming_len = length
启用词干提取的最小词长。可选,默认为 1(对所有词进行词干提取)。
词干提取器并不完美,有时可能会产生不理想的结果。例如,将 "gps" 关键词通过英语的 Porter 词干提取器处理后会得到 "gp",这显然不是预期的结果。min_stemming_len 功能允许您根据源词的长度来抑制词干提取,即避免对过短的词进行词干提取。长度小于指定阈值的关键词将不会被提取。请注意,长度正好等于指定值的关键词 将会 被提取。因此,为了避免对三字符关键词进行提取,应将值设为 4。如需更精细的控制,请参考 wordforms 功能。
- SQL
- JSON
- PHP
- Python
- Python-asycnio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) min_stemming_len = '4' morphology = 'stem_en'POST /cli -d "
CREATE TABLE products(title text, price float) min_stemming_len = '4' morphology = 'stem_en'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'min_stemming_len' => '4',
'morphology' => 'stem_en'
]);utilsApi.sql('CREATE TABLE products(title text, price float) min_stemming_len = \'4\' morphology = \'stem_en\'')await utilsApi.sql('CREATE TABLE products(title text, price float) min_stemming_len = \'4\' morphology = \'stem_en\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) min_stemming_len = \'4\' morphology = \'stem_en\'');utilsApi.sql("CREATE TABLE products(title text, price float) min_stemming_len = '4' morphology = 'stem_en'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) min_stemming_len = '4' morphology = 'stem_en'", true);utils_api.sql("CREATE TABLE products(title text, price float) min_stemming_len = '4' morphology = 'stem_en'", Some(true)).await;table products {
min_stemming_len = 4
morphology = stem_en
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}index_exact_words = {0|1}
此选项允许对原始关键词及其形态学修改后的版本进行索引。但是,通过 wordforms 和 exceptions 重新映射的原始关键词无法被索引。默认值为 0,表示此功能默认禁用。
此功能允许在查询语言中使用 精确形式操作符。启用此功能会增加全文索引的大小和索引时间,但不会影响搜索性能。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) index_exact_words = '1' morphology = 'stem_en'POST /cli -d "
CREATE TABLE products(title text, price float) index_exact_words = '1' morphology = 'stem_en'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'index_exact_words' => '1',
'morphology' => 'stem_en'
]);utilsApi.sql('CREATE TABLE products(title text, price float) index_exact_words = \'1\' morphology = \'stem_en\'')await utilsApi.sql('CREATE TABLE products(title text, price float) index_exact_words = \'1\' morphology = \'stem_en\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) index_exact_words = \'1\' morphology = \'stem_en\'');utilsApi.sql("CREATE TABLE products(title text, price float) index_exact_words = '1' morphology = 'stem_en'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) index_exact_words = '1' morphology = 'stem_en'", true);utils_api.sql("CREATE TABLE products(title text, price float) index_exact_words = '1' morphology = 'stem_en'", Some(true)).await;table products {
index_exact_words = 1
morphology = stem_en
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}jieba_hmm = {0|1}
启用或禁用 Jieba 分词工具中的 HMM(隐马尔可夫模型)。可选,默认为 1。
在 Jieba 中,HMM 选项指的是用于分词的算法。具体来说,它允许 Jieba 通过识别不在其词典中的未知词(尤其是未收录的词)来进行中文分词。
Jieba 主要使用基于词典的方法对已知词进行分词,但当启用 HMM 选项时,它会应用统计模型来识别不在其词典中的词或短语的可能分词边界。这对于分割新词、生僻词、人名和俚语特别有用。
总之,jieba_hmm 选项通过牺牲索引性能来提高分词准确性。它必须与 morphology = jieba_chinese 一起使用,参见 中文、日文和韩文(CJK)及泰语。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_hmm = '0'POST /cli -d "
CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_hmm = '0'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'morphology' => 'jieba_chinese',
'jieba_hmm'='1'
]);utilsApi.sql('CREATE TABLE products(title text, price float) morphology = \'jieba_chinese\' jieba_hmm = \'0\'')await utilsApi.sql('CREATE TABLE products(title text, price float) morphology = \'jieba_chinese\' jieba_hmm = \'0\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) morphology = \'jieba_chinese\' jieba_hmm = \'0\'');utilsApi.sql("CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_hmm = '0'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_hmm = '0'", true);utils_api.sql("CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_hmm = '0'", Some(true)).await;table products {
morphology = jieba_chinese
jieba_hmm = 0
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}jieba_mode = {accurate|full|search}
Jieba 分词模式。可选,默认为 accurate。
在精确模式下,Jieba 通过词典匹配将句子拆分为最精确的词语。此模式注重精确度,确保分词尽可能准确。
在完整模式下,Jieba 尝试将句子拆分为所有可能的词语组合,旨在包含所有潜在的词语。此模式注重召回率,即尽可能多地识别词语,即使其中一些词语重叠或使用频率较低。它会返回其词典中找到的所有词语。
在搜索模式下,Jieba 将文本拆分为完整的单词和更小的部分,通过提供重叠的单词片段,结合精确的分词和额外的细节。此模式在精确度和召回率之间取得平衡,适用于搜索引擎。
jieba_mode 应与 morphology = jieba_chinese 一起使用。请参见 中文、日文、韩文(CJK)和泰语。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_mode = 'full'POST /cli -d "
CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_mode = 'full'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'morphology' => 'jieba_chinese',
'jieba_mode'='full'
]);utilsApi.sql('CREATE TABLE products(title text, price float) morphology = \'jieba_chinese\' jieba_mode = \'full\'')await utilsApi.sql('CREATE TABLE products(title text, price float) morphology = \'jieba_chinese\' jieba_mode = \'full\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) morphology = \'jieba_chinese\' jieba_mode = \'full\'');utilsApi.sql("CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_mode = 'full'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_mode = 'full'", true);utils_api.sql("CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_mode = 'full'", Some(true)).await;table products {
morphology = jieba_chinese
jieba_mode = full
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}jieba_user_dict_path = path/to/stopwords/file
Jieba 用户字典的路径。可选。
Jieba 是一个中文文本分词库,使用字典文件来辅助分词。这些字典文件的格式如下:每行包含一个单词,分为三部分,用空格分隔 —— 单词本身、词频和词性(POS)标签。词频和词性标签是可选的,可以省略。字典文件必须使用 UTF-8 编码。
示例:
创新办 3 i
云计算 5
凱特琳 nz
台中
jieba_user_dict_path 应与 morphology = jieba_chinese 一起使用。更多详情请参见 中文、日文、韩文(CJK)和泰语。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_user_dict_path = '/usr/local/manticore/data/user-dict.txt'POST /cli -d "
CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_user_dict_path = '/usr/local/manticore/data/user-dict.txt'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'morphology' => 'jieba_chinese',
'jieba_user_dict_path' = '/usr/local/manticore/data/user-dict.txt'
]);utilsApi.sql('CREATE TABLE products(title text, price float) morphology = \'jieba_chinese\' jieba_user_dict_path = \'/usr/local/manticore/data/user-dict.txt\'')await utilsApi.sql('CREATE TABLE products(title text, price float) morphology = \'jieba_chinese\' jieba_user_dict_path = \'/usr/local/manticore/data/user-dict.txt\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) morphology = \'jieba_chinese\' jieba_user_dict_path = \'/usr/local/manticore/data/user-dict.txt\'');utilsApi.sql("CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_user_dict_path = '/usr/local/manticore/data/user-dict.txt'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_user_dict_path = '/usr/local/manticore/data/user-dict.txt'", true);utils_api.sql("CREATE TABLE products(title text, price float) morphology = 'jieba_chinese' jieba_user_dict_path = '/usr/local/manticore/data/user-dict.txt'", Some(true)).await;table products {
morphology = jieba_chinese
jieba_user_dict_path = /usr/local/manticore/data/user-dict.txt
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}