PHPackages                             searchology/searchology-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. searchology/searchology-php

ActiveLibrary[Search &amp; Filtering](/categories/search)

searchology/searchology-php
===========================

Official PHP SDK for the Searchology API — turn natural language search queries into structured JSON

v1.0.0(1mo ago)00MITPHPPHP &gt;=8.0

Since Mar 19Pushed 1mo agoCompare

[ Source](https://github.com/thedevabdullah/searchology-php)[ Packagist](https://packagist.org/packages/searchology/searchology-php)[ RSS](/packages/searchology-searchology-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

searchology-php
===============

[](#searchology-php)

Official PHP SDK for the Searchology API — turn natural language search queries into structured JSON.

Instead of building dropdowns and filters, let your users search naturally:

> *"black nike shoes under $80"*

And your app receives clean, structured JSON:

```
{
    "product_type": { "value": "shoes",  "confidence": 1.0  },
    "brand":        { "value": "nike",   "confidence": 1.0  },
    "color":        { "value": "black",  "confidence": 1.0  },
    "price_max":    { "value": 80,       "confidence": 1.0  }
}
```

---

Install
-------

[](#install)

```
composer require searchology/searchology-php
```

---

Quick Start
-----------

[](#quick-start)

There are only **two steps** to using Searchology:

1. Create your API key (once)
2. Call `extract()` with any search query

---

Step 1 — Get Your API Key
-------------------------

[](#step-1--get-your-api-key)

Run this **once**, save the key it gives you.

```
require 'vendor/autoload.php';

use Searchology\Searchology;

$client = new Searchology();
$result = $client->createApiKey('my-laravel-app');

echo $result['key'];
// sgy_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

> **Important:** Your key is only shown once. Save it to your `.env` file before moving on.

---

Step 2 — Extract from any query
-------------------------------

[](#step-2--extract-from-any-query)

```
use Searchology\Searchology;
use Searchology\SearchologyException;

$client = new Searchology([
    'api_key' => 'sgy_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
]);

$data = $client->extract('black t-shirt for my son under $15');

print_r($data['result']);
// [
//   'color'        => ['value' => 'black',   'confidence' => 1.0],
//   'product_type' => ['value' => 't-shirt',  'confidence' => 1.0],
//   'gender'       => ['value' => 'male',     'confidence' => 0.85],
//   'price_max'    => ['value' => 15,         'confidence' => 0.95],
// ]
```

---

Saving Your API Key (Recommended)
---------------------------------

[](#saving-your-api-key-recommended)

Store it in your `.env` file:

```
SEARCHOLOGY_API_KEY=sgy_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

Then use it in PHP:

```
$client = new Searchology([
    'api_key' => $_ENV['SEARCHOLOGY_API_KEY']
]);
```

In Laravel use `env()`:

```
$client = new Searchology([
    'api_key' => env('SEARCHOLOGY_API_KEY')
]);
```

---

Laravel Example — Search Controller
-----------------------------------

[](#laravel-example--search-controller)

```
