用elasticsearch-php laravel為什麼不能回傳高亮資料?

WBOY
發布: 2016-08-04 09:20:13
原創
973 人瀏覽過

<code>    namespace App\Http\Controllers\Search;
    use Illuminate\Http\Request;
    use App\Http\Requests;
    use App\Http\Controllers\Controller;
    use Elasticsearch\Client;

class Index extends Controller
{
    protected $client;
    public function __construct(Client $client)
    {
        $this->client = $client;
    }
    public function search_test(Request $request,$filter='list'){
        $word = trim($request->input('word'));

        $s=is_null($request->input('s'))?10:trim($request->input('s'));//一页多少条
        $f=is_null($request->input('f'))?1:trim($request->input('f'));//当前页数
        $fr=($f-1)*$s;//当前页从第一条记录开始
        $params=[
            'index' => 's_index',
            'type' => 's_type',
            'body' => [
                'query' => [
                    'bool' => [
                        'should' => [
                            [ 'match' => [ 'title' => $word ] ],
                            [ 'match' => [ 'description' => $word ] ],
                        ]
                    ]
                ]
                ,'from'=>$fr, 'size'=>$s
                ,'highlight'=>[
                    'fields'=>[
                        'title'=>[]
                    ]
                ]
            ]
        ];

        $response = $this->client->search($params);

        echo "<pre class="brush:php;toolbar:false">";
        var_dump($response);
        echo "
"; } }
登入後複製
登入後複製

查詢結果都能返回,就是無highlight數據,求朋友幫忙! ! !

回覆內容:

<code>    namespace App\Http\Controllers\Search;
    use Illuminate\Http\Request;
    use App\Http\Requests;
    use App\Http\Controllers\Controller;
    use Elasticsearch\Client;

class Index extends Controller
{
    protected $client;
    public function __construct(Client $client)
    {
        $this->client = $client;
    }
    public function search_test(Request $request,$filter='list'){
        $word = trim($request->input('word'));

        $s=is_null($request->input('s'))?10:trim($request->input('s'));//一页多少条
        $f=is_null($request->input('f'))?1:trim($request->input('f'));//当前页数
        $fr=($f-1)*$s;//当前页从第一条记录开始
        $params=[
            'index' => 's_index',
            'type' => 's_type',
            'body' => [
                'query' => [
                    'bool' => [
                        'should' => [
                            [ 'match' => [ 'title' => $word ] ],
                            [ 'match' => [ 'description' => $word ] ],
                        ]
                    ]
                ]
                ,'from'=>$fr, 'size'=>$s
                ,'highlight'=>[
                    'fields'=>[
                        'title'=>[]
                    ]
                ]
            ]
        ];

        $response = $this->client->search($params);

        echo "<pre class="brush:php;toolbar:false">";
        var_dump($response);
        echo "
"; } }
登入後複製
登入後複製

查詢結果都能返回,就是無highlight數據,求朋友幫忙! ! !

暫時沒做過搜尋服務,感覺高亮的資料應該在控制器裡面處理的吧。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!