From 307bda6e529b33cda2ed3190c950ba6756c7f969 Mon Sep 17 00:00:00 2001 From: Omar Rida Date: Tue, 13 Aug 2024 21:54:28 +0300 Subject: [PATCH 1/3] Install typesense and update index. --- .env.example | 9 +- app/Package.php | 14 +- composer.json | 3 +- composer.lock | 462 +++++++++++++++++++++++++++++++++++++++++++++-- config/scout.php | 46 +++++ 5 files changed, 510 insertions(+), 24 deletions(-) diff --git a/.env.example b/.env.example index 360edb08..bdadb14f 100644 --- a/.env.example +++ b/.env.example @@ -49,9 +49,12 @@ GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= GITHUB_CALLBACK_URL=http://novapackages.test/login/github/callback -SCOUT_DRIVER=algolia -ALGOLIA_APP_ID= -ALGOLIA_SECRET= +SCOUT_DRIVER=typesense +SCOUT_PREFIX= +TYPESENSE_API_KEY= +TYPESENSE_HOST= +TYPESENSE_PORT= +TYPESENSE_PROTOCOL= HONEYBADGER_API_KEY= diff --git a/app/Package.php b/app/Package.php index af84dafa..f5949b45 100644 --- a/app/Package.php +++ b/app/Package.php @@ -119,6 +119,7 @@ public function toSearchableArray() // Temporarily truncate to prevent algolia from throwing a size exceeded exception $packageAttributes['readme'] = substr($packageAttributes['readme'], 0, 500); $packageAttributes['instructions'] = substr($packageAttributes['instructions'], 0, 500); + $packageAttributes['created_at'] = $this->created_at->timestamp; Arr::forget($packageAttributes, $this->excludeFromSearchIndex); @@ -126,7 +127,18 @@ public function toSearchableArray() // @todo Make sure this is updated when tags are updated $packageAttributes['_tags'] = $this->tags->pluck('slug')->toArray(); - return $packageAttributes; + return [ + 'id' => (string) $packageAttributes['id'], + 'name' => (string) $packageAttributes['name'], + 'url' => (string) $packageAttributes['url'], + 'instructions' => (string) $packageAttributes['instructions'], + 'composer_name' => (string) $packageAttributes['composer_name'], + 'repo_url' => (string) $packageAttributes['repo_url'], + 'readme' => (string) $packageAttributes['readme'], + 'abstract' => (string) $packageAttributes['abstract'], + '_tags' => $packageAttributes['_tags'], + 'created_at' => $packageAttributes['created_at'], + ]; } protected static function booted() diff --git a/composer.json b/composer.json index 98381dc1..1340bde5 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "laravel/helpers": "^1.6", "laravel/horizon": "^5.12", "laravel/passport": "^11.5", - "laravel/scout": "^9.8", + "laravel/scout": "^v10.7.0", "laravel/slack-notification-channel": "^2.5", "laravel/socialite": "^5.6", "laravel/telescope": "^4.12", @@ -35,6 +35,7 @@ "spatie/laravel-sitemap": "^6.2", "stil/gd-text": "^1.1", "tightenco/ziggy": "^2.0", + "typesense/typesense-php": "^4.9", "willvincent/laravel-rateable": "^3.1" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 5b17f628..fbb45605 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "879c1c2aa2d670dc93e15f01e67bbeb4", + "content-hash": "f517b7e3187863041ba7a89218b3d0f3", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -544,6 +544,72 @@ ], "time": "2023-12-11T17:09:12+00:00" }, + { + "name": "clue/stream-filter", + "version": "v1.7.0", + "source": { + "type": "git", + "url": "https://github.com/clue/stream-filter.git", + "reference": "049509fef80032cb3f051595029ab75b49a3c2f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/clue/stream-filter/zipball/049509fef80032cb3f051595029ab75b49a3c2f7", + "reference": "049509fef80032cb3f051595029ab75b49a3c2f7", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "Clue\\StreamFilter\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering" + } + ], + "description": "A simple and modern approach to stream filtering in PHP", + "homepage": "https://github.com/clue/stream-filter", + "keywords": [ + "bucket brigade", + "callback", + "filter", + "php_user_filter", + "stream", + "stream_filter_append", + "stream_filter_register" + ], + "support": { + "issues": "https://github.com/clue/stream-filter/issues", + "source": "https://github.com/clue/stream-filter/tree/v1.7.0" + }, + "funding": [ + { + "url": "https://clue.engineering/support", + "type": "custom" + }, + { + "url": "https://github.com/clue", + "type": "github" + } + ], + "time": "2023-12-20T15:40:13+00:00" + }, { "name": "composer/ca-bundle", "version": "1.5.1", @@ -2624,43 +2690,48 @@ }, { "name": "laravel/scout", - "version": "v9.8.1", + "version": "v10.11.1", "source": { "type": "git", "url": "https://github.com/laravel/scout.git", - "reference": "38595717b396ce733d432b82e3225fa4e0d6c8ef" + "reference": "b31056d49ae0540a475947391d7ea8617d779aee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/scout/zipball/38595717b396ce733d432b82e3225fa4e0d6c8ef", - "reference": "38595717b396ce733d432b82e3225fa4e0d6c8ef", + "url": "https://api.github.com/repos/laravel/scout/zipball/b31056d49ae0540a475947391d7ea8617d779aee", + "reference": "b31056d49ae0540a475947391d7ea8617d779aee", "shasum": "" }, "require": { - "illuminate/bus": "^8.0|^9.0|^10.0", - "illuminate/contracts": "^8.0|^9.0|^10.0", - "illuminate/database": "^8.0|^9.0|^10.0", - "illuminate/http": "^8.0|^9.0|^10.0", - "illuminate/pagination": "^8.0|^9.0|^10.0", - "illuminate/queue": "^8.0|^9.0|^10.0", - "illuminate/support": "^8.0|^9.0|^10.0", - "php": "^7.3|^8.0" + "illuminate/bus": "^9.0|^10.0|^11.0", + "illuminate/contracts": "^9.0|^10.0|^11.0", + "illuminate/database": "^9.0|^10.0|^11.0", + "illuminate/http": "^9.0|^10.0|^11.0", + "illuminate/pagination": "^9.0|^10.0|^11.0", + "illuminate/queue": "^9.0|^10.0|^11.0", + "illuminate/support": "^9.0|^10.0|^11.0", + "php": "^8.0", + "symfony/console": "^6.0|^7.0" }, "require-dev": { - "meilisearch/meilisearch-php": "^0.19", + "algolia/algoliasearch-client-php": "^3.2", + "meilisearch/meilisearch-php": "^1.0", "mockery/mockery": "^1.0", - "orchestra/testbench": "^6.17|^7.0|^8.0", + "orchestra/testbench": "^7.31|^8.11|^9.0", "php-http/guzzle7-adapter": "^1.0", - "phpunit/phpunit": "^9.3" + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.3|^10.4", + "typesense/typesense-php": "^4.9.3" }, "suggest": { "algolia/algoliasearch-client-php": "Required to use the Algolia engine (^3.2).", - "meilisearch/meilisearch-php": "Required to use the MeiliSearch engine (^0.23)." + "meilisearch/meilisearch-php": "Required to use the Meilisearch engine (^1.0).", + "typesense/typesense-php": "Required to use the Typesense engine (^4.9)." }, "type": "library", "extra": { "branch-alias": { - "dev-master": "9.x-dev" + "dev-master": "10.x-dev" }, "laravel": { "providers": [ @@ -2693,7 +2764,7 @@ "issues": "https://github.com/laravel/scout/issues", "source": "https://github.com/laravel/scout" }, - "time": "2023-02-14T16:53:14+00:00" + "time": "2024-08-06T15:13:57+00:00" }, { "name": "laravel/serializable-closure", @@ -5061,6 +5132,154 @@ }, "time": "2020-10-15T08:29:30+00:00" }, + { + "name": "php-http/client-common", + "version": "2.7.1", + "source": { + "type": "git", + "url": "https://github.com/php-http/client-common.git", + "reference": "1e19c059b0e4d5f717bf5d524d616165aeab0612" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/client-common/zipball/1e19c059b0e4d5f717bf5d524d616165aeab0612", + "reference": "1e19c059b0e4d5f717bf5d524d616165aeab0612", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0", + "php-http/httplug": "^2.0", + "php-http/message": "^1.6", + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0 || ^2.0", + "symfony/options-resolver": "~4.0.15 || ~4.1.9 || ^4.2.1 || ^5.0 || ^6.0 || ^7.0", + "symfony/polyfill-php80": "^1.17" + }, + "require-dev": { + "doctrine/instantiator": "^1.1", + "guzzlehttp/psr7": "^1.4", + "nyholm/psr7": "^1.2", + "phpspec/phpspec": "^5.1 || ^6.3 || ^7.1", + "phpspec/prophecy": "^1.10.2", + "phpunit/phpunit": "^7.5.20 || ^8.5.33 || ^9.6.7" + }, + "suggest": { + "ext-json": "To detect JSON responses with the ContentTypePlugin", + "ext-libxml": "To detect XML responses with the ContentTypePlugin", + "php-http/cache-plugin": "PSR-6 Cache plugin", + "php-http/logger-plugin": "PSR-3 Logger plugin", + "php-http/stopwatch-plugin": "Symfony Stopwatch plugin" + }, + "type": "library", + "autoload": { + "psr-4": { + "Http\\Client\\Common\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + } + ], + "description": "Common HTTP Client implementations and tools for HTTPlug", + "homepage": "http://httplug.io", + "keywords": [ + "client", + "common", + "http", + "httplug" + ], + "support": { + "issues": "https://github.com/php-http/client-common/issues", + "source": "https://github.com/php-http/client-common/tree/2.7.1" + }, + "time": "2023-11-30T10:31:25+00:00" + }, + { + "name": "php-http/discovery", + "version": "1.19.4", + "source": { + "type": "git", + "url": "https://github.com/php-http/discovery.git", + "reference": "0700efda8d7526335132360167315fdab3aeb599" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/discovery/zipball/0700efda8d7526335132360167315fdab3aeb599", + "reference": "0700efda8d7526335132360167315fdab3aeb599", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0|^2.0", + "php": "^7.1 || ^8.0" + }, + "conflict": { + "nyholm/psr7": "<1.0", + "zendframework/zend-diactoros": "*" + }, + "provide": { + "php-http/async-client-implementation": "*", + "php-http/client-implementation": "*", + "psr/http-client-implementation": "*", + "psr/http-factory-implementation": "*", + "psr/http-message-implementation": "*" + }, + "require-dev": { + "composer/composer": "^1.0.2|^2.0", + "graham-campbell/phpspec-skip-example-extension": "^5.0", + "php-http/httplug": "^1.0 || ^2.0", + "php-http/message-factory": "^1.0", + "phpspec/phpspec": "^5.1 || ^6.1 || ^7.3", + "sebastian/comparator": "^3.0.5 || ^4.0.8", + "symfony/phpunit-bridge": "^6.4.4 || ^7.0.1" + }, + "type": "composer-plugin", + "extra": { + "class": "Http\\Discovery\\Composer\\Plugin", + "plugin-optional": true + }, + "autoload": { + "psr-4": { + "Http\\Discovery\\": "src/" + }, + "exclude-from-classmap": [ + "src/Composer/Plugin.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + } + ], + "description": "Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations", + "homepage": "http://php-http.org", + "keywords": [ + "adapter", + "client", + "discovery", + "factory", + "http", + "message", + "psr17", + "psr7" + ], + "support": { + "issues": "https://github.com/php-http/discovery/issues", + "source": "https://github.com/php-http/discovery/tree/1.19.4" + }, + "time": "2024-03-29T13:00:05+00:00" + }, { "name": "php-http/guzzle7-adapter", "version": "1.0.0", @@ -5180,6 +5399,75 @@ }, "time": "2023-04-14T15:10:03+00:00" }, + { + "name": "php-http/message", + "version": "1.16.1", + "source": { + "type": "git", + "url": "https://github.com/php-http/message.git", + "reference": "5997f3289332c699fa2545c427826272498a2088" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/message/zipball/5997f3289332c699fa2545c427826272498a2088", + "reference": "5997f3289332c699fa2545c427826272498a2088", + "shasum": "" + }, + "require": { + "clue/stream-filter": "^1.5", + "php": "^7.2 || ^8.0", + "psr/http-message": "^1.1 || ^2.0" + }, + "provide": { + "php-http/message-factory-implementation": "1.0" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.6", + "ext-zlib": "*", + "guzzlehttp/psr7": "^1.0 || ^2.0", + "laminas/laminas-diactoros": "^2.0 || ^3.0", + "php-http/message-factory": "^1.0.2", + "phpspec/phpspec": "^5.1 || ^6.3 || ^7.1", + "slim/slim": "^3.0" + }, + "suggest": { + "ext-zlib": "Used with compressor/decompressor streams", + "guzzlehttp/psr7": "Used with Guzzle PSR-7 Factories", + "laminas/laminas-diactoros": "Used with Diactoros Factories", + "slim/slim": "Used with Slim Framework PSR-7 implementation" + }, + "type": "library", + "autoload": { + "files": [ + "src/filters.php" + ], + "psr-4": { + "Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + } + ], + "description": "HTTP Message related tools", + "homepage": "http://php-http.org", + "keywords": [ + "http", + "message", + "psr-7" + ], + "support": { + "issues": "https://github.com/php-http/message/issues", + "source": "https://github.com/php-http/message/tree/1.16.1" + }, + "time": "2024-03-07T13:22:09+00:00" + }, { "name": "php-http/promise", "version": "1.3.1", @@ -8216,6 +8504,73 @@ ], "time": "2024-06-28T09:49:33+00:00" }, + { + "name": "symfony/options-resolver", + "version": "v6.4.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/options-resolver.git", + "reference": "22ab9e9101ab18de37839074f8a1197f55590c1b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/22ab9e9101ab18de37839074f8a1197f55590c1b", + "reference": "22ab9e9101ab18de37839074f8a1197f55590c1b", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.5|^3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\OptionsResolver\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an improved replacement for the array_replace PHP function", + "homepage": "https://symfony.com", + "keywords": [ + "config", + "configuration", + "options" + ], + "support": { + "source": "https://github.com/symfony/options-resolver/tree/v6.4.8" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-05-31T14:49:08+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.30.0", @@ -9783,6 +10138,75 @@ }, "time": "2023-12-08T13:03:43+00:00" }, + { + "name": "typesense/typesense-php", + "version": "v4.9.3", + "source": { + "type": "git", + "url": "https://github.com/typesense/typesense-php.git", + "reference": "50fc2089ff4829c8e0e11d8c674e9da085b49998" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/typesense/typesense-php/zipball/50fc2089ff4829c8e0e11d8c674e9da085b49998", + "reference": "50fc2089ff4829c8e0e11d8c674e9da085b49998", + "shasum": "" + }, + "require": { + "ext-json": "*", + "monolog/monolog": "^2.1 || ^3.0 || ^3.3", + "nyholm/psr7": "^1.3", + "php": ">=7.4", + "php-http/client-common": "^1.0 || ^2.3", + "php-http/discovery": "^1.0", + "php-http/httplug": "^1.0 || ^2.2", + "psr/http-client-implementation": "^1.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "require-dev": { + "squizlabs/php_codesniffer": "3.*", + "symfony/http-client": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Typesense\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Typesense", + "email": "contact@typesense.org", + "homepage": "https://typesense.org", + "role": "Developer" + }, + { + "name": "Abdullah Al-Faqeir", + "email": "abdullah@devloops.net", + "homepage": "https://www.devloops.net", + "role": "Developer" + } + ], + "description": "PHP client for Typesense Search Server: https://github.com/typesense/typesense", + "homepage": "https://github.com/typesense/typesense-php", + "support": { + "docs": "https://typesense.org/api", + "issues": "https://github.com/typesense/typesense-php/issues", + "source": "https://github.com/typesense/typesense-php" + }, + "funding": [ + { + "url": "https://github.com/typesense", + "type": "github" + } + ], + "time": "2024-04-29T15:34:34+00:00" + }, { "name": "vlucas/phpdotenv", "version": "v5.6.1", diff --git a/config/scout.php b/config/scout.php index d8f0f3bb..56179936 100644 --- a/config/scout.php +++ b/config/scout.php @@ -1,5 +1,7 @@ env('ALGOLIA_SECRET', ''), ], + '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' => [ + Package::class => [ + 'collection-schema' => [ + 'fields' => [ + ['name' => 'id', 'type' => 'string'], + ['name' => 'name', 'type' => 'string'], + ['name' => 'url', 'type' => 'string'], + ['name' => 'instructions', 'type' => 'string'], + ['name' => 'composer_name', 'type' => 'string'], + ['name' => 'repo_url', 'type' => 'string'], + ['name' => 'readme', 'type' => 'string'], + ['name' => 'abstract', 'type' => 'string'], + ['name' => '_tags', 'type' => 'string[]'], + ['name' => 'created_at', 'type' => 'int64'], + ], + ], + 'search-parameters' => [ + 'query_by' => 'name,composer_name,instructions,readme,abstract,url,repo_url', + ], + ], + ], + ] ]; From 2225e48272293752090174b36bc9210623603e79 Mon Sep 17 00:00:00 2001 From: Omar Rida Date: Tue, 13 Aug 2024 22:15:13 +0300 Subject: [PATCH 2/3] add fallback to pass test cases --- app/Package.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/Package.php b/app/Package.php index f5949b45..4148dded 100644 --- a/app/Package.php +++ b/app/Package.php @@ -129,14 +129,14 @@ public function toSearchableArray() return [ 'id' => (string) $packageAttributes['id'], - 'name' => (string) $packageAttributes['name'], - 'url' => (string) $packageAttributes['url'], - 'instructions' => (string) $packageAttributes['instructions'], - 'composer_name' => (string) $packageAttributes['composer_name'], - 'repo_url' => (string) $packageAttributes['repo_url'], - 'readme' => (string) $packageAttributes['readme'], - 'abstract' => (string) $packageAttributes['abstract'], - '_tags' => $packageAttributes['_tags'], + 'name' => (string) ($packageAttributes['name'] ?? ''), + 'url' => (string) ($packageAttributes['url'] ?? ''), + 'instructions' => (string) ($packageAttributes['instructions'] ?? ''), + 'composer_name' => (string) ($packageAttributes['composer_name'] ?? ''), + 'repo_url' => (string) ($packageAttributes['repo_url'] ?? ''), + 'readme' => (string) ($packageAttributes['readme'] ?? ''), + 'abstract' => (string) ($packageAttributes['abstract'] ?? ''), + '_tags' => ($packageAttributes['_tags'] ?? []), 'created_at' => $packageAttributes['created_at'], ]; } From 895cbf36cab801aa26e1fa3a8db48d7295ec2545 Mon Sep 17 00:00:00 2001 From: Omar Rida Date: Wed, 14 Aug 2024 07:56:02 +0300 Subject: [PATCH 3/3] remove algolia branding --- resources/views/livewire/partials/search.blade.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/resources/views/livewire/partials/search.blade.php b/resources/views/livewire/partials/search.blade.php index 5fbd74e6..38d952e1 100644 --- a/resources/views/livewire/partials/search.blade.php +++ b/resources/views/livewire/partials/search.blade.php @@ -1,8 +1,3 @@
-
- - Search by algolia - -