zhuzixian520/yii2-meilisearch This extension provides the MeiliSearch integration for the Yii framework 2.0.

yii2 logo meilisearch logo

MeiliSearch Extension For Yii2 Framework

  1. English | 简体中文 | 繁體中文
  2. Installation
  3. Usage
  4. Contact Us
  5. Sponsorship and donation:

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

English | 简体中文 | 繁體中文

This extension provides the MeiliSearch integration for the Yii framework 2.0.

Installation

The preferred way to install this extension is through composer.

Either run

composer require zhuzixian520/yii2-meilisearch

or add

"zhuzixian520/yii2-meilisearch": "^1.0"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

return [
    'components' => [
        'meilisearch' => [
            'class' => zhuzixian520\meilisearch\Connection::class,
            'hostname' => 'localhost',
            'port' => 7700,
            //'apiKey' => 'your_master_key',
            //'useSSL' => false,
        ],
    ],
];
Work with this component
$ms = \Yii::$app->meilisearch;

// Set API keys From your master Key
$ms->apiKey = 'xxxx';

$msc = $ms->createCommand();

//The health check endpoint enables you to periodically test the health of your Meilisearch instance
$msc->health;
Indexes
//$res = $msc->allIndexes;
//$res = $msc->createIndex('movies', 'id');
//$res = $msc->updateIndex('movies', 'id');
//$res = $msc->deleteIndex('movies');
$msci = $msc->index('movies');
//$res = $msci->info;
//$res = $msci->update('id');
//$res = $msci->delete();
Documents
$res = $msci->getDocument(25684);
$res = $msci->getDocuments(['offset' => 0, 'limit' => 2, 'attributesToRetrieve' => '*']);
/*$file_name = Yii::getAlias('@app/runtime/') . 'movies.json';
$movies_json = file_get_contents($file_name);
$movies = json_decode($movies_json, true);
$res = $msci->addDocuments($movies,'id');*/
//$res = $msci->updateDocuments($movies,'id');
//$res = $msci->deleteAllDocuments();
//$res = $msci->deleteDocument(100);
//$res = $msci->deleteDocuments([10001, 100017]);
Search
$res = $meilisearch->createCommand()->index('movies')->search(['q' => 'saw', 'limit' => 2,]);
var_dump($res);
Task
$res = $msc->tasks;
$res = $msc->getTask(4);
$res = $msci->getTasks();
$res = $msci->getTask(8);
Keys
//$res = $msc->keys;
//$res = $msc->getKey('9bFPJSxkc0e7939d743e110b354fe3625876cfec14efb4301bf195f6aed4a57f1d9004fa');
/*$res = $msc->createKey([
'description' => 'Add documents: Products API key',
'actions' => ['documents.add'],
'indexes' => ['products'],
'expiresAt' => '2042-04-02T00:42:42Z',
]);*/
/*$res = $msc->updateKey('yKEcAaQX547e46c7d8eaa1224f6a5196c5c7a13f47932cbeb1ba06db962b379cb0ef19e4', [
'description' => 'Add documents: Products API key',
'actions' => ['documents.add'],
'indexes' => ['products'],
'expiresAt' => '2043-04-02T00:42:42Z',
]);*/
//$res = $msc->deleteKey('qAZlXnA191d328ea51fb26b822fecc556c38c0a3af1caa95962ede60a0155381a39a3a36');
Settings
$res = $msci->settings;
/*$res = $msci->updateSettings([
'displayedAttributes' => ['*'],
'distinctAttribute' => null,
'filterableAttributes' => [],
'rankingRules' => [
'words',
'typo',
'proximity',
'attribute',
'sort',
'exactness',
'release_date:desc',
'rank:desc'
],
'searchableAttributes' => ['*'],
'sortableAttributes' => [],
'stopWords' => [
'the',
'a',
'an'
],
'synonyms' => [
'wolverine' => ['xmen', 'logan'],
'logan' => ['wolverine']
]
]);*/
//$res = $msci->resetSettings();
//$res = $msci->displayedAttrs;
//$res = $msci->updateDisplayedAttrs(['*']);
//$res = $msci->resetDisplayedAttrs();
/*$res = $msci->distinctAttr;
$res = $msci->updateDistinctAttr('id');
$res = $msci->resetDistinctAttr();
$res = $msci->filterableAttrs;
$res = $msci->updateFilterableAttrs([]);
$res = $msci->resetFilterableAttrs();
$res = $msci->rankingRules;
$res = $msci->updateRankingRules([
'words',
'typo',
'proximity',
'attribute',
'sort',
'exactness',
'release_date:desc',
'rank:desc'
]);
$res = $msci->resetRankingRules();
$res = $msci->searchableAttrs;
$res = $msci->updateSearchableAttrs(['*']);
$res = $msci->resetSearchableAttrs();
$res = $msci->sortableAttrs;
$res = $msci->updateSortableAttrs([]);
$res = $msci->resetSortableAttrs();
$res = $msci->stopWords;
$res = $msci->updateStopWords([
'the',
'a',
'an'
]);
$res = $msci->resetStopWords();
$res = $msci->synonyms;
$res = $msci->updateSynonyms([
'wolverine' => ['xmen', 'logan'],
'logan' => ['wolverine']
]);
$res = $msci->resetSynonyms();*/
Stats
//$res = $msc->stats;
//$res = $msci->stats;
Health
$msc->health;
Version
$msc->version;
Dumps
$res = $msc->createDump();
//$res = $msc->getDumpStatus('20220211-145911299');
var_dump($res);

Contact Us

>Email:zhuzixian520@126.com

Sponsorship and donation:

wepay.jpg alipay.jpg

1 0
1 follower
42 downloads
Yii Version: 2.0
License: MIT
Category: Database
Developed by: zhuzixian520
Created on: Feb 15, 2022
Last updated: 2 years ago
Packagist Profile
Github Repository

Related Extensions