PHP code example of xcalder / laravel-scout-xunsearch

1. Go to this page and download the library: Download xcalder/laravel-scout-xunsearch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xcalder / laravel-scout-xunsearch example snippets


SCOUT_DRIVER=xunsearch
SCOUT_PREFIX=opx
XUNSEARCH_INDEX_HOST=127.0.0.1:8383
XUNSEARCH_SEARCH_HOST=127.0.0.1:8384
XUNSEARCH_SCHEMA_ARTICLE=config/xunsearch/article.ini
XUNSEARCH_SCHEMA_SPECIAL=config/xunsearch/special.ini
XUNSEARCH_SCHEMA_FORUM=config/xunsearch/forum.ini

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



namespace App;

use Scout\Xunsearch\Searchable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Searchable;

    /**
     * 获取模型的索引名称.
     * 加上前缀,为了多个项目索引共存
     *
     * @return string
     */
    public function searchableAs()
    {
        return config('scout.prefix').'_article';
    }

    /**
     * Get the indexable data array for the model.
     *
     * @return array
     */
    public function toSearchableArray()
    {
        $array = $this->toArray();

        // Customize array...

        return $array;
    }
}