我想用elasticsearch为博客的文章做站内搜索,后台用的php。
文章表articles的全部字段如下:
<code>id title content user_id created_at updated_at</code>
现在我想为文章表的title字段、content字段、updated_at字段,共三个字段创建索引。
下面是我参照elasticsearch-php客户端的官方文档写的创建索引blog和创建类型article的demo,分词用到了ik分词。
其中有些选项不太清楚什么意思,具体问题在下面代码中(有4个),请大神帮解答一下,谢谢。
官方文档链接:https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_index_management_operations.html#_create_an_index_advanced_example
<code> $params = [ 'index' => 'blog', 'body' => [ 'settings' => [ 'number_of_shards' => 1, 'number_of_replicas' => 0, 'analysis' => [ 'filter' => [ //1、这里的两个shingle应该改成article吗? 'shingle' => [ 'type' => 'shingle' ] ], //2、char_filter里面内容表示什么意思?包括pre_negs和post_negs。 'char_filter' => [ 'pre_negs' => [ 'type' => 'pattern_replace', 'pattern' => '(\\w+)\\s+((?i:never|no|nothing|nowhere|noone|none|not|havent|hasnt|hadnt|cant|couldnt|shouldnt|wont|wouldnt|dont|doesnt|didnt|isnt|arent|aint))\\b', 'replacement' => '~$1 $2' ], 'post_negs' => [ 'type' => 'pattern_replace', 'pattern' => '\\b((?i:never|no|nothing|nowhere|noone|none|not|havent|hasnt|hadnt|cant|couldnt|shouldnt|wont|wouldnt|dont|doesnt|didnt|isnt|arent|aint))\\s+(\\w+)', 'replacement' => '$1 ~$2' ] ], //3、analyzer的内容需要怎么修改吗? 'analyzer' => [ 'blog' => [ 'type' => 'custom', 'tokenizer' => 'standard', 'filter' => ['lowercase', 'stop', 'kstem'] ] ] ] ], 'mappings' => [ 'article' => [ "_all" => [ "analyzer" => "ik_max_word", "search_analyzer" => "ik_max_word", "term_vector" => "no", "store" => "false" ], 'properties' => [ 'title' => [ 'type' => 'string', 'store' => 'no', 'term_vector' => 'with_positions_offsets', 'analyzer' => 'ik_max_word', 'search_analyzer' => 'ik_max_word', 'include_in_all' => 'true', 'boost' => 9 ], 'content' => [ 'type' => 'string', 'store' => 'no', 'term_vector' => 'with_positions_offsets', 'analyzer' => 'ik_max_word', 'search_analyzer' => 'ik_max_word', 'include_in_all' => 'true', 'boost' => 8 ], //4、时间只是用来在搜索的时候排序使用,下面的选项该怎么填写? 'updated_at' => [ 'type' => '', 'store' => '', 'term_vector' => '', 'analyzer' => '', 'search_analyzer' => '', 'include_in_all' => '', 'boost' => ] ] ] ] ] ]; $client->indices()->create($params);</code>
回复内容:
我想用elasticsearch为博客的文章做站内搜索,后台用的php。
文章表articles的全部字段如下:
<code>id title content user_id created_at updated_at</code>
现在我想为文章表的title字段、content字段、updated_at字段,共三个字段创建索引。
下面是我参照elasticsearch-php客户端的官方文档写的创建索引blog和创建类型article的demo,分词用到了ik分词。
其中有些选项不太清楚什么意思,具体问题在下面代码中(有4个),请大神帮解答一下,谢谢。
官方文档链接:https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_index_management_operations.html#_create_an_index_advanced_example
<code> $params = [ 'index' => 'blog', 'body' => [ 'settings' => [ 'number_of_shards' => 1, 'number_of_replicas' => 0, 'analysis' => [ 'filter' => [ //1、这里的两个shingle应该改成article吗? 'shingle' => [ 'type' => 'shingle' ] ], //2、char_filter里面内容表示什么意思?包括pre_negs和post_negs。 'char_filter' => [ 'pre_negs' => [ 'type' => 'pattern_replace', 'pattern' => '(\\w+)\\s+((?i:never|no|nothing|nowhere|noone|none|not|havent|hasnt|hadnt|cant|couldnt|shouldnt|wont|wouldnt|dont|doesnt|didnt|isnt|arent|aint))\\b', 'replacement' => '~$1 $2' ], 'post_negs' => [ 'type' => 'pattern_replace', 'pattern' => '\\b((?i:never|no|nothing|nowhere|noone|none|not|havent|hasnt|hadnt|cant|couldnt|shouldnt|wont|wouldnt|dont|doesnt|didnt|isnt|arent|aint))\\s+(\\w+)', 'replacement' => '$1 ~$2' ] ], //3、analyzer的内容需要怎么修改吗? 'analyzer' => [ 'blog' => [ 'type' => 'custom', 'tokenizer' => 'standard', 'filter' => ['lowercase', 'stop', 'kstem'] ] ] ] ], 'mappings' => [ 'article' => [ "_all" => [ "analyzer" => "ik_max_word", "search_analyzer" => "ik_max_word", "term_vector" => "no", "store" => "false" ], 'properties' => [ 'title' => [ 'type' => 'string', 'store' => 'no', 'term_vector' => 'with_positions_offsets', 'analyzer' => 'ik_max_word', 'search_analyzer' => 'ik_max_word', 'include_in_all' => 'true', 'boost' => 9 ], 'content' => [ 'type' => 'string', 'store' => 'no', 'term_vector' => 'with_positions_offsets', 'analyzer' => 'ik_max_word', 'search_analyzer' => 'ik_max_word', 'include_in_all' => 'true', 'boost' => 8 ], //4、时间只是用来在搜索的时候排序使用,下面的选项该怎么填写? 'updated_at' => [ 'type' => '', 'store' => '', 'term_vector' => '', 'analyzer' => '', 'search_analyzer' => '', 'include_in_all' => '', 'boost' => ] ] ] ] ] ]; $client->indices()->create($params);</code>

PHP仍然流行的原因是其易用性、灵活性和强大的生态系统。1)易用性和简单语法使其成为初学者的首选。2)与web开发紧密结合,处理HTTP请求和数据库交互出色。3)庞大的生态系统提供了丰富的工具和库。4)活跃的社区和开源性质使其适应新需求和技术趋势。

PHP和Python都是高层次的编程语言,广泛应用于Web开发、数据处理和自动化任务。1.PHP常用于构建动态网站和内容管理系统,而Python常用于构建Web框架和数据科学。2.PHP使用echo输出内容,Python使用print。3.两者都支持面向对象编程,但语法和关键字不同。4.PHP支持弱类型转换,Python则更严格。5.PHP性能优化包括使用OPcache和异步编程,Python则使用cProfile和异步编程。

PHP主要是过程式编程,但也支持面向对象编程(OOP);Python支持多种范式,包括OOP、函数式和过程式编程。PHP适合web开发,Python适用于多种应用,如数据分析和机器学习。

PHP起源于1994年,由RasmusLerdorf开发,最初用于跟踪网站访问者,逐渐演变为服务器端脚本语言,广泛应用于网页开发。Python由GuidovanRossum于1980年代末开发,1991年首次发布,强调代码可读性和简洁性,适用于科学计算、数据分析等领域。

PHP适合网页开发和快速原型开发,Python适用于数据科学和机器学习。1.PHP用于动态网页开发,语法简单,适合快速开发。2.Python语法简洁,适用于多领域,库生态系统强大。

PHP在现代化进程中仍然重要,因为它支持大量网站和应用,并通过框架适应开发需求。1.PHP7提升了性能并引入了新功能。2.现代框架如Laravel、Symfony和CodeIgniter简化开发,提高代码质量。3.性能优化和最佳实践进一步提升应用效率。

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP类型提示提升代码质量和可读性。1)标量类型提示:自PHP7.0起,允许在函数参数中指定基本数据类型,如int、float等。2)返回类型提示:确保函数返回值类型的一致性。3)联合类型提示:自PHP8.0起,允许在函数参数或返回值中指定多个类型。4)可空类型提示:允许包含null值,处理可能返回空值的函数。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3汉化版
中文版,非常好用

Atom编辑器mac版下载
最流行的的开源编辑器

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)