matsevh/matsevhsearch

一个轻量级的底层HTTP客户端,用于与MatseVHSearch的API交互

1.0.1 2022-08-31 17:57 UTC

This package is auto-updated.

Last update: 2024-09-29 06:25:53 UTC


README

在您的PHP项目中集成MatseVHSearch的完美起点

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

✨ 特性

  • 一个轻量级的底层HTTP客户端,用于与MatseVHSearch的API交互
  • 支持php >=7.4

💡 入门

首先,通过composer包管理器安装MatseVHSearch PHP API客户端

composer require matsevh/matsevhsearch

然后您可以在项目中使用它

// Require the autoloader from the composer
require_once 'vendor/autoload.php';

// Use the MatseVHSearch PHP API Client
use MatseVH\MatseVHSearch\SearchClient;

// Instantiate the client
$client = new SearchClient('<application_id>', '<api_key>');

// Add the function you want to use (You can find the function below)

功能

推送

// Push some data to the index -> products
// It doesn't matter if the data is already in the index
// The already existing data will be deleted and replaced by the new data
// You can push a PHP array or a JSON string array
$php = array(
    array(
        'objectID' => '1',
        'title' => 'My first object',
        'description' => 'This is my first object',
        'price' => '10.00',
        'currency' => 'EUR',
        'image' => 'https://example.com/image.jpg',
        'url' => 'https://example.com/product/1',
        'brand' => 'My brand',
        'category' => 'My category',
        'tags' => array('tag1', 'tag2'),
        'attributes' => array(
            'attribute1' => 'value1',
            'attribute2' => 'value2'
        )
    ),
    array(
        'objectID' => '2',
        'title' => 'My second object',
        'description' => 'This is my second object',
        'price' => '20.00',
        'currency' => 'EUR',
        'image' => 'https://example.com/image.jpg',
        'url' => 'https://example.com/product/2',
        'brand' => 'My brand',
        'category' => 'My category',
        'tags' => array('tag1', 'tag2'),
        'attributes' => array(
            'attribute1' => 'value1',
            'attribute2' => 'value2'
        )
    )
);

// In json format it would look like this:
$json = '[
          {
            "objectID":"1",
            "title":"My first object",
            "description":"This is my first object",
            "price":"10.00",
            "currency":"EUR",
            "image":"https://example.com/image.jpg",
            "url":"https://example.com/product/1",
            "brand":"My brand",
            "category":"My category",
            "tags":["tag1","tag2"],
            "attributes":{
              "attribute1":"value1",
              "attribute2":"value2"
            }
          },
          {
            "objectID":"2",
            "title":"My second object",
            "description":"This is my second object",
            "price":"20.00",
            "currency":"EUR",
            "image":"https://example.com/image.jpg",
            "url":"https://example.com/product/2",
            "brand":"My brand",
            "category":"My category",
            "tags":["tag1","tag2"],
            "attributes":{
              "attribute1":"value1",
              "attribute2":"value2"
            }
          }
        ]';

// Push the data to the index -> products
$client->push('products', $php); // or $client->push('products', $json);

搜索

// Search for products
$results = $client->search('products', 'My first object');

获取

// Get all the pushed data from the index -> products
$results = $client->get('products');

反转

// Get all the pushed data reversed from the index -> products
$results = $client->reverse('products');

随机

// Get all the pushed data in random order from the index -> products
$results = $client->random('products');

需要帮助?请通过电子邮件联系我: matse@vanhorebeek.be

📄 许可证

MatseVHSearch PHP API客户端是一个开源软件,许可协议为MIT许可证