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

[10.x] Add Typesense engine #773

Merged
merged 37 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f725d5a
Integrate Typesense
karakhanyans Oct 3, 2023
36d87a3
Changes for Scout
arayiksmbatyan Oct 5, 2023
6a1b0f5
Add search options
arayiksmbatyan Oct 6, 2023
dde5183
Add Unit tests
arayiksmbatyan Oct 11, 2023
86ee37d
Rename search options and remove Index Response class
arayiksmbatyan Oct 16, 2023
813d5d8
Code style fixes
karakhanyans Oct 17, 2023
e2d85e7
Typesense Engine Style Fixes
karakhanyans Oct 17, 2023
a40b8d0
Trailing Comma Style Changes
karakhanyans Oct 17, 2023
1e8a338
Code Doc Spaces
karakhanyans Oct 17, 2023
6a617a3
Code Doc Spaces
karakhanyans Oct 17, 2023
b7c72c9
Add DocBlocks to all methods
karakhanyans Oct 19, 2023
737b3c9
Add dots to all comments
karakhanyans Oct 19, 2023
c54cfdd
formatting
taylorotwell Oct 26, 2023
620c746
formatting
taylorotwell Oct 26, 2023
3bd194a
Add default configs
karakhanyans Nov 9, 2023
16a52dd
Formatting
karakhanyans Nov 9, 2023
beb2e67
Formatting
karakhanyans Nov 9, 2023
76a872a
Remove unnecessary empty line
karakhanyans Nov 9, 2023
e0264c0
Change Mapping
karakhanyans Nov 9, 2023
18d08f6
Config Params
karakhanyans Nov 9, 2023
e875e90
Typesense Collection Settings: Query Params
karakhanyans Nov 10, 2023
4fa5bf8
Formatting
karakhanyans Nov 10, 2023
a4d05ed
Formatting
karakhanyans Nov 10, 2023
47727a8
Rename methods and parameters
karakhanyans Nov 10, 2023
a5e702a
Query By As String
karakhanyans Nov 10, 2023
1f853a0
formatting
taylorotwell Nov 28, 2023
8f2229c
Use Typsense v4.8
karakhanyans Dec 5, 2023
41bd8ae
Use Typsense v4.9
karakhanyans Dec 5, 2023
72baa83
Use Typsense v4.9
karakhanyans Dec 5, 2023
908dfd7
Update Suggestion
karakhanyans Dec 5, 2023
9223c63
fix bug
taylorotwell Dec 13, 2023
47ea220
Typesense Engine -> Update Method Changes
karakhanyans Dec 29, 2023
b8d4678
Typesense Engine -> Update Method Changes:Tests
karakhanyans Dec 29, 2023
0808e2c
Tests for With/Only Trashed Methods
karakhanyans Jan 5, 2024
304505d
Tests for With/Only Trashed Methods Changes
karakhanyans Jan 5, 2024
c51222f
formatting
taylorotwell Jan 7, 2024
f05dcef
remove link
taylorotwell Jan 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"require-dev": {
"algolia/algoliasearch-client-php": "^3.2",
"typesense/typesense-php": "^4.9",
"meilisearch/meilisearch-php": "^1.0",
"mockery/mockery": "^1.0",
"orchestra/testbench": "^7.0|^8.0",
Expand Down Expand Up @@ -54,7 +55,8 @@
},
"suggest": {
"algolia/algoliasearch-client-php": "Required to use the Algolia engine (^3.2).",
"meilisearch/meilisearch-php": "Required to use the Meilisearch engine (^1.0)."
"meilisearch/meilisearch-php": "Required to use the Meilisearch engine (^1.0).",
"typesense/typesense-php": "Required to use the Typesense engine (^4.9)."
},
"config": {
"sort-packages": true,
Expand Down
62 changes: 61 additions & 1 deletion config/scout.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
| using Laravel Scout. This connection is used when syncing all models
| to the search service. You should adjust this based on your needs.
|
| Supported: "algolia", "meilisearch", "database", "collection", "null"
| Supported: "algolia", "meilisearch", "typesense",
| "database", "collection", "null"
|
*/

Expand Down Expand Up @@ -139,4 +140,63 @@
],
],

/*
|--------------------------------------------------------------------------
| Typesense Configuration
|--------------------------------------------------------------------------
|
| Here you may configure your Typesense settings. Typesense is an open
| source search engine using minimal configuration. Below, you will
| state the host, key, and schema configuration for the instance.
|
*/

'typesense' => [
'client-settings' => [
'api_key' => env('TYPESENSE_API_KEY', 'xyz'),
'nodes' => [
[
'host' => env('TYPESENSE_HOST', 'localhost'),
'port' => env('TYPESENSE_PORT', '8108'),
'path' => env('TYPESENSE_PATH', ''),
'protocol' => env('TYPESENSE_PROTOCOL', 'http'),
],
],
'nearest_node' => [
'host' => env('TYPESENSE_HOST', 'localhost'),
'port' => env('TYPESENSE_PORT', '8108'),
'path' => env('TYPESENSE_PATH', ''),
'protocol' => env('TYPESENSE_PROTOCOL', 'http'),
],
'connection_timeout_seconds' => env('TYPESENSE_CONNECTION_TIMEOUT_SECONDS', 2),
'healthcheck_interval_seconds' => env('TYPESENSE_HEALTHCHECK_INTERVAL_SECONDS', 30),
'num_retries' => env('TYPESENSE_NUM_RETRIES', 3),
'retry_interval_seconds' => env('TYPESENSE_RETRY_INTERVAL_SECONDS', 1),
],
'model-settings' => [
// User::class => [
// 'collection-schema' => [
// 'fields' => [
// [
// 'name' => 'id',
// 'type' => 'string',
// ],
// [
// 'name' => 'name',
// 'type' => 'string',
// ],
// [
// 'name' => 'created_at',
// 'type' => 'int64',
// ],
// ],
// 'default_sorting_field' => 'created_at',
// ],
// 'search-parameters' => [
// 'query_by' => 'name'
// ],
// ],
],
],

];
30 changes: 30 additions & 0 deletions src/EngineManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
use Laravel\Scout\Engines\DatabaseEngine;
use Laravel\Scout\Engines\MeilisearchEngine;
use Laravel\Scout\Engines\NullEngine;
use Laravel\Scout\Engines\TypesenseEngine;
use Meilisearch\Client as MeilisearchClient;
use Meilisearch\Meilisearch;
use Typesense\Client as Typesense;

class EngineManager extends Manager
{
Expand Down Expand Up @@ -138,6 +140,34 @@ protected function ensureMeilisearchClientIsInstalled()
throw new Exception('Please install the suggested Meilisearch client: meilisearch/meilisearch-php.');
}

/**
* Create a Typesense engine instance.
*
* @return \Laravel\Scout\Engines\TypesenseEngine
*
* @throws \Typesense\Exceptions\ConfigError
*/
public function createTypesenseDriver()
{
$this->ensureTypesenseClientIsInstalled();

return new TypesenseEngine(new Typesense(config('scout.typesense.client-settings')));
}

/**
* Ensure the Typesense client is installed.
*
* @return void
*
* @throws Exception
*/
protected function ensureTypesenseClientIsInstalled()
{
if (! class_exists(Typesense::class)) {
throw new Exception('Please install the suggested Typesense client: typesense/typesense-php.');
}
}

/**
* Create a database engine instance.
*
Expand Down
Loading