I am trying to implement search functionality in my laravel app. Angolia is not preferred by my supervisors due to data security problems. Other than that one good option is to implement elastic search and another is to use full text search from mysql. I am not sure what are the pros and cons and although I have read in a few places that elastic search should be the better alternative, I would like to understand what I am working with since I haven't worked with searching before this.

I am looking at MySQL requirements and it seems I can only implement it with 5.6 or above with InnoDb engine. And other than that I can only implement fulltext indexes on char and text type fields. I am not sure what kind of fields are permitted in Elastic search.

I know I have to something like:

DB::statement('ALTER TABLE posts ADD FULLTEXT search(title, body)');

Then I guess I do something like:

SELECT * FROM posts
WHERE MATCH (title, body)
AGAINST ('foo' IN NATURAL LANGUAGE MODE);

Is there Eloquent implementation for this or do I have to do this manually using the DB facade? If there isn't a Eloquent implementation, are there 3rd party packages with this functionality?

除此之外,我还需要搜索相关的表格,比如 comments 和标签等等.如何在表之间创建索引,还是不可能?如果在MySQL中无法跨表创建索引,那么ES中有什么可以克服的地方吗.

使用MySQL全文搜索与Elastic search 相比,我可能面临的其他利弊是什么?

推荐答案

With MySQL you will always be indexing and searching your data.

使用ElasticSearch,您可以更灵活地将索引作为一个单元.您可以获取一个项目的所有内容、注释和标记,并将其作为一个项目放入ES中.

You'll also likely find that ES will give better performance and better results in general that you would get with mysql. You also have more flexibility with things like synonyms and weighting.

But it does mean you have another stack to maintain and you have to manage indexing and updating of content.

因此,这将取决于您的数据大小和将搜索作为一项功能的重要性.

I would suggest that you start with MySql text search, as in a simple case it will be quick to set up and if this does not provide what you need then upgrade to elastic search. You will at least have a straw man feature which can be used to further refine your search requirements.

Laravel相关问答推荐

Nginx上带有SSL的Laravel混响

如何在 Laravel 9 中获取带分页的订单列表?

如何将用户对象绑定到中间件中的请求

在 apache docker 容器中运行虚拟主机

如何使用 ajax 请求删除 laravel 5.3 中的记录?

如何比较laravel中的两个加密(bcrypt)密码

设置 Laravel 5.4 以使用 React

在 Laravel 容器中覆盖单例

Auth 在 Laravel Tinker 中不起作用

Laravel/Lumen 中两列之间的 SQL

Laravel Eloquent - 加入表时防止覆盖值

在 Laravel 应用程序中在哪里指定应用程序版本?

在 Laravel 的数据透视表中添加 id 列有什么好处?

Laravel 获取查询字符串

今天之前的 Laravel 规则......怎么办

Eloquent - 带有字符串值而不是列标题的连接子句

Laravel 4 简单路由无法使用 mod_rewrite 和 .htaccess

如何在 Laravel 中动态更改 .env 文件中的变量?

Laravel 中的 isDirty() 是什么意思?

phpunit 命令不适用于 Windows 7 上的 laravel 4