create-sort

Create Elasticsearch Sort classes with PHPUnit tests and PHPStan checks.

66|2|Updated Nov 27, 2025
One-click install
npx skills add https://github.com/bonu-dev/php-elasticsearch-builder --skill create-sort
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: create-sort
Source: https://github.com/bonu-dev/php-elasticsearch-builder/tree/main/.agents/skills/create-sort
Command: npx skills add https://github.com/bonu-dev/php-elasticsearch-builder --skill create-sort

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Manually adding new Elasticsearch Sort classes is error‑prone and requires repetitive boilerplate, violating project standards.

Core Features & Use Cases

  • Provides step‑by‑step guidelines to create the class file, unit test, and ensure CI conventions (immutability, no final/private, proper PHPDoc, strict types).
  • Generates appropriate templates for field‑based, delegating, and complex nested sorts.
  • Integrates the new sort with the QueryBuilder for immediate usage in search queries.

Quick Start

Ask the create‑sort skill to add a GeoDistanceSort for the 'location' field.

Frequently Asked Questions about create-sort

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create an Elasticsearch Sort class in PHP without violating CI conventions?

Creating an Elasticsearch Sort class requires PHP 8.4+ and adherence to strict immutability, proper PHPDoc, and CI coding standards. This approach eliminates repetitive boilerplate when adding complex sorts like GeoDistanceSort or ScriptSort to your QueryBuilder.

What is the best way to add a GeoDistanceSort to a php-elasticsearch-builder?

Adding a GeoDistanceSort involves generating a class file from predefined templates for complex nested sorts. You must also create the corresponding PHPUnit test and ensure the implementation integrates with the QueryBuilder for immediate search query usage.

Does my PHP Elasticsearch Sort class need to be immutable?

Yes, your Elasticsearch Sort class must be immutable. Project conventions enforced by CI require strict types, no final or private keywords, and proper PHPDoc to maintain consistency across field-based, delegating, and nested sort implementations.

How do I unit test a new ScriptSort class in a PHP Elasticsearch builder?

Unit testing a new ScriptSort class requires PHPUnit to validate the sort logic and structure. The process involves creating a unit test file alongside the class to verify immutability and integration before passing CI checks.

When do I need to extend Elasticsearch sort types in my PHP project?

You extend Elasticsearch sort types when developers require specific sorting mechanisms like GeoDistanceSort, ScriptSort, or nested field sorts that are not currently supported. This enables custom sorting logic to be directly used within search queries.