PHPackages                             xlstudio/xunsearch - 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. xlstudio/xunsearch

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

xlstudio/xunsearch
==================

Laravel 5 package for full-text search over Eloquent models based on XunSearch.

2211HTML

Since Jun 8Pushed 9y ago1 watchersCompare

[ Source](https://github.com/xlstudio/xunsearch)[ Packagist](https://packagist.org/packages/xlstudio/xunsearch)[ RSS](/packages/xlstudio-xunsearch/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel 5 XunSearch
===================

[](#laravel-5-xunsearch)

[![StyleCI](https://camo.githubusercontent.com/5f5a75341f6fcd5c95694b394798782843b362004f3bdb813b82204aedd80996/68747470733a2f2f7374796c6563692e696f2f7265706f732f37333839343838342f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/73894884)[![Total Downloads](https://camo.githubusercontent.com/3173147e235579369cafc5866cc09f7785e63dc4ba963f92b0127f5685d5bb1f/68747470733a2f2f706f7365722e707567782e6f72672f786c73747564696f2f78756e7365617263682f646f776e6c6f616473)](https://packagist.org/packages/xlstudio/xunsearch)[![Latest Stable Version](https://camo.githubusercontent.com/e5af6467826c099b7d2dbeb14423b23866cef5f5585a5c8d6482a706f2acd33b/68747470733a2f2f706f7365722e707567782e6f72672f786c73747564696f2f78756e7365617263682f762f737461626c652e706e67)](https://packagist.org/packages/xlstudio/xunsearch)[![Latest Unstable Version](https://camo.githubusercontent.com/a02dc7d86858bee6c490fb1c5ecd04275cd286286cb7e17af4c8ada94356e326/68747470733a2f2f706f7365722e707567782e6f72672f786c73747564696f2f78756e7365617263682f762f756e737461626c652e706e67)](https://packagist.org/packages/xlstudio/xunsearch)[![License](https://camo.githubusercontent.com/6a289369ae1824e65d27176c2877596c7b55d116d326023b5a1840622d5740c7/68747470733a2f2f706f7365722e707567782e6f72672f786c73747564696f2f78756e7365617263682f6c6963656e73652e706e67)](https://packagist.org/packages/xlstudio/xunsearch)

Laravel 5 package for full-text search over Eloquent models based on XunSearch.

Installation
------------

[](#installation)

Require this package in your composer.json and run composer update:

```
{
	"require": {
            "xlstudio/xunsearch": "dev-master"
	}
}
```

After updating composer, add the ServiceProvider to the providers array in `app/config/app.php`

```
'providers' => [
	Xlstudio\XunSearch\ServiceProvider::class,
],
```

If you want to use the facade to search, add this to your facades in `app/config/app.php`:

```
'aliases' => [
	'Search' => Xlstudio\XunSearch\Facade::class,
],
```

Configuration
-------------

[](#configuration)

Publish the config file into your project by running:

```
php artisan vendor:publish --provider="Xlstudio\XunSearch\ServiceProvider"
```

\###Basic In published config file add descriptions for models which need to be indexed, for example:

```
//@see http://www.xunsearch.com/doc/php/guide/ini.guide
"project" => [
    "project.name" => "xunsearch",
    "project.default_charset" => "utf-8",
    "server.index" => "127.0.0.1:8383",
    "server.search" => "127.0.0.1:8384",
    //remember change FIELD_LABEL_DEFAULT_SEARCH_PK value in Config.php
    "primary_key" => [
        "type" => "id"
    ],
    //remember change FIELD_LABEL_DEFAULT_CLASS_ID value in Config.php
    "class_uid" => [
        "index" => "both"
    ],
    //remember change FIELD_LABEL_DEFAULT_DB_PK value in Config.php
    "id" => [
        "type" => "numeric"
    ],
    "subject" => [
        "type" => "title"
    ],
    "status" => [
        'type' => "numeric"
    ],
    "content" => [
        "type" => "body"
    ]
],

'index' => [

	// ...

	namespace\FirstModel::class => [
		'fields' => [
			'name', 'full_description', // fields for indexing
		],
		'primary_key' => 'id'  //primary_key name in DB, default 'id'
	],

	namespace\SecondModel::class => [
		'fields' => [
			'name', 'short_description', // fields for indexing
		]
	],

	// ...

],
```

Usage
-----

[](#usage)

### Artisan commands

[](#artisan-commands)

#### Initialize or rebuild search index

[](#initialize-or-rebuild-search-index)

For building of search index run:

```
php artisan search:rebuild --verbose
```

#### Clear search index

[](#clear-search-index)

For clearing of search index run:

```
php artisan search:clear
```

#### Filtering of models in search results

[](#filtering-of-models-in-search-results)

For filtering of models in search results each model's class can implements `SearchableInterface`. For example:

```
use Illuminate\Database\Eloquent\Model;
use Xlstudio\XunSearch\Model\SearchableInterface;

class Dummy extends Model implements SearchableInterface
{
        // ...

        /**
         * Get id list for all searchable models.
         */
        public static function searchableIds()
        {
            return self::wherePublish(true)->lists('id');
        }

        // ...
}
```

### Partial updating of search index

[](#partial-updating-of-search-index)

For register of necessary events (save/update/delete) `use Xlstudio\XunSearch\Model\SearchTrait` in target model:

```
    use Illuminate\Database\Eloquent\Model;
    use Xlstudio\XunSearch\Model\SearchableInterface;
    use Xlstudio\XunSearch\Model\SearchTrait;

    class Dummy extends Model implements SearchableInterface
    {
        use SearchTrait;

        // ...
    }
```

### Query building

[](#query-building)

Build query in several ways:

#### Using constructor:

[](#using-constructor)

By default, queries which will execute search in the **phrase entirely** are created.

##### Simple queries

[](#simple-queries)

```
$query = Model::getSearch()->addQuery("clock"); // search by all fields.
// or
$query = Model::getSearch()->addQuery('name:clock'); // search by 'name' field.
// or
$query = Model::getSearch()->addQuery('name:clock'); // filter by 'short_description' field.

$Ids = Model::getSearch()->addQuery('name:clock')->getIDList(); // filter by 'short_description' field.
```

### Getting of results

[](#getting-of-results)

For built query are available following actions:

#### Get all found models

[](#get-all-found-models)

```
$models = $query->search();
```

#### Get all found models ID

[](#get-all-found-models-id)

```
$models = $query->getIDList();
```

#### Get count of results

[](#get-count-of-results)

```
$count = $query->count();
```

#### Get limit results with offset

[](#get-limit-results-with-offset)

```
$models = $query->limit(5, 10)->get(); // Limit = 5 and offset = 10
```

#### Sort

[](#sort)

```
$query = $query->setSort('chrono', true);
```

### Highlighting of matches

[](#highlighting-of-matches)

Highlighting of matches is available for any html fragment encoded in **utf-8** and is executed only for the last executed request.

```
$docs = $search->setQuery('测试')->setLimit(5)->search();
foreach ($docs as $doc)
{
   $subject = $search->highlight($doc->subject); // 高亮处理 subject 字段
   $message = $search->highlight($doc->message); // 高亮处理 message 字段
   echo $doc->rank() . '. ' . $subject . " [" . $doc->percent() . "%] - ";
   echo date("Y-m-d", $doc->chrono) . "\n" . $message . "\n";
}
```

License
-------

[](#license)

Package licenced under the MIT license.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/fdde82cfbd2da5d619bf834c98bd120708998e9e036d0f1fd044f3dde6fe7831?d=identicon)[Xiphin](/maintainers/Xiphin)

---

Top Contributors

[![Xiphin](https://avatars.githubusercontent.com/u/3348428?v=4)](https://github.com/Xiphin "Xiphin (10 commits)")

---

Tags

laravelxunsearch

### Embed Badge

![Health badge](/badges/xlstudio-xunsearch/health.svg)

```
[![Health](https://phpackages.com/badges/xlstudio-xunsearch/health.svg)](https://phpackages.com/packages/xlstudio-xunsearch)
```

###  Alternatives

[awesome-nova/dependent-filter

Dependent filters for Laravel Nova

26190.2k](/packages/awesome-nova-dependent-filter)[algolia/php-dom-parser

A simple tool to turn DOM into Algolia search friendly record objects.

181.8k](/packages/algolia-php-dom-parser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
