当前位置: 首页 > news >正文

上海门户网站建设公司搜索引擎市场份额2023

上海门户网站建设公司,搜索引擎市场份额2023,华为用了哪些网络营销方式,静态网页有哪些提示#xff1a;文章写完后#xff0c;目录可以自动生成#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、thinkphp中使用Elasticsearch 7.0进行多表的搜索二、使用步骤1.引入库2.读入数据 总结 前言 提示#xff1a;thinkphp中使用Elasticsearch 7.0进行多表的… 提示文章写完后目录可以自动生成如何生成可参考右边的帮助文档 文章目录 前言一、thinkphp中使用Elasticsearch 7.0进行多表的搜索二、使用步骤1.引入库2.读入数据 总结 前言 提示thinkphp中使用Elasticsearch 7.0进行多表的搜索 thinkphp数据库配置文件 // Elasticsearch数据库配置信息elasticsearch [scheme http,host 127.0.0.1,port 9200,user ,pass ,timeout 2,],提示以下是本篇文章正文内容下面案例可供参考 一、thinkphp中使用Elasticsearch 7.0进行多表的搜索 示例thinkphp中使用Elasticsearch 7.0进行多表的搜索 二、使用步骤 1.引入库 直接上代码如下示例 composer require elasticsearch/elasticsearch: 7.0.*2.读入数据 代码如下示例 namespace app\common\model; use think\facade\Db; use think\Model; use Elasticsearch\ClientBuilder; class Article extends Model {protected $client;public function __construct($data []){parent::__construct($data);try { $this-client ClientBuilder::create()-setHosts([config(database.connections.elasticsearch.host) . : . config(database.connections.elasticsearch.port)])-build();} catch (\Exception $e) {// 输出连接错误信息echo $e-getMessage();exit;}}// 添加文档到Elasticsearchpublic function addDocument(){$articles Db::name(article)-select();foreach ($articles as $article) {$data [id $article[id], // 文章表的 IDtitle $article[title],content $article[content],category_id $article[category_id], // 文章表的 ID];$params [index articles, // 索引名称id $data[id], // 文章 ID 作为文档的唯一标识body $data,];$response $this-client-index($params);}return $response;}// 搜索文档public function searchDocuments($index,$query){$params [index $index,body [query [multi_match [query $query,fields [title, content],],],],];$response $this-client-search($params);return $response;} }?php /*** Created by PhpStorm.* User: wangkxinfoxmail.com* Date: 2023/9/2* Time: 17:55*/namespace app\common\model; use think\facade\Db; use think\Model; use Elasticsearch\ClientBuilder;class Book extends Model {protected $client;public function __construct($data []){parent::__construct($data);try {// $host config(database.connections.elasticsearch.host);// $port config(database.connections.elasticsearch.port);$this-client ClientBuilder::create()-setHosts([config(database.connections.elasticsearch.host) . : . config(database.connections.elasticsearch.port)])-build();} catch (\Exception $e) {// 输出连接错误信息echo $e-getMessage();exit;}}// 添加文档到Elasticsearchpublic function addDocument(){$books Db::name(book)-select();foreach ($books as $book) {$data [id $book[id], // 书籍表的 IDuser_id $book[user_id], // 书籍表作者IDbook $book[book],];$params [index books, // 索引名称id $data[id], // 文章 ID 作为文档的唯一标识body $data,];$response $this-client-index($params);}return $response;}// 搜索文档public function searchDocuments($index,$query){$params [index $index,body [query [multi_match [query $query,fields [book],],],],];$response $this-client-search($params);return $response;} }?php /*** Created by PhpStorm.* User: wangkxinfoxmail.com* Date: 2023/9/2* Time: 15:27* 全局搜素模型*/namespace app\common\model;use think\Model; use Elasticsearch\ClientBuilder;class ElasticsearchModel extends Model {protected $client;public function __construct($data []){parent::__construct($data);try {$this-client ClientBuilder::create()-setHosts([config(database.connections.elasticsearch.host) . : . config(database.connections.elasticsearch.port)])-build();} catch (\Exception $e) {// 输出连接错误信息echo $e-getMessage();exit;}}public function globalSearch($keyword){// 搜索articles索引$articles $this-searchIndex(articles, $keyword);// 搜索books索引$books $this-searchIndex(books, $keyword);// 合并搜索结果$result array_merge($articles, $books);return $result;}protected function searchIndex($index, $keyword){$params [index $index,body [query [multi_match [query $keyword,fields [title, content,book],],],],];// 执行搜索请求$response $this-client-search($params);// 解析结果$result [];if (isset($response[hits][hits])) {foreach ($response[hits][hits] as $hit) {$result[] $hit[_source];$result[index] $index;}}return $result;}}?php /*** Created by PhpStorm.* User: wangkxinfoxmail.com* Date: 2023/9/2* Time: 18:53*/namespace app\index\controller;use app\common\model\ElasticsearchModel;class SearchController {//全局搜索个表间的数据public function search($keyword){$searchModel new ElasticsearchModel();$result $searchModel-globalSearch($keyword);return json($result);} }namespace app\index\controller; use app\BaseController; use app\common\model\Article as ElasticArticle; use app\common\model\Book as ElasticBook; use app\Request; use Elasticsearch\ClientBuilder;class Demo1 extends BaseController { //新增索引,建议在模型中新增 ,删除, 修改 或者使用观察者模式更新ES索引public function addDocument(){$elasticsearchArticle new ElasticArticle();$response $elasticsearchArticle-addDocument();$elasticsearchBook new ElasticBook();$response1 $elasticsearchBook-addDocument();return json($response);// print_r(json($response));// print_r(json($response1));}/*** 单独搜索文章表例子*/public function search(Request $request){$keyword $request-param(keyword);$elasticsearchModel new ElasticArticle();$index articles;$query 你;$response $elasticsearchModel-searchDocuments($index, $query);return json($response);}//单独搜搜书籍表public function searchBook(Request $request){$keyword $request-param(keyword);$elasticsearchModel new ElasticBook();$index books;$query 巴黎;$response $elasticsearchModel-searchDocuments($index, $query);return json($response);}public function deleteIndex(){$client ClientBuilder::create()-build();$params [index my_index, // 索引名称];$response $client-indices()-delete($params);if ($response[acknowledged]) {return 索引删除成功;} else {return 索引删除失败;}}}使用的表 CREATE TABLE article (id int(11) NOT NULL AUTO_INCREMENT,category_id int(11) DEFAULT NULL,title varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,content varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,PRIMARY KEY (id) ) ENGINEMyISAM AUTO_INCREMENT107 DEFAULT CHARSETutf8 COLLATEutf8_unicode_ci;CREATE TABLE book (id int(11) NOT NULL AUTO_INCREMENT,user_id int(11) DEFAULT NULL,book varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,PRIMARY KEY (id) ) ENGINEMyISAM AUTO_INCREMENT21 DEFAULT CHARSETutf8 COLLATEutf8_unicode_ci;CREATE TABLE elasticsearch_model (id int(11) NOT NULL AUTO_INCREMENT COMMENT 主键,model_name varchar(255) NOT NULL DEFAULT COMMENT 模型名称,index_name varchar(255) NOT NULL DEFAULT COMMENT 索引名称,created_time int(11) NOT NULL DEFAULT 0 COMMENT 创建时间,updated_time int(11) NOT NULL DEFAULT 0 COMMENT 更新时间,PRIMARY KEY (id),UNIQUE KEY index_name_unique (index_name) ) ENGINEInnoDB AUTO_INCREMENT3 DEFAULT CHARSETutf8mb4 COMMENTElasticsearch 模型配置表; 结果 windwos 上记住 安装 Elasticsearch 7.0 库, 和 kibana-7.0.0-windows-x86_64 图像管理工具 总结 提示这是简单例子, 注意’fields’ [‘title’, ‘content’], 尝试使用搜索number型字段,索引报错, 貌似只支持txt类型字段搜索 例如以上就是今天要讲的内容本文仅仅简单介绍了Elasticsearch的使用
http://www.hkea.cn/news/14269137/

