php meilisearch demo

# 创建一个meilisearch 使用完自动销毁
docker run -itd --rm -p 7700:7700 getmeili/meilisearch:v1.3

docker-compose 参数

version: "3"
networks:
  flyserver:
    driver: bridge
services:
  search:
    image: getmeili/meilisearch:v1.3
    restart: always
    environment:
      - MEILI_MASTER_KEY=masterKey
    ports:
      - "7700:7700"
    networks:
      - flyserver
    user: root
    tty: true


require_once __DIR__ . '/vendor/autoload.php';

use Meilisearch\Client;

$client = new Client('http://127.0.0.1:7700', 'masterKey');

# An index is where the documents are stored.
$index = $client->index('movies');

$documents = [
    ['id' => 1,  'title' => 'Carol', 'genres' => ['Romance, Drama']],
    ['id' => 2,  'title' => 'Wonder Woman', 'genres' => ['Action, Adventure']],
    ['id' => 3,  'title' => 'Life of Pi', 'genres' => ['Adventure, Drama']],
    ['id' => 4,  'title' => 'Mad Max: Fury Road', 'genres' => ['Adventure, Science Fiction']],
    ['id' => 5,  'title' => 'Moana', 'genres' => ['Fantasy, Action']],
    ['id' => 6,  'title' => 'Philadelphia', 'genres' => ['Drama']],
    ["id" => 7, "title" => "fiy", "genres" => ["01","02"]],
    ["id" => 8, "title" => "fiy", "genres" => ["03","04"]],
];

# If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.
$index->addDocuments($documents); // => { "uid": 0 }

$index->updateFilterableAttributes([
    'id',
    'genres'
  ]);

$search = $index->search(
    'fiy',
    [
      'filter' => ['id > 2', "genres = '01'"]
    ]
  );

print_r($search->getHits());

你可能感兴趣的:(php,android,开发语言)