Git Product home page Git Product logo

meilisearch's Introduction

Meilisearch

Meilisearch

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

MeiliSearch是一个功能强大,快速,开源,易于使用和部署的搜索引擎。搜索和索引都是高度可定制的。允许输入、过滤器和同义词等特性都是开箱即用的。是近两年开源的项目,同样也支持中文分词,在小数据规模下可以实现比ElasticSearch更加快速和易用的搜索体验。更多安装、配置、使用等细节请参考官方文档或交友网站

安装

composer require tinywan/meilisearch

使用

初始化配置

$config = [
    'url' => 'http://127.0.0.1:7700',
    'key' => '',
    'guzzle' => [
        'headers' => [
            'charset' => 'UTF-8',
        ],
        'timeout' => 20
    ],
];

// 调用 config 方法初始化
Tinywan\Meilisearch::config($config);

基本使用

1. 创建索引

Tinywan\Meilisearch::search()->index('meilisearch');

2. 添加文档

$documents = [
    ['id' => 1, 'title' => '酒吧墙面装饰美式复古咖啡厅'],
    ['id' => 2, 'title' => '工艺品桌面摆件'],
    ['id' => 3, 'title' => '现代简约三联餐厅壁画玄关挂画'],
    ['id' => 4, 'title' => '现代简约时尚单头餐吊灯创意个性吧台']
];
Tinywan\Meilisearch::search()->index('meilisearch')->addDocuments($documents);

3. 默认查询

Tinywan\Meilisearch::search()->index('meilisearch')->search('桌面摆件')->getRaw();
  • getRaw() 返回数组

返回字段

  • hits 命中的结果
  • offset 页大小
  • limit 每页条数
  • processingTimeMs 处理耗时
  • query 查询的内容

前端集成

demo.png;

数据查询

分页查询

http://172.30.32.1:7700/indexes/mall_goods/search?limit=1&offset=3
http://172.30.32.1:7700/indexes/mall_goods_27_30/search?q=10
  • offset 页大小
  • limit 每页条数

关键字查询

http://172.30.32.1:7700/indexes/mall_goods_27_30/search?q=桌面摆件

数据添加

已经存在的数据

  1. 直接批量添加即可
$documents = Db::table('mall_goods')
    ->field('id,name,default_image')
    ->whereIn('goods_id',[30])
    ->limit(2)
    ->select()
    ->toArray();
Tinywan\Meilisearch::search()->index('meilisearch')->addDocuments($documents);
  1. 新添加的商品,单独添加
$documents = [
    ['id' => 1, 'title' => '酒吧墙面装饰美式复古咖啡厅'],
];
Tinywan\Meilisearch::search()->index('meilisearch')->addDocuments($documents);

Test

vendor/bin/phpstan analyse -l 5 src

vendor/bin/php-cs-fixer fix src

Other

Config

  • ① 配置初始化 Tinywan\Meilisearch::config([])
  • ② 调用构造函数 new self($config, $container)
  • ③ 构造函数注册服务 $this->registerServices($config, $container);
  • ④ 注册服务:核心服务和自定义服务
  • ⑤ 核心服务 ContainerServiceProvider 注册函数register($data) 调用
  • ⑥ 注册函数register($data) 调用PSR11实现的DI依赖注入扩展 DI\ContainerBuilder
  • ⑦ 通过依赖注入扩展 DI\ContainerBuilder 为容器服务ContainerServiceProvider指定容器 MeiliSearch::setContainer($container);
  • ⑧ 通过依赖注入扩展 DI\ContainerBuilder 为当前服务设置容器 MeiliSearch::setContainer($container);
  • ⑨ 获取当前设置的容器 var_dump(MeiliSearch::getContainer()); 获取对象:class DI\Container#101 (8) {}

文件加载

TP6 Container 调用反射执行类的实例化。并不是按照标准的PSR11的容器接口实现的

meilisearch's People

Contributors

tinywan avatar

Stargazers

zhengweidong avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.