承接 amitavroy/laravel-elastic 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

amitavroy/laravel-elastic

Composer 安装命令:

composer require amitavroy/laravel-elastic

包简介

A package to give the ability to index data on Elastic search and allow to searh on individual models.

README 文档

README

This package will allow you to use Elastic search along with your Eloquent models with ease. This package will create individual indexes for each model of your application and using the Eloquent events 'created', 'updated' and 'deleted' this package will keep your Elastic index in sync.

Installation and usage

This package best works with Elastic search 6.0 and above.

To install, you just need to require the package using the following command

composer require amitavroy/laravel-elastic

Setup and configuration

This package comes with a configuration file which you will need to publish and set the host array. This is how the package is going to access the Elastic search instance.

'hosts' => [
    'http://localhost:6200',
],

Also, you can define a prefix to your indexes in case you are using the same Elastic search instance for multiple application.

'prefix' => 'some_prefix_',

Usage

This package provides a trait which you need to add to any Eloquent model that you want to be indexed and searched. And, you need to mention which fields of that model you want to search on. For example, you don't want to store and search the user's password, the remember token or some other sensitive data.

<?php

namespace App;

use Amitav\LaravelElastic\Traits\Searchable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Searchable;

    protected $searchFields = [
        'name', 'address', 'phone'
    ];
}

With this configuration, if a new user is created, the content will get indexed. And the same holds true for update and delete.

Some additional methods which are available with any model using the Searchable traits are:

User::reindex();

This will clear the current Elastic search index created and re-index the entire content.

And the most important method, is the search. On any Eloquent model which is using the Searchable trait, you can perform the following action:

User::search('keyword');

This will return you the Elastic search reponse with data points like the number of hits, the execution time, score and the search results. And, there is another option where you can get the result as a collection by passing a second argument as true.

User::search('keyword', true);

统计信息

  • 总下载量: 36
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固