magiclegacy/search-client

Search Client for magic card in ElasticSearch engine

1.0.0 2021-11-17 23:37 UTC

This package is auto-updated.

Last update: 2024-04-18 05:02:20 UTC


README

Current version Supported PHP version Coverage Quality Gate Status CI

Search Client for magic card in ElasticSearch engine

Supported search (related to Atomic Card from mtgjson.org, with some minor field renaming):

  • /atomic/_search: ElasticSearch index with name atomic for all atomics cards

Composer

composer require magiclegacy/search-client

Usage in application

<?php
namespace Application;

use MagicLegacy\Component\Search\Client\SearchClient;
use Eureka\Component\Curl;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Log\NullLogger;

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

//~ Declare tier required services (included as dependencies)
$httpFactory  = new Psr17Factory();
$searchClient = new SearchClient(
    new Curl\HttpClient(),
    $httpFactory,
    $httpFactory,
    $httpFactory,
    new NullLogger()
);

$cards = $searchClient->searchAtomicCards('name:llanowar types:creature power:1 OR power:2');

foreach ($cards as $card) {

    echo (string) $card->getName() . ' - ' . $card->getPower() . '/' . $card->getToughness() . PHP_EOL;
}

see: example.php

The output will be:

Llanowar Cavalry - 1/4
Llanowar Druid - 1/2
Llanowar Elite - 1/1
Llanowar Elves - 1/1
Llanowar Mentor - 1/1
Llanowar Scout - 1/3
Llanowar Vanguard - 1/1
Llanowar Dead - 2/2
Llanowar Empath - 2/2
Llanowar Knight - 2/2

SearchClient

About Atomic Cards

Available methods:

  • SearchClient::searchAtomicCards(): AtomicCard[]