PHPackages                             tobento/app-search - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. tobento/app-search

ActiveLibrary[Search &amp; Filtering](/categories/search)

tobento/app-search
==================

App search support.

2.0(9mo ago)0131MITPHPPHP &gt;=8.4

Since May 22Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/tobento-ch/app-search)[ Packagist](https://packagist.org/packages/tobento/app-search)[ Docs](https://www.tobento.ch)[ RSS](/packages/tobento-app-search/feed)WikiDiscussions 2.x Synced today

READMEChangelog (6)Dependencies (19)Versions (8)Used By (1)

App Search
==========

[](#app-search)

The search app provides interfaces to search resources by filters. It comes with a default implementation and some basic [searchables](#available-searchables) and [filters](#available-filters).

Table of Contents
-----------------

[](#table-of-contents)

- [Getting Started](#getting-started)
    - [Requirements](#requirements)
- [Documentation](#documentation)
    - [App](#app)
    - [Search Boot](#search-boot)
        - [Search Config](#search-config)
    - [Basic Usage](#basic-usage)
        - [Searching](#searching)
    - [Features](#features)
        - [Search Feature](#search-feature)
    - [Search](#search)
        - [Adding Searchables](#adding-searchables)
        - [Creating Searchables](#creating-searchables)
        - [Adding Filters](#adding-filters)
        - [Creating Filters](#creating-filters)
        - [Searching](#searching)
    - [Available Searchables](#available-searchables)
        - [Menu Searchable](#menu-searchable)
        - [Repository Searchable](#repository-searchable)
    - [Available Filters](#available-filters)
        - [Clear Filter](#clear-filter)
        - [Input Filter](#input-filter)
        - [Pagination Filter](#pagination-filter)
        - [Searchables Filter](#searchables-filter)
        - [Search Term Filter](#search-term-filter)
        - [Select Filter](#select-filter)
- [Credits](#credits)

---

Getting Started
===============

[](#getting-started)

Add the latest version of the app search project running this command.

```
composer require tobento/app-search

```

Requirements
------------

[](#requirements)

- PHP 8.4 or greater

Documentation
=============

[](#documentation)

App
---

[](#app)

Check out the [**App Skeleton**](https://github.com/tobento-ch/app-skeleton) if you are using the skeleton.

You may also check out the [**App**](https://github.com/tobento-ch/app) to learn more about the app in general.

Search Boot
-----------

[](#search-boot)

The search boot does the following:

- migrates search config, view and asset files
- implements search interfaces based on the search config file
- boots features defined in config file

```
use Tobento\App\AppFactory;
use Tobento\App\Search\InputInterface;
use Tobento\App\Search\SearchInterface;

// Create the app
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots:
$app->boot(\Tobento\App\Search\Boot\Search::class);
$app->booting();

// Implemented interfaces:
$search = $app->get(SearchInterface::class);
$input = $app->get(InputInterface::class);

// Run the app
$app->run();
```

### Search Config

[](#search-config)

The configuration for the search is located in the `app/config/search.php` file at the default App Skeleton config location where you can configure the implemented search interfaces for your application and more.

Basic Usage
-----------

[](#basic-usage)

### Searching

[](#searching)

This example shows how a search process works in general. If you use the [Search Feature](#search-feature), there is no need to implement anything.

```
use Tobento\App\Search\Filters;
use Tobento\App\Search\FiltersInterface;
use Tobento\App\Search\Input;
use Tobento\App\Search\InputInterface;
use Tobento\App\Search\Search;
use Tobento\App\Search\Searchables;
use Tobento\App\Search\SearchablesInterface;
use Tobento\App\Search\SearchInterface;
use Tobento\App\Search\SearchResultsInterface;

$search = new Search(
    filters: new Filters(), // FiltersInterface
    searchables: new Searchables(), // SearchablesInterface
);

var_dump($search instanceof SearchInterface);
// bool(true)

// Searching:
$searchResults = $search->search(
    input: new Input(['search' => ['term' => 'foo']]), // InputInterface
);

var_dump($searchResults instanceof SearchResultsInterface);
// bool(true)

// You may get the filters:
var_dump($search->filters() instanceof FiltersInterface);
// bool(true)

// You may get the searchables:
var_dump($search->searchables() instanceof SearchablesInterface);
// bool(true)
```

Features
--------

[](#features)

### Search Feature

[](#search-feature)

The search feature provides a simple search page where users can search the applications content. Furthermore, it provides a searchbar which you may render on all pages.

Check out the [Search](#search) section on how to add searchables, filters and more as this feature uses the implemented search interfaces.

**Config**

In the [config file](#search-config) you can configure this feature:

```
'features' => [
    new Feature\Search(
        // The default views to render:
        view: 'search/index',
        viewSearchbar: 'search/searchbar',
        viewSearchbarResults: 'search/searchbar-results',

        // You may customize the searchbar input placeholder:
        searchbarInputPlaceholder: 'Search...',

        // If true, routes are being localized.
        localizeRoute: false,
    ),
],
```

**Search Page**

The search page is available under the `https://example.com/search` url.

**Searchbar**

In any view file, render the view named `search.bar` which will display a search input element:

```
