Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught PHP Exception JsonException: "Syntax error" at /home/exceloid/OFC-ECOM/organic-api/vendor/typesense/typesense-php/src/ApiCall.php line 236 #52

Open
avinashingoleexceloid opened this issue Dec 7, 2023 · 1 comment

Comments

@avinashingoleexceloid
Copy link

avinashingoleexceloid commented Dec 7, 2023

## Description

<!--- Describe the issue here -->
Im trying to integrate typesense in my symfony application  for that i have written below   code


TypesenseService.php

<?php

namespace App\Service;

use Typesense\Client;

class TypesenseService
{
    private $typesenseClient;

    public function __construct()
    {
        $this->typesenseClient = new Client([
            'api_key' => 'exceloid-test',
            'nodes' => [
                [
                    'host' => '95.216.171.30',
                    'port' => '8092',
                    'protocol' => 'http',
                ],
            ],
            'connection_timeout_seconds' => 2,
        ]);
    }

    public function getTypesenseClient(): Client
    {
        return $this->typesenseClient;
    }
}

Productservice.php

<?php

namespace App\Service;
use Psr\Log\LoggerInterface;

class ProductService
{
    private $typesenseService;
    private $logger;


    public function __construct(TypesenseService $typesenseService, LoggerInterface $logger)
    {
        $this->typesenseService = $typesenseService;
        $this->logger = $logger;

    }

    public function getProducts(): array
    {
        $typesenseClient = $this->typesenseService->getTypesenseClient();

        $searchParameters = [
            'q' => 'banana',
            'query_by' => 'shortName'
        ];

        $searchResults = $typesenseClient->collections['Ofcproducts']->documents->search($searchParameters);

        $products = [];
        foreach ($searchResults['hits'] as $hit) {
            $document = $hit['document'];    
            unset($document['document']);
            $products[] = $document;
        }
    
        return $products;
        // return $searchResults['hits'];
    }

}



and when im trying to call this function in any controller 

        $typesenseProducts = $this->productService->getProducts();
im getting below error

Uncaught PHP Exception JsonException: "Syntax error" at /home/exceloid/OFC-ECOM/organic-api/vendor/typesense/typesense-php/src/ApiCall.php line 236


till 3 dec 2023 it was working fine ,but now getting syntax error  from library
an someone pls help me



**Typesense Version**:4.8 or 4.9

**OS**: ubuntu

@AbdullahFaqeir
Copy link
Collaborator

Hi @avinashingoleexceloid,

Just to make sure as no one else reported the issue, are you still facing this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants