From 24edc6f70474582faade7ca34c75f97414929ffc Mon Sep 17 00:00:00 2001 From: soufiane Date: Tue, 16 Sep 2025 15:35:32 +0200 Subject: [PATCH] wait #7718 @17:00 --- app/Http/Controllers/Controller.php | 35 ++++- app/PhpVars.php | 8 +- resources/js/app.js | 2 +- .../js/components/FileSearch/FileHit.vue | 38 ----- .../FileSearch/FileInstantSearch.vue | 130 +++++++++++------- resources/js/components/FileSearch/Search.vue | 33 +---- resources/sass/_ais.scss | 31 ++++- routes/web.php | 2 +- 8 files changed, 147 insertions(+), 132 deletions(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index a59cc79..c8bf54b 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -8,11 +8,14 @@ use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Routing\Controller as BaseController; +use Typesense\Client; class Controller extends BaseController { use AuthorizesRequests, DispatchesJobs, ValidatesRequests; + private $client; + public function __construct() { // if(config('app.env') === 'production') { @@ -45,8 +48,38 @@ class Controller extends BaseController ); } + public function connect() { + $this->client = new Client( + [ + 'api_key' => env('TYPESENSE_API_KEY', 'K4fae5KYZTVj6Wucp5q9'), + 'nodes' => [ + [ + 'host' => env('TYPESENSE_HOST', 'typesense.dev.prescription-quotidien.com'), // For Typesense Cloud use xxx.a1.typesense.net + 'port' => '', // For Typesense Cloud use 443 + 'protocol' => env('TYPESENSE_PROTOCOL', 'https'), // For Typesense Cloud use https + ], + ], + 'connection_timeout_seconds' => 2, + ] + ); + } + public function getPdfBySlug() { - $refs = request('refs', []); + if(null === $this->client) { + $this->connect(); + } + $q = request('query', ''); + $page = request('page', 1); + $searchParameters = [ + 'q' => $q, + 'query_by' => 'text', + 'per_page' => 20, + 'page' => $page + ]; + + $typeSenseResults = $this->client->collections['fluidbooks']->documents->search($searchParameters); + $refs = array_map(function($hits) { return $hits['document']['reference']; }, $typeSenseResults['hits']); + $pdfFile = new PdfFile(); return $pdfFile->whereIn('slug', $refs)->get()->toArray(); } diff --git a/app/PhpVars.php b/app/PhpVars.php index b79b508..8960c9d 100644 --- a/app/PhpVars.php +++ b/app/PhpVars.php @@ -10,15 +10,15 @@ class PhpVars protected static function data() { return [ - 'algolia_app_id' => config('scout.algolia.id'), - 'algolia_search_key' => config('scout.algolia.search_key'), - 'algolia_prefix' => config('scout.prefix'), + 'typesense_api_key' => config('scout.typesense.api_key'), + 'typesense_host' => config('scout.typesense.host'), + 'typesense_prefix' => config('scout.prefix'), ]; } public static function output() { - $json = json_encode(self::data()); + $json = ""; //json_encode(self::data()); return 'const php_vars = '.$json; diff --git a/resources/js/app.js b/resources/js/app.js index ab1d4db..51573cf 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -31,7 +31,7 @@ window.Vue.use(Toasted); * * Eg. ./components/ExampleComponent.vue -> */ - +console.log(process.env.MIX_TYPESENSE_HOST) const files = require.context('./', true, /\.vue$/i) files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default)) diff --git a/resources/js/components/FileSearch/FileHit.vue b/resources/js/components/FileSearch/FileHit.vue index bb350f4..e69de29 100644 --- a/resources/js/components/FileSearch/FileHit.vue +++ b/resources/js/components/FileSearch/FileHit.vue @@ -1,38 +0,0 @@ - - - - - diff --git a/resources/js/components/FileSearch/FileInstantSearch.vue b/resources/js/components/FileSearch/FileInstantSearch.vue index 127da49..64f2768 100644 --- a/resources/js/components/FileSearch/FileInstantSearch.vue +++ b/resources/js/components/FileSearch/FileInstantSearch.vue @@ -1,82 +1,106 @@ diff --git a/resources/js/components/FileSearch/Search.vue b/resources/js/components/FileSearch/Search.vue index 576be8e..97f54d5 100644 --- a/resources/js/components/FileSearch/Search.vue +++ b/resources/js/components/FileSearch/Search.vue @@ -1,44 +1,13 @@ diff --git a/resources/sass/_ais.scss b/resources/sass/_ais.scss index 8ce3774..c60ef44 100644 --- a/resources/sass/_ais.scss +++ b/resources/sass/_ais.scss @@ -1,7 +1,29 @@ +.ais-SearchBox-form { + display: flex; + gap: 16px; + background-color: white; + border-radius: 3px; + border: 1px solid #DCE0F5; + padding: 17px 24px; +} .ais-SearchBox-input { - @extend .form-control; - width: calc(100% - 80px); + width: 100%; display: inline-block; + outline: none; + font-weight: 500; + color: $blue; + line-height: 1; + &::placeholder { + color: $blue; + } +} +.ais-SearchBox-submit { + order: -1; + svg { + width: 13px; + height: 13px; + fill: #044e9c; + } } .ais-SearchBox-reset { display: none; @@ -10,3 +32,8 @@ mark.ais-Snippet-highlighted, mark.ais-Highlight-highlighted, mark.mark { padding: 0; background-color: #fff252; } +.ais-Pagination { + position: absolute; + visibility: hidden; +} + diff --git a/routes/web.php b/routes/web.php index 565ae5f..a28bac4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -140,7 +140,7 @@ Route::domain(env('CLIENT_DOMAIN_NAME'))->group(function () { Route::get('devenez-annonceurs', 'AdvertisersController@index')->name('annonceurs.index'); Route::post('devenez-annonceurs', 'AdvertisersController@requestMail')->name('annonceurs.store'); - Route::post('retrieveLetter', 'Controller@getPdfBySlug'); + Route::match(['post','get'],'retrieveLetter', 'Controller@getPdfBySlug'); }); /** Public routes + NGROK routes */ -- 2.39.5