停用词是在索引和搜索过程中被忽略的词语,通常是因为它们的频率高且对搜索结果的贡献较低。
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;形态学预处理器可以在索引时应用于单词,以规范化同一单词的不同形式并改进分词。例如,英文词干提取器可以将 "dogs" 和 "dog" 规范化为 "dog",从而这两个关键词的搜索结果相同。
Manticore 有四种内置的形态学预处理器:
- 词形还原器(Lemmatizer):将单词还原为其根或词元。例如,“running”可还原为“run”,“octopi”可还原为“octopus”。注意,有些单词可能有多个对应的根形式。例如,“dove”既可以是“dive”的过去式,也可以是名词“鸽子”,如在句子“A white dove flew over the cuckoo's nest.”中。此时,词形还原器可以生成所有可能的根形式。
- 词干提取器(Stemmer):通过移除或替换某些已知的后缀,将单词还原为词干。所得的词干不一定是有效词。例如,Porter 英文词干提取器会将“running”还原为“run”,“business”还原为“busi”(非有效词),且不会还原“octopi”。
- 语音算法:将单词替换为语音编码,即使单词不同但发音相近,编码也相同。
- 分词算法:将文本拆分成词。目前仅对中文有效。
morphology = morphology1[, morphology2, ...]
morphology 指令指定要应用于被索引单词的一系列形态学预处理器。这是一个可选设置,默认是不应用任何预处理器。
Manticore 具有内置的形态学预处理器,支持:
- 英语、俄语和德语的词形还原器
- 英语、俄语、阿拉伯语和捷克语的词干提取器
- SoundEx 和 MetaPhone 语音算法
- 中文分词算法
- Snowball(libstemmer)词干提取器,支持超过15 种其他语言。
词形还原器需要字典 .pak 文件,可以通过 manticore-language-packs 包安装,或者从Manticore官网下载。后一种情况需要将字典放入由 lemmatizer_base 指定的目录。
此外,设置 lemmatizer_cache 可以通过使用更多内存缓存未压缩字典,加快词形还原速度。
中文分词可以使用 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 实现基于双重 Metaphone 算法,索引其主码。
要使用 morphology 选项,请指定一个或多个内置选项,包括:
- none:不执行任何形态学处理
- lemmatize_ru - 使用俄语词形还原器,选择单一根形式
- lemmatize_uk - 使用乌克兰语词形还原器,选择单一根形式(请先在 Centos 或 Ubuntu/Debian 安装)。为保证词形还原器正常工作,务必保留
charset_table中的乌克兰特有字符,因默认不会保留。可通过如下方法覆盖:charset_table='non_cont,U+0406->U+0456,U+0456,U+0407->U+0457,U+0457,U+0490->U+0491,U+0491'。此处 有一个关于如何安装和使用乌克兰词形还原器的交互课程。 - lemmatize_en - 使用英语词形还原器,选择单一根形式
- lemmatize_de - 使用德语词形还原器,选择单一根形式
- lemmatize_ru_all - 使用俄语词形还原器,索引所有可能的根形式
- lemmatize_uk_all - 使用乌克兰语词形还原器,索引所有可能的根形式。安装链接见上,注意
charset_table设置。 - lemmatize_en_all - 使用英语词形还原器,索引所有可能的根形式
- lemmatize_de_all - 使用德语词形还原器,索引所有可能的根形式
- stem_en - 使用 Porter's 英语词干提取器
- stem_ru - 使用 Porter's 俄语词干提取器
- stem_enru - 使用 Porter's 英语和俄语词干提取器
- 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功能允许您根据源单词长度抑制词干提取,即避免对过短的单词进行词干提取。比给定阈值短的关键词将不会被词干提取。请注意,长度恰好等于指定值的关键词会被词干提取。所以要避免对3字符关键词进行词干提取,您应该将值设为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 是一个中文文本分词库,使用词典文件辅助分词。这些词典文件的格式如下:每行包含一个词,分为三部分用空格分隔——词语本身、词频和词性标签。词频和词性标签是可选的,可以省略。词典文件必须是 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
}