相关文章:

  • 宣传网站建设的步骤网站建设新闻中心
  • 河北省建设厅官方网站做企业网站后期还需要费用吗
  • 一个新网站要怎么做seo营销云产品
  • 虚拟主机做网站展厅宣传片
  • 丹东建设工程信息网站羽毛球赛事
  • 如何自己建设淘宝网站首页wed网站开发是什么
  • 宁晋网站建设公司信息咨询公司注册要求
  • 吉林整站优化.net网站开发岗位
  • 如何建设网站学校网站建设内容设计
  • 成都网站优化方案重庆网站seo设计
  • 南平网站开发u钙网logo设计官网
  • 叫别人做网站要多久山西做杂粮的网站
  • 网站建设与推广策划书wordpress 热门文章调用
  • 如何在企业版社保网站做增员自助免费建站
  • 建设网站的appphp做直播类型的网站
  • 免费商城app邢台seo一站式
  • 广东卫视你会怎么做网站php网站制作报价
  • 免费网站建设培训广州个人网站备案要多久
  • 浙江建设继续教育网站WordPress网站动漫你在
  • 佛山网站建设wantsun甘肃谷歌seo
  • 新公司网站建设费用怎么入账怎么开店铺
  • 商业网站建设案例课程视屏下载青岛抖音seo
  • 网站开发公司应该具备怎样的资质为企业做贡献的文章
  • 重庆网络问政平台华龙网电影采集网站怎么做seo
  • 阳江 网站建设wordpress 增加语言包
  • 网站开发流程框架熟悉网页设计人机交互实验报告
  • 有了页游源代码如何做网站网页制作框架教程
  • 淘宝客网站如何做制作公司网站需要购买域名和服务器吗
  • 网站的建设成本的账务处理seo服务工程
  • 如何为产品做网站重庆网站维护制作