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

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

liugj/lumen-xunsearch
=====================

Xunsearch Driver for Laravel Scout.

v1.2.9(7y ago)62413[2 issues](https://github.com/liugj/lumen-xunsearch/issues)MITPHPPHP &gt;=5.6.4

Since Jan 10Pushed 7y ago3 watchersCompare

[ Source](https://github.com/liugj/lumen-xunsearch)[ Packagist](https://packagist.org/packages/liugj/lumen-xunsearch)[ RSS](/packages/liugj-lumen-xunsearch/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (1)Versions (13)Used By (0)

Lumen XunSearch
===============

[](#lumen-xunsearch)

Xunsearch Engine for Laravel Scout.

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

[](#installation)

You can install the package via composer:

```
composer require liugj/lumen-xunsearch
```

You must add the Scout service provider and the package service provider in your `bootstrap/app.php` line 80 config:

```
$app->register(Liugj\Xunsearch\XunsearchServiceProvider::class);
```

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

[](#configuration)

Publish the config file into your project by edit `config/scout.php` line 62:

```
    'xunsearch' => [
        'index'  => env('XUNSEARCH_INDEX_HOST', ''),
        'search' => env('XUNSEARCH_SEARCH_HOST', ''),
        'schema' => [
           'brand_index'=>app()->basePath()  .'/'. env('XUNSEARCH_SCHEMA_BRAND'),
        ]
    ],
```

Add Xunsearch settings into `.env` file:

```
SCOUT_DRIVER=xunsearch
XUNSEARCH_INDEX_HOST=127.0.0.1:8383
XUNSEARCH_SEARCH_HOST=127.0.0.1:8384
XUNSEARCH_SCHEMA_BRAND=config/brand.ini

```

Usage
-----

[](#usage)

Now you can use Laravel Scout as described in the [official documentation](https://laravel.com/docs/5.3/scout).

### Where Clauses

[](#where-clauses)

This enginge allows you to add more advanced "where" clauses.

- addRange

```
   $users = App\User::search('Star Trek')
            ->where('age', new \Liugj\Xunsearch\Operators\RangeOperator(30,50))->get();

```

- setCollapse

```
   $users = App\User::search('Star Trek')
            ->where('city', new \Liugj\Xunsearch\Operators\CollapseOperator($num = 10))->get();

```

- setFuzzy

```
   $users = App\Users::search('Star Trek')
           ->where('**', new \Liugj\Xunsearch\Operators\FuzzyOperator($fuzzy = false))->get();

```

- setFacets

```
   $users = App\Users::search('Star Trek')
            ->where('***', new \Liugj\Xunsearch\Operators\FacetsOperator(array('age','city')))->get();

```

- addWeight

```
   $users = App\User::search('Star Trek')
   ->where('country', new \Liugj\Xunsearch\Operators\WeightOperator('US'))->get();

```

### Configuring Searchable Data

[](#configuring-searchable-data)

By default, the entire toArray form of a given model will be persisted to its search index. If you would like to customize the data that is synchronized to the search index, you may override the toSearchableArray method on the model:

```
