From 8908a02d44e6f3dab00374fe51e2cd2e0b17b33b Mon Sep 17 00:00:00 2001 From: edalzell Date: Wed, 8 Apr 2026 16:02:32 -0700 Subject: [PATCH 01/10] Return the search highlight --- src/Typesense/Index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Typesense/Index.php b/src/Typesense/Index.php index 6c15991..4adcb18 100644 --- a/src/Typesense/Index.php +++ b/src/Typesense/Index.php @@ -134,6 +134,7 @@ public function searchUsingApi($query, array $options = []): array ->map(function ($result, $i) use ($total) { $result['document']['reference'] = $result['document']['id']; $result['document']['search_score'] = Arr::get($this->config, 'settings.maintain_ranking', false) ? ($total - $i) : (int) ($result['text_match'] ?? 0); + $result['document']['search_highlight'] = $result['highlight'] ?? []; return $result['document']; }), From 5688555028e6c63c25a27b92cdaf17ae05892021 Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 9 Apr 2026 15:27:59 -0700 Subject: [PATCH 02/10] Get tests working --- .github/workflows/run-tests.yml | 60 ++++++++++++++++----------------- .gitignore | 7 ++-- composer.json | 3 +- tests/Unit/IndexTest.php | 14 ++++++++ 4 files changed, 50 insertions(+), 34 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a9da705..d3f978a 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,7 +12,7 @@ jobs: services: typesense: - image: typesense/typesense:27.0.rc21 + image: typesense/typesense:30.1 ports: - 8108:8108/tcp volumes: @@ -23,36 +23,36 @@ jobs: TYPESENSE_ENABLE_CORS: true strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - php: [8.2, 8.3] - laravel: [10.*, 11.*, 12.*] - statamic: [5.*] - dependency-version: [prefer-stable] + fail-fast: false + matrix: + os: [ubuntu-latest] + php: [8.2, 8.3] + laravel: [10.*, 11.*, 12.*] + statamic: [5.*] + dependency-version: [prefer-stable] name: P${{ matrix.php }} - L${{ matrix.laravel }} - S${{ matrix.statamic }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: fileinfo, dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick - coverage: none - - - name: Setup Problem Matches - run: | - echo "::add-matcher::${{ runner.tool_cache }}/php.json" - echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - - name: Install dependencies - run: | - composer require "statamic/cms:${{ matrix.statamic }}" "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update - composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction - - - name: Execute tests - run: vendor/bin/phpunit + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: fileinfo, dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick + coverage: none + + - name: Setup Problem Matches + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install dependencies + run: | + composer require "statamic/cms:${{ matrix.statamic }}" "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction + + - name: Execute tests + run: vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index 4ea6620..0743681 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -.idea -/vendor .DS_Store -composer.lock +.idea .php-cs-fixer.cache +.phpunit.cache build/report.junit.xml +composer.lock +/vendor diff --git a/composer.json b/composer.json index ada4e3f..77f9ba3 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "require-dev": { "laravel/pint": "^1.17", "orchestra/testbench": "^8.14 || ^9.0 || ^10.0", - "phpunit/phpunit": "^10.0 || ^11.0" + "phpunit/phpunit": "^10.0", + "spatie/laravel-ray": "^1.43" }, "autoload": { "psr-4": { diff --git a/tests/Unit/IndexTest.php b/tests/Unit/IndexTest.php index bce387e..1a85d1b 100644 --- a/tests/Unit/IndexTest.php +++ b/tests/Unit/IndexTest.php @@ -132,4 +132,18 @@ public function it_sorts_by_specified_order() $this->assertSame(['Entry 2', 'Entry 1'], collect($results['results'])->pluck('title')->all()); } + + #[Test] + public function it_adds_search_highlight() + { + $entry1 = Facades\Entry::make() + ->id('test-2') + ->collection('pages') + ->data(['title' => 'Entry 1']) + ->save(); + + $results = Facades\Search::index('typesense_index')->searchUsingApi('Entry 1'); + + $this->assertEquals('Entry 1', $results['results'][0]['search_highlight']['title']['snippet']); + } } From e2533c8f014fd8011c7917c631c5f67828a40465 Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 9 Apr 2026 15:40:11 -0700 Subject: [PATCH 03/10] try this --- .github/workflows/run-tests.yml | 15 ++++++++------- composer.json | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d3f978a..e560758 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -40,19 +40,20 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php }} - extensions: fileinfo, dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick - coverage: none + php-version: ${{ matrix.php }} + extensions: fileinfo, dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick + coverage: none + ini-values: zend.assertions=-1 - name: Setup Problem Matches run: | - echo "::add-matcher::${{ runner.tool_cache }}/php.json" - echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Install dependencies run: | - composer require "statamic/cms:${{ matrix.statamic }}" "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update - composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction + composer require "statamic/cms:${{ matrix.statamic }}" "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction - name: Execute tests run: vendor/bin/phpunit diff --git a/composer.json b/composer.json index 77f9ba3..c7a7f46 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "require-dev": { "laravel/pint": "^1.17", "orchestra/testbench": "^8.14 || ^9.0 || ^10.0", - "phpunit/phpunit": "^10.0", + "phpunit/phpunit": "^10.0 || ^11.0", "spatie/laravel-ray": "^1.43" }, "autoload": { From cd719eea6b0e8457357cb60cc509269b82a13866 Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 9 Apr 2026 16:08:26 -0700 Subject: [PATCH 04/10] Augment the search highlight --- src/Typesense/Index.php | 11 +++++++++++ tests/Unit/IndexTest.php | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Typesense/Index.php b/src/Typesense/Index.php index 4adcb18..82c7081 100644 --- a/src/Typesense/Index.php +++ b/src/Typesense/Index.php @@ -7,6 +7,7 @@ use Statamic\Facades\Blink; use Statamic\Search\Documents; use Statamic\Search\Index as BaseIndex; +use Statamic\Search\Result; use Statamic\Support\Arr; use Typesense\Client; use Typesense\Exceptions\ObjectNotFound; @@ -196,4 +197,14 @@ public function client() { return $this->client; } + + public function extraAugmentedResultData(Result $result) + { + + if (is_null($highlight = Arr::get($result->getRawResult(), 'search_highlight')) && ! empty($highlight)) { + return []; + } + + return ['search_highlight' => Arr::first($highlight)['snippet']]; + } } diff --git a/tests/Unit/IndexTest.php b/tests/Unit/IndexTest.php index 1a85d1b..4d320d4 100644 --- a/tests/Unit/IndexTest.php +++ b/tests/Unit/IndexTest.php @@ -146,4 +146,21 @@ public function it_adds_search_highlight() $this->assertEquals('Entry 1', $results['results'][0]['search_highlight']['title']['snippet']); } + + #[Test] + public function it_augments_with_search_highlight() + { + $entry1 = Facades\Entry::make() + ->id('test-2') + ->collection('pages') + ->data(['title' => 'Entry 1']) + ->save(); + + $index = Facades\Search::index('typesense_index'); + $result = $index->search('Entry 1')->get()->first(); + + $augmentedData = $index->extraAugmentedResultData($result); + + $this->assertSame(['search_highlight' => 'Entry 1'], $augmentedData); + } } From 972edd709bb00a092fa7071fbe379fda01223713 Mon Sep 17 00:00:00 2001 From: edalzell Date: Tue, 16 Jun 2026 11:59:46 -0700 Subject: [PATCH 05/10] =?UTF-8?q?no=20error=20if=20key=20doesn=E2=80=99t?= =?UTF-8?q?=20exist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Typesense/Index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Typesense/Index.php b/src/Typesense/Index.php index 82c7081..d00e60f 100644 --- a/src/Typesense/Index.php +++ b/src/Typesense/Index.php @@ -205,6 +205,6 @@ public function extraAugmentedResultData(Result $result) return []; } - return ['search_highlight' => Arr::first($highlight)['snippet']]; + return ['search_highlight' => Arr::get(Arr::first($highlight), 'snippet')]; } } From a3fa1bb869df863f0552819e2ae9008b5facc372 Mon Sep 17 00:00:00 2001 From: Erin Dalzell Date: Tue, 16 Jun 2026 14:29:38 -0700 Subject: [PATCH 06/10] Drop Laravel 10 & 11 support for security reasons (#31) --- .github/workflows/run-tests.yml | 4 ++-- composer.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a9da705..fc6e29e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,7 +12,7 @@ jobs: services: typesense: - image: typesense/typesense:27.0.rc21 + image: typesense/typesense:30.1 ports: - 8108:8108/tcp volumes: @@ -27,7 +27,7 @@ jobs: matrix: os: [ubuntu-latest] php: [8.2, 8.3] - laravel: [10.*, 11.*, 12.*] + laravel: [12.*] statamic: [5.*] dependency-version: [prefer-stable] diff --git a/composer.json b/composer.json index ada4e3f..3492ada 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": "^8.2", "guzzlehttp/guzzle": "^7.3", "http-interop/http-factory-guzzle": "^1.0", - "illuminate/support": "^10.0|^11.0|^12.0", + "illuminate/support": "^12.40", "statamic/cms": "^5.38", "typesense/typesense-php": "^5.1" }, From 67e179a30a2dab0794c358ce2569689f133c3987 Mon Sep 17 00:00:00 2001 From: edalzell Date: Tue, 16 Jun 2026 14:41:39 -0700 Subject: [PATCH 07/10] back these out --- .github/workflows/run-tests.yml | 53 ++++++++++++++++----------------- composer.json | 19 ++++++------ 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 611b194..44a7e35 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,7 +12,7 @@ jobs: services: typesense: - image: typesense/typesense:30.1 + image: typesense/typesense:27.0.rc21 ports: - 8108:8108/tcp volumes: @@ -26,34 +26,33 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: [8.2, 8.3] - laravel: [12.*] - statamic: [5.*] + php: [8.3, 8.4, 8.5] + laravel: [12.*, 13.*] + statamic: [6.*] dependency-version: [prefer-stable] name: P${{ matrix.php }} - L${{ matrix.laravel }} - S${{ matrix.statamic }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: fileinfo, dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick - coverage: none - ini-values: zend.assertions=-1 - - - name: Setup Problem Matches - run: | - echo "::add-matcher::${{ runner.tool_cache }}/php.json" - echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - - name: Install dependencies - run: | - composer require "statamic/cms:${{ matrix.statamic }}" "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update - composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction - - - name: Execute tests - run: vendor/bin/phpunit + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: fileinfo, dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick + coverage: none + + - name: Setup Problem Matches + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install dependencies + run: | + composer require "statamic/cms:${{ matrix.statamic }}" "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction + + - name: Execute tests + run: vendor/bin/phpunit diff --git a/composer.json b/composer.json index ec8e77d..d2b8348 100644 --- a/composer.json +++ b/composer.json @@ -10,25 +10,22 @@ "license": "MIT", "authors": [ { - "name": "Ryan Mitchell", - "email": "ryan@thoughtcollective.com", - "homepage": "https://github.com/ryanmitchell", - "role": "Developer" + "name": "Statamic Rad Pack", + "homepage": "https://statamic.com/creators/rad-pack" } ], "require": { "php": "^8.2", "guzzlehttp/guzzle": "^7.3", "http-interop/http-factory-guzzle": "^1.0", - "illuminate/support": "^12.40", - "statamic/cms": "^5.38", + "illuminate/support": "^12.0 || ^13.0", + "statamic/cms": "^6.0", "typesense/typesense-php": "^5.1" }, "require-dev": { "laravel/pint": "^1.17", - "orchestra/testbench": "^8.14 || ^9.0 || ^10.0", - "phpunit/phpunit": "^10.0 || ^11.0", - "spatie/laravel-ray": "^1.43" + "orchestra/testbench": "^10.0 || ^11.0", + "phpunit/phpunit": "^11.0 || ^12.0" }, "autoload": { "psr-4": { @@ -61,5 +58,7 @@ "name": "Typesense", "description": "Typesense search driver for Statamic" } - } + }, + "minimum-stability": "dev", + "prefer-stable": true } From d6014d5412c473457ab4f2c134c7cc39b5a057bf Mon Sep 17 00:00:00 2001 From: Erin Dalzell Date: Tue, 16 Jun 2026 14:43:15 -0700 Subject: [PATCH 08/10] review --- .github/workflows/run-tests.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 44a7e35..fc6e29e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,7 +12,7 @@ jobs: services: typesense: - image: typesense/typesense:27.0.rc21 + image: typesense/typesense:30.1 ports: - 8108:8108/tcp volumes: @@ -26,9 +26,9 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: [8.3, 8.4, 8.5] - laravel: [12.*, 13.*] - statamic: [6.*] + php: [8.2, 8.3] + laravel: [12.*] + statamic: [5.*] dependency-version: [prefer-stable] name: P${{ matrix.php }} - L${{ matrix.laravel }} - S${{ matrix.statamic }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} From 6b1817eda3f601f45ff38559cbbe0ca092b6a0ce Mon Sep 17 00:00:00 2001 From: Erin Dalzell Date: Tue, 16 Jun 2026 14:43:36 -0700 Subject: [PATCH 09/10] revert --- composer.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index d2b8348..3492ada 100644 --- a/composer.json +++ b/composer.json @@ -10,22 +10,24 @@ "license": "MIT", "authors": [ { - "name": "Statamic Rad Pack", - "homepage": "https://statamic.com/creators/rad-pack" + "name": "Ryan Mitchell", + "email": "ryan@thoughtcollective.com", + "homepage": "https://github.com/ryanmitchell", + "role": "Developer" } ], "require": { "php": "^8.2", "guzzlehttp/guzzle": "^7.3", "http-interop/http-factory-guzzle": "^1.0", - "illuminate/support": "^12.0 || ^13.0", - "statamic/cms": "^6.0", + "illuminate/support": "^12.40", + "statamic/cms": "^5.38", "typesense/typesense-php": "^5.1" }, "require-dev": { "laravel/pint": "^1.17", - "orchestra/testbench": "^10.0 || ^11.0", - "phpunit/phpunit": "^11.0 || ^12.0" + "orchestra/testbench": "^8.14 || ^9.0 || ^10.0", + "phpunit/phpunit": "^10.0 || ^11.0" }, "autoload": { "psr-4": { @@ -58,7 +60,5 @@ "name": "Typesense", "description": "Typesense search driver for Statamic" } - }, - "minimum-stability": "dev", - "prefer-stable": true + } } From dcff7d8fdfe170afd1086c4e531f42c311a10050 Mon Sep 17 00:00:00 2001 From: Erin Dalzell Date: Tue, 16 Jun 2026 14:43:56 -0700 Subject: [PATCH 10/10] revert --- .gitignore | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 0743681..4ea6620 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ -.DS_Store .idea +/vendor +.DS_Store +composer.lock .php-cs-fixer.cache -.phpunit.cache build/report.junit.xml -composer.lock -/vendor