形态学预处理器可以在索引时应用于单词,以规范化同一单词的不同形式并改进分词。例如,英文词干提取器可以将 "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
}html_strip = {0|1}
此选项确定是否应从传入的全文数据中去除HTML标记。默认值为0,表示禁用去除。要启用去除,请将值设置为1。
HTML标签和实体被视为标记,并将被处理。
HTML标签被移除,而它们之间的内容(例如,<p>和</p>之间的内容)保持不变。可以选择保留并索引标签属性(例如,A标签中的HREF属性或IMG标签中的ALT属性)。一些常见的内联标签,如A、B、I、S、U、BASEFONT、BIG、EM、FONT、IMG、LABEL、SMALL、SPAN、STRIKE、STRONG、SUB、SUP和TT,将完全移除。所有其他标签被视为块级标签,并用空格替换。例如,文本te<b>st</b>将被索引为单个关键词'test',而te<p>st</p>将被索引为两个关键词'te'和'st'。
HTML实体被解码并替换为其相应的UTF-8字符。去除器支持实体的数字形式(例如ï)和文本形式(例如ó或 ),并支持HTML4标准中指定的所有实体。
去除器旨在与正确形成的HTML和XHTML一起使用,但在处理不规范的输入(例如带有游离的<'s或未关闭的>'s的HTML)时可能会产生意外结果。
请注意,仅移除标签本身以及HTML注释。要移除标签的内容,包括嵌入的脚本,请参阅html_remove_elements选项。标签名称没有限制,这意味着任何看起来是有效标签开始、结束或注释的内容都将被移除。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) html_strip = '1'POST /cli -d "
CREATE TABLE products(title text, price float) html_strip = '1'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'html_strip' => '1'
]);utilsApi.sql('CREATE TABLE products(title text, price float) html_strip = \'1\'')await utilsApi.sql('CREATE TABLE products(title text, price float) html_strip = \'1\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) html_strip = \'1\'');utilsApi.sql("CREATE TABLE products(title text, price float) html_strip = '1'");utilsApi.Sql("CREATE TABLE products(title text, price float) html_strip = '1'");utils_api.sql("CREATE TABLE products(title text, price float) html_strip = '1'", Some(true)).await;table products {
html_strip = 1
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}html_index_attrs = img=alt,title; a=title;
html_index_attrs选项允许您指定即使其他HTML标记被去除,哪些HTML标记属性也应被索引。默认值为空,表示不会索引任何属性。 该选项的格式是每个标签的可索引属性的枚举,如上例所示。指定属性的内容将被保留并索引,从而提供从全文数据中提取附加信息的方法。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) html_index_attrs = 'img=alt,title; a=title;' html_strip = '1'POST /cli -d "
CREATE TABLE products(title text, price float) html_index_attrs = 'img=alt,title; a=title;' html_strip = '1'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'html_index_attrs' => 'img=alt,title; a=title;',
'html_strip' => '1'
]);utilsApi.sql('CREATE TABLE products(title text, price float) html_index_attrs = \'img=alt,title; a=title;\' html_strip = \'1\'')await utilsApi.sql('CREATE TABLE products(title text, price float) html_index_attrs = \'img=alt,title; a=title;\' html_strip = \'1\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) html_index_attrs = \'img=alt,title; a=title;\' html_strip = \'1\'');utilsApi.sql("CREATE TABLE products(title text, price float) html_index_attrs = \'img=alt,title; a=title;\' html_strip = '1'");utilsApi.Sql("CREATE TABLE products(title text, price float) html_index_attrs = \'img=alt,title; a=title;\' html_strip = '1'");utils_api.sql("CREATE TABLE products(title text, price float) html_index_attrs = \'img=alt,title; a=title;\' html_strip = '1'", Some(true)).await;table products {
html_index_attrs = img=alt,title; a=title;
html_strip = 1
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}html_remove_elements = element1[, element2, ...]
一个HTML元素列表,其内容及其自身将被移除。可选,默认值为空字符串(不移除任何元素的内容)。
此选项允许您移除元素的内容,即移除它们之间的所有内容。这对于移除嵌入的脚本、CSS等非常有用。空元素的简短标签形式(例如<br/>)得到了适当支持,这样的标签后面的文本不会被移除。
值是一个逗号分隔的元素(标签)名称列表,这些元素的内容应被移除。标签名称是不区分大小写的。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) html_remove_elements = 'style, script' html_strip = '1'POST /cli -d "
CREATE TABLE products(title text, price float) html_remove_elements = 'style, script' html_strip = '1'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'html_remove_elements' => 'style, script',
'html_strip' => '1'
]);utilsApi.sql('CREATE TABLE products(title text, price float) html_remove_elements = \'style, script\' html_strip = \'1\'')await utilsApi.sql('CREATE TABLE products(title text, price float) html_remove_elements = \'style, script\' html_strip = \'1\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) html_remove_elements = \'style, script\' html_strip = \'1\'');utilsApi.sql("CREATE TABLE products(title text, price float) html_remove_elements = \'style, script\' html_strip = '1'");utilsApi.Sql("CREATE TABLE products(title text, price float) html_remove_elements = \'style, script\' html_strip = '1'");utils_api.sql("CREATE TABLE products(title text, price float) html_remove_elements = \'style, script\' html_strip = '1'", Some(true)).await;table products {
html_remove_elements = style, script
html_strip = 1
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}index_sp = {0|1}
控制句子和段落边界的检测和索引。可选,默认值为0(不进行检测或索引)。
此指令启用句子和段落边界的检测和索引,使得SENTENCE 和 PARAGRAPH 操作符可以工作。句子边界检测基于纯文本分析,只需设置index_sp = 1即可启用。段落检测依赖于HTML标记,并在HTML去除过程期间进行。因此,要索引段落边界,必须同时设置index_sp指令和html_strip指令为1。
以下规则用于确定句子边界:
- 问号(?)和感叹号(!)总是表示句子的边界。
- 结尾的点(.)表示句子的边界,除非出现以下情况:
- 后跟一个字母。这被认为是缩写的一部分(例如 "S.T.A.L.K.E.R." 或 "Goldman Sachs S.p.A.")。
- 后跟一个逗号。这被认为是缩写后跟一个逗号(例如 "Telecom Italia S.p.A., founded in 1994")。
- 后跟一个空格和一个小写字母。这被认为是句子中的缩写(例如 "News Corp. announced in February")。
- 前跟一个空格和一个大写字母,后跟一个空格。这被认为是中间名(例如 "John D. Doe")。
段落边界在每个块级HTML标签处检测,包括:ADDRESS, BLOCKQUOTE, CAPTION, CENTER, DD, DIV, DL, DT, H1, H2, H3, H4, H5, LI, MENU, OL, P, PRE, TABLE, TBODY, TD, TFOOT, TH, THEAD, TR, 和 UL。
句子和段落都会使关键词位置计数器增加1。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) index_sp = '1' html_strip = '1'POST /cli -d "
CREATE TABLE products(title text, price float) index_sp = '1' html_strip = '1'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'index_sp' => '1',
'html_strip' => '1'
]);utilsApi.sql('CREATE TABLE products(title text, price float) index_sp = \'1\' html_strip = \'1\'')await utilsApi.sql('CREATE TABLE products(title text, price float) index_sp = \'1\' html_strip = \'1\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) index_sp = \'1\' html_strip = \'1\'');utilsApi.sql("CREATE TABLE products(title text, price float) index_sp = \'1\' html_strip = '1'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) index_sp = \'1\' html_strip = '1'", true);utils_api.sql("CREATE TABLE products(title text, price float) index_sp = \'1\' html_strip = '1'", Some(true)).await;table products {
index_sp = 1
html_strip = 1
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}index_zones = h*, th, title
一个字段内的HTML/XML区域列表,用于索引。默认值为空字符串(不会索引任何区域)。
一个“区域”定义为一对匹配的起始和结束标签之间的内容,所有共享相同标签名的span都称为一个“区域”。例如,文档字段中的 <H1> 和 </H1> 之间的内容属于H1区域。
index_zones 指令启用区域索引,但HTML stripper 也必须启用(通过设置 html_strip = 1)。index_zones 的值应为逗号分隔的标签名和通配符(以星号结尾)的列表,用于作为区域进行索引。
区域可以嵌套和重叠,只要每个起始标签都有一个匹配的标签。区域也可以用于与 ZONE 运算符匹配,如 extended_query_syntax 中所述。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
- CONFIG
CREATE TABLE products(title text, price float) index_zones = 'h, th, title' html_strip = '1'POST /cli -d "
CREATE TABLE products(title text, price float) index_zones = 'h, th, title' html_strip = '1'"$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float']
],[
'index_zones' => 'h*,th,title',
'html_strip' => '1'
]);utilsApi.sql('CREATE TABLE products(title text, price float) index_zones = \'h, th, title\' html_strip = \'1\'')await utilsApi.sql('CREATE TABLE products(title text, price float) index_zones = \'h, th, title\' html_strip = \'1\'')res = await utilsApi.sql('CREATE TABLE products(title text, price float) index_zones = \'h, th, title\' html_strip = \'1\'');utilsApi.sql("CREATE TABLE products(title text, price float) index_zones = 'h, th, title' html_strip = '1'", true);utilsApi.Sql("CREATE TABLE products(title text, price float) index_zones = 'h, th, title' html_strip = '1'", true);utils_api.sql("CREATE TABLE products(title text, price float) index_zones = 'h, th, title' html_strip = '1'", Some(true)).await;table products {
index_zones = h*, th, title
html_strip = 1
type = rt
path = tbl
rt_field = title
rt_attr_uint = price
}Manticore 允许创建分布式表,它们的行为类似普通的普通表或实时表,但实际上是用于搜索的子表集合。当向分布式表发送查询时,查询会被分配到集合中的所有表。服务器随后收集并处理响应,必要时对聚合值进行排序和重新计算。
从客户端的角度来看,感觉就像是在查询一个单一的表。
分布式表可以由以下任意组合的表组成:
- 本地存储表(普通表 和 实时表)
- 远程表
- 本地和远程表的组合
- Percolate 表(本地、远程或组合)
- 单个本地表和多个远程表,或任何其他组合
不建议将 percolate 和模板表与普通表和实时表混合使用。
分布式表在配置文件中定义为类型 'distributed',或者通过 SQL 子句 CREATE TABLE 定义。
table foo {
type = distributed
local = bar
local = bar1, bar2
agent = 127.0.0.1:9312:baz
agent = host1|host2:tbl
agent = host1:9301:tbl1|host2:tbl2 [ha_strategy=random retry_count=10]
...
}
CREATE TABLE distributed_index type='distributed' local='local_index' agent='127.0.0.1:9312:remote_table'
分布式表的核心在于其所指向的子表列表。分布式表中有两种类型的子表:
在Manticore Search中,分布式表充当“主节点”,将所需的查询代理到其他表,并提供从接收到的响应中合并的结果。该表本身不存储任何数据。它可以连接到本地表和其他服务器上的表。以下是一个简单的分布式表示例:
- Configuration file
- RT mode
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
table index_dist {
type = distributed
local = index1
local = index2
...
}CREATE TABLE local_dist type='distributed' local='index1' local='index2';$params = [
'body' => [
'settings' => [
'type' => 'distributed',
'local' => [
'index1',
'index2'
]
]
],
'table' => 'products'
];
$index = new \Manticoresearch\Index($client);
$index->create($params);utilsApi.sql('CREATE TABLE local_dist type=\'distributed\' local=\'index1\' local=\'index2\'')await utilsApi.sql('CREATE TABLE local_dist type=\'distributed\' local=\'index1\' local=\'index2\'')res = await utilsApi.sql('CREATE TABLE local_dist type=\'distributed\' local=\'index1\' local=\'index2\'');utilsApi.sql("CREATE TABLE local_dist type='distributed' local='index1' local='index2'");utilsApi.Sql("CREATE TABLE local_dist type='distributed' local='index1' local='index2'");utils_api.sql("CREATE TABLE local_dist type='distributed' local='index1' local='index2'", Some(true)).await;