• 忽略停用词

停用词是指在索引和搜索过程中被忽略的词,通常是因为它们的出现频率高且对搜索结果的价值低。

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 种语言的停用词可用。以下是它们的完整别名列表:

  • 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:

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

stopword_step={0|1}

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
}

最后更新于