auto-search-chips

Laravel package ยท v0.1 pre-release

Your users type a sentence. Eloquent gets typed filters.

The package reads a plain search sentence and turns it into filters on your model. It shows each filter as a chip under the search box, so the user sees how the search was read and can remove a part. It works with no API key. An AI step is optional.

Demo

Showing
    TitleTypeAuthorViewsPublished

    Try a sentence:

    Each sentence was parsed by the package in the demo app, with the rules engine and Cloudflare Clairic. The chips are that recorded result. The filters run in your browser on 60 sample posts, so you can remove a chip and see the list change. This page does not call a server.

    Three steps to a search box

    1. Install

      composer require meirdick/auto-search-chips
      php artisan search-chips:install

      The install command finds your stack and copies the component for it: Livewire, React, Vue, Svelte, or Blade with Alpine.

    2. Name the fields

      use Meirdick\SearchChips\HasSearchChips;
      use Meirdick\SearchChips\Schema\ChipSchema;
      
      class Post extends Model
      {
          use HasSearchChips;
      
          public function searchChips(ChipSchema $chips): void
          {
              $chips->text('title')->searchable();
              $chips->enum('type', ['video' => 'Video', 'article' => 'Article'])
                  ->synonyms(['movie' => 'video']);
              $chips->number('views')->aliases('plays')->sortable();
              $chips->datetime('published_at')->label('Published');
              $chips->relation('author', 'name');
          }
      }

      Only the fields you name can be filtered. The package can also write this method for you from the table.

    3. Register and show

      // AppServiceProvider
      SearchChips::register(Post::class, 'posts');
      <livewire:search-chips for="posts" panel />

      Or use it in PHP with no UI: SearchChips::for(Post::class)->search($text)->paginate().

    Read the quickstart Overview

    What you get

    A rules engine that needs no key
    Types, numbers, units, dates, ranges, negation and sort are read in PHP. No network call. Chips show while the user types.
    AI that adds, and does not override
    Cloudflare Clairic or a chat model reads the words the rules did not explain. A chip from the rules always stays. A chip the AI is not sure of shows as a suggestion.
    One check on every chip
    Each chip is checked against your field list before it touches the query. That is true for chips from the rules, from the AI and from the browser.
    Safe defaults
    Routes need a signed-in user and have a rate limit. A model is reachable only after you register it. No row values go to an AI provider.
    A component for each starter kit
    Livewire, React and Blade with Alpine are tested in a browser. Vue and Svelte components ship but are not run in a starter kit yet.
    Tests without a network
    SearchChips::fake() returns the chips you give it, so your feature tests do not call a model.

    Status

    Version 0.1 is not tagged yet. The test suite runs on PHP 8.3 to 8.5 with Laravel 12 and 13, on SQLite. Laravel Scout is tested with Meilisearch and Typesense. MySQL, PostgreSQL and Algolia are not run yet. Read the limits page before you use it in production.