停用词是指在索引和搜索过程中被忽略的词,通常是因为它们的出现频率高且对搜索结果的价值低。
Manticore Search 默认会对停用词应用词干化 ,这可能会导致不希望的结果,不过可以通过stopwords_unstemmed 关闭此功能。
小型停用词文件存储在表头,文件大小受限于 embedded_limit 选项的设置。
停用词不会被索引,但它们会影响关键词的位置。例如,如果“the”是一个停用词,文档1包含短语“in office”,而文档2包含短语“in the office”,搜索“in office”作为精确短语时只会返回文档1,即使文档2中的“the”被跳过作为停用词。可以通过stopword_step 指令修改此行为。
stopwords
复制 stopwords=path/to/stopwords/file[ path/to/another/file ...]
`stopwords` 是可选设置,默认是空的。它允许指定一个或多个停用词文件的路径,用空格分隔。所有文件都会被加载。在实时模式下,仅允许使用绝对路径。
停用词文件格式为简单的 UTF-8 编码纯文本。文件数据会根据 charset_table 设置进行标记,因此你可以使用与索引数据相同的分隔符。
停用词文件可以手动创建或半自动生成。indexer
提供了一个模式,用于创建表的频率字典,按关键词频率排序。该字典中的前几个关键词通常可以作为停用词。有关详细信息,请参阅--buildstops 和 --buildfreqs 参数。
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'
复制 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'
]);
Python:
复制 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\'')
Javascript:
复制 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\'');
Java:
复制 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'");
C#:
复制 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'");
复制 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 种语言的停用词可用。以下是它们的完整别名列表:
例如,要使用意大利语的停用词,只需在配置文件中添加以下行:
SQL:
复制 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'
]);
Python:
复制 utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'it\'')
Javascript:
复制 res = await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'it\'');
Java:
复制 utilsApi.sql("CREATE TABLE products(title text, price float) stopwords = 'it'");
C#:
复制 utilsApi.Sql("CREATE TABLE products(title text, price float) stopwords = 'it'");
复制 table products {
stopwords = it
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}
如果需要使用多种语言的停用词,您应将所有别名列出,并用逗号(实时模式)或空格(普通模式)分隔:
SQL:
复制 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'
]);
Python:
复制 utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en, it, ru\'')
Javascript:
复制 res = await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en, it, ru\'');
Java:
复制 utilsApi.sql("CREATE TABLE products(title text, price float) stopwords = 'en, it, ru'");
C#:
复制 utilsApi.sql("CREATE TABLE products(title text, price float) stopwords = 'en, it, ru'");
复制 table products {
stopwords = en it ru
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}
stopword_step
position_increment
设置在 stopwords 中是可选的,允许的值为 0 和 1,默认值为 1。
SQL:
复制 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'
]);
Python:
复制 utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en\' stopword_step = \'1\'')
Javascript:
复制 res = await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en\' stopword_step = \'1\'');
Java:
复制 utilsApi.sql("CREATE TABLE products(title text, price float) stopwords = \'en\' stopword_step = \'1\'");
C#:
复制 utilsApi.sql("CREATE TABLE products(title text, price float) stopwords = \'en\' stopword_step = \'1\'");
复制 table products {
stopwords = en
stopword_step = 1
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}
stopwords_unstemmed
复制 stopwords_unstemmed={0|1}
此设置决定是应用停用词过滤器在词干提取之前还是之后。可选,默认值为 0(在词干提取之后应用停用词过滤器)。
默认情况下,停用词会被词干提取处理,然后在提取后的标记上应用。这意味着,当 stem(token)
等于 stem(stopword)
时,标记会被视为停用。因此,像 "Andes" 这样的词可能会被提取为 "and",如果 "and" 是一个停用词,那么 "Andes" 也会被跳过。
但是,您可以通过启用 stopwords_unstemmed
指令来改变这一行为。当启用此选项时,停用词会在词干提取之前应用(因此对原始词形进行处理),当标记与停用词相等时,会跳过该标记。
SQL:
复制 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'
]);
Python:
复制 utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en\' stopwords_unstemmed = \'1\'')
Javascript:
复制 res = await utilsApi.sql('CREATE TABLE products(title text, price float) stopwords = \'en\' stopwords_unstemmed = \'1\'');
Java:
复制 utilsApi.sql("CREATE TABLE products(title text, price float) stopwords = \'en\' stopwords_unstemmed = \'1\'");
C#:
复制 utilsApi.Sql("CREATE TABLE products(title text, price float) stopwords = \'en\' stopwords_unstemmed = \'1\'");
复制 table products {
stopwords = en
stopwords_unstemmed = 1
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}