课程编程项目2,第2组的学校项目,专业单身汉在Erasmumshogeschool Brussel上进行了“应用”。
搜索引擎申请保险文件。保险公司在其特定领域中存储有关立法,法学和法律学说的文件。目的是根据Elasticsearch框架的算法为员工提供易于使用的搜索引擎应用程序。
| 成分 | 版本 |
|---|---|
| Linux Ubuntu | |
| fscrawler | |
| Elasticsearch | 6.8 |
| Elasticsearch-PHP | 6.7 |
| php | 7.4.10(CLI) |
| 作曲家 | 2.0.6 |
| Laravel安装程序 | 4.1.0 |
| mysql |
注意: FSCrawler VXXXX仅与Elasticsearch 6.8兼容。因此,在您的laravel Composer.json文件中需要包装eLasticsearch-php v6.7
完整的文档可以在此处找到。文档存储在repo /docs /中,因此,如果您看到错别字或问题,请提交PR修复它!
我们还使用util/GenerateDocExamples.php脚本提供了用于PHP的代码示例生成器。此命令解析此json规范产生的util/alternative_report.spec.json文件,并生成php示例for each摘要值。这些示例以docs/examples文件夹的形式以Asciidoc格式存储。
安装Elasticsearch-PHP的推荐方法是通过作曲家。
将elasticsearch/elasticsearch添加为项目的composer.json文件中的依赖项(例如,更改适合您的Elasticsearch版本的版本,例如ES 7.0):
{
"require" : {
"elasticsearch/elasticsearch" : " ^7.0 "
}
}下载并安装作曲家:
curl -s http://getcomposer.org/installer | php安装您的依赖项:
php composer.phar install需要作曲家的自动加载器
作曲家还准备一个自动加载文件,该文件能够自动加载其下载的任何库中的所有类。要使用它,只需将以下行添加到您的代码的引导过程中:
<?php
use Elasticsearch ClientBuilder ;
require ' vendor/autoload.php ' ;
$ client = ClientBuilder:: create ()-> build ();您可以在如何安装作曲家,配置自动加载以及其他最佳实践方面找到有关在getComposer.org上定义依赖项的更多信息。
该库的7.0版至少需要PHP版本7.1。此外,它要求本机JSON扩展名为1.3.7版或更高版本。
| Elasticsearch-PHP分支 | PHP版本 |
|---|---|
| 7.0 | > = 7.1.0 |
| 6.0 | > = 7.0.0 |
| 5.0 | > = 5.6.6 |
| 2.0 | > = 5.4.0 |
| 0.4,1.0 | > = 5.3.9 |
由于InsuraQuest使用Laravel Jetstream,因此包括登录,注册,电子邮件验证,两因素身份验证和会话管理。 Jetstream使用Laravel Fortify,这是Laravel的前端不可知论身份验证后端。
在config/fortify.php配置文件中,您可以自定义不同方面,请选择要在项目等上实现的方面。
可以根据授权请求执行的逻辑,可以在App Action Fortify中找到和修改。
有关Jetstream的更多信息和文档,请参见Jetstream网站。
InsuraQuest通过属性“类型”实现授权,该属性包含在每个用户启示中。有四种类型:来宾,用户,图书馆员和管理员。类型是级联。每个新级别具有以下级别的权限 +其他权限。
授权在不同的路线(web.php)上执行。在混合视图方面,还通过实现本机Laravel @Can和@Cannot来在视图级上执行。
可以直接在数据库中或使用AdminActCount签名时在数据库中进行调整。
当访客尚未签约时,他将被重新安排到登录屏幕上。默认情况下 - 新用户注册时 - 他将分配“访客”类型。他将能够看到着陆页和文档,但无法查询任何文件。用户可以查询文档,打开它们并邮寄。图书馆员可以上传新文件,删除文件并更改其上的标签。管理员可以查看所有用户,他们的信息并调整其类型。
部署设置的描述。
"external" : {
"properties" : {
"title" : {
"type" : " text "
},
"language" : {
"type" : " keyword "
},
"date_published" : {
"type" : " date "
},
"issuer" : {
"type" : " keyword "
},
"category" : {
"type" : " keyword "
},
"tag" : {
"type" : " keyword "
}
}
}被认为比内置的Laravel服务器更健壮。
server {
listen 80 ;
server_name 10.3.50.7 ;
root /var/www/insuraquest_production/insuraquest/public ;
add_header X-Frame-Options " SAMEORIGIN " ;
add_header X-XSS-Protection " 1; mode=block " ;
add_header X-Content-Type-Options " nosniff " ;
index index.php ;
charset utf-8 ;
location / {
try_files $uri $uri / /index.php ? $query_string ;
}
location = /favicon.ico { access_log off ; log_not_found off ; }
location = /robots.txt { access_log off ; log_not_found off ; }
error_page 404 /index.php ;
location ~ . php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock ;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name ;
include fastcgi_params ;
}
location ~ / . ( ? ! well-known). * {
deny all ;
}
}php artisan migrate:fresh --seedgit init --bare /home/student/insuraquest/bare_project.init #! /bin/bash
# check out the files
git --work-tree=/var/www/insuraquest_production --git-dir=/home/student/insuraquest/bare_project.git checkout -f
chmod +x /path/to/bare_project.git/hooks/post-receivegit remote add live ' [email protected]:/home/student/insuraquest/bare_project.git '
git push --set-upstream live maincomposer update chgrp -R www-data insuraquest_productionphp artisan storage:link在Elasticsearch-PHP中,几乎所有内容都是由关联数组配置的。休息端点,文档和可选参数 - 一切都是关联数组。
要索引文档,我们需要指定三个信息:索引,ID和文档正文。这是通过构造密钥的关联数组来完成的:值对。请求主体本身是一个关联阵列,具有密钥:值对,与文档中的数据相对应:
$ params = [
' index ' => ' my_index ' ,
' id ' => ' my_id ' ,
' body ' => [ ' testField ' => ' abc ' ]
];
$ response = $ client -> index ( $ params );
print_r ( $ response );您返回的响应指示该文档是在您指定的索引中创建的。响应是一个关联阵列,包含Elasticsearch返回的JSON的解码版本:
Array
(
[_index] => my_index
[_type] => _doc
[_id] => my_id
[_version] => 1
[result] => created
[_shards] => Array
(
[total] => 1
[successful] => 1
[failed] => 0
)
[_seq_no] => 0
[_primary_term] => 1
)让我们获取我们刚刚索引的文档。这只会返回文档:
$ params = [
' index ' => ' my_index ' ,
' id ' => ' my_id '
];
$ response = $ client -> get ( $ params );
print_r ( $ response );响应包含一些元数据(索引,版本等)以及_source字段,这是您发送到Elasticsearch的原始文档。
Array
(
[_index] => my_index
[_type] => _doc
[_id] => my_id
[_version] => 1
[_seq_no] => 0
[_primary_term] => 1
[found] => 1
[_source] => Array
(
[testField] => abc
)
)如果要直接检索_source字段,则有getSource方法:
$ params = [
' index ' => ' my_index ' ,
' id ' => ' my_id '
];
$ source = $ client -> getSource ( $ params );
print_r ( $ source );响应将只是_source值:
Array
(
[testField] => abc
)搜索是Elasticsearch的标志,所以让我们进行搜索。我们将使用匹配查询作为演示:
$ params = [
' index ' => ' my_index ' ,
' body ' => [
' query ' => [
' match ' => [
' testField ' => ' abc '
]
]
]
];
$ response = $ client -> search ( $ params );
print_r ( $ response );响应与以前的响应有些不同。我们看到了一些元数据( took , timed_out等)和一个名为hits的阵列。这代表您的搜索结果。 hits的内部是另一个名为hits的数组,其中包含单独的搜索结果:
Array
(
[took] => 33
[timed_out] =>
[_shards] => Array
(
[total] => 1
[successful] => 1
[skipped] => 0
[failed] => 0
)
[hits] => Array
(
[total] => Array
(
[value] => 1
[relation] => eq
)
[max_score] => 0.2876821
[hits] => Array
(
[ 0 ] => Array
(
[_index] => my_index
[_type] => _doc
[_id] => my_id
[_score] => 0.2876821
[_source] => Array
(
[testField] => abc
)
)
)
)
)好吧,让我们继续删除我们之前添加的文档:
$ params = [
' index ' => ' my_index ' ,
' id ' => ' my_id '
];
$ response = $ client -> delete ( $ params );
print_r ( $ response );您会注意到这与get语法相同。唯一的区别是操作: delete而不是get 。响应将确认该文档已删除:
Array
(
[_index] => my_index
[_type] => _doc
[_id] => my_id
[_version] => 2
[result] => deleted
[_shards] => Array
(
[total] => 1
[successful] => 1
[failed] => 0
)
[_seq_no] => 1
[_primary_term] => 1
)由于Elasticsearch的动态性质,我们添加的第一个文档自动构建了一个带有一些默认设置的索引。让我们删除该索引,因为我们要以后指定自己的设置:
$ deleteParams = [
' index ' => ' my_index '
];
$ response = $ client -> indices ()-> delete ( $ deleteParams );
print_r ( $ response );回应:
Array
(
[acknowledged] => 1
)现在我们开始新鲜(没有数据或索引),让我们添加一个新的索引,并使用一些自定义设置:
$ params = [
' index ' => ' my_index ' ,
' body ' => [
' settings ' => [
' number_of_shards ' => 2 ,
' number_of_replicas ' => 0
]
]
];
$ response = $ client -> indices ()-> create ( $ params );
print_r ( $ response );Elasticsearch现在将使用您选择的设置创建该索引,并返回确认:
Array
(
[acknowledged] => 1
)图书馆员有可能上传新文件。上传文档时,可以将标签添加到上传的文档中。标签的内容从MySQL表中拉出并添加到表单中。
FileUploadController.php
$ this ->validate( $ request , [
' title ' => ' required ' ,
' language ' => ' required ' ,
' date ' => ' required|date ' ,
' issuer ' => ' required ' ,
' category ' => ' required ' ,
' tag ' => ' required ' ,
' file ' => ' required|mimes:pdf|max:2048 '
]上传文档后,文件和标签将发布到fscrawler,该文件将在添加到我们的elasticsearch节点之前索引文档。
FileUploadController.php
$ file = $ request -> file ( ' file ' );
$ pathname = $ file -> store ( ' public ' );
$ fully_qualified_pathname = storage_path ( ' app/ ' . $ pathname );
$ client = new Client ();
try {
$ client -> request ( ' POST ' , ' http://127.0.0.1:8080/fscrawler/_upload ' ,
);
} catch ( GuzzleException $ e ) {
echo $ e ;
}为形式布局添加了一个插件 - > tailwind.config.js
https://tailwindcss-custom-forms.netlify.app/
plugins: [
require ( ' @tailwindcss/custom-forms ' ),
]用户获得所有搜索结果后,他可以查看有关任何结果的更多详细信息。
在这里,他有可能编辑,删除或邮寄显示的PDF。
修改或创建的邮件功能文件是
命令使用了用于创建电子邮件的Laravel Mail -Mail Markdown类。
php artisan make:mail EmailInsuraquest --markdown=Email.insuraEmail
邮件控制器,从本质上讲,我们将定义具有显示用户列表的逻辑。运行命令以创建控制器。
php artisan make:controller MailController
测试电子邮件功能的可能性http:// localhost:8000/send -email->将邮件发送到MailTrap(帐户BART)
TODO:将邮件功能实现到一个搜索结果中
use GuzzleHttp Ring Client MockHandler ;
use Elasticsearch ClientBuilder ;
// The connection class requires 'body' to be a file stream handle
// Depending on what kind of request you do, you may need to set more values here
$ handler = new MockHandler ([
' status ' => 200 ,
' transfer_stats ' => [
' total_time ' => 100
],
' body ' => fopen ( ' somefile.json ' ),
' effective_url ' => ' localhost '
]);
$ builder = ClientBuilder:: create ();
$ builder -> setHosts ([ ' somehost ' ]);
$ builder -> setHandler ( $ handler );
$ client = $ builder -> build ();
// Do a request and you'll get back the 'body' response above那只是客户及其语法的崩溃课程概述。如果您熟悉Elasticsearch,您会注意到这些方法的命名就像rebt端点一样。
您还会注意到,客户端的配置方式可以促进通过IDE轻松发现。所有核心操作均在$client对象(索引,搜索,获取等)下可用。索引和集群管理分别位于$client->indices()和$client->cluster()对象下。
查看其余文档,以了解整个客户端的工作原理。
请注意,此项目可在学校环境中使用。要进一步发展,请联系TE
用户可以选择他们希望使用的许可证。由于没有区分可执行文件或分发捆绑包来区分许可,因此用户应在库重新分配的情况下在外部记录其许可证选择。如果没有做出明确的选择,则假设重新分配遵守这两个许可的规则。