PHP code example of tinywan / meilisearch

1. Go to this page and download the library: Download tinywan/meilisearch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tinywan / meilisearch example snippets


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

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

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

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

Tinywan\Meilisearch::search()->index('meilisearch')->search('桌面摆件')->getRaw();

$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);

$documents = [
    ['id' => 1, 'title' => '酒吧墙面装饰美式复古咖啡厅'],
];
Tinywan\Meilisearch::search()->index('meilisearch')->addDocuments($documents);
regexp
vendor/bin/phpstan analyse -l 5 src

vendor/bin/php-cs-fixer fix src

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

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