2016-05-10 100 views
0

我使用的是Laravel 5.1mustafaaloko/elasticquent5包(found here)。Elasticsearch不返回部分結果

但是當試圖返回結果時,我只能在搜索確切的單詞時得到結果。如果我嘗試搜索部分單詞,它將不會返回任何內容。

我使用Profile::addAllToIndex();dd(Profile::search(Input::get('search_term')));

我的配置是這樣的:

<?php 

return array(

    /* 
    |-------------------------------------------------------------------------- 
    | Custom Elasticsearch Client Configuration 
    |-------------------------------------------------------------------------- 
    | 
    | This array will be passed to the Elasticsearch client. 
    | See configuration options here: 
    | 
    | http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/_configuration.html 
    */ 

    'config' => [ 
     'hosts'  => ['ahp.dev:9200'], 
     'logging' => true, 
     'logPath' => storage_path() . '/logs/elasticsearch.log', 
     'logLevel' => Monolog\Logger::WARNING, 
    ], 

    /* 
    |-------------------------------------------------------------------------- 
    | Default Index Name 
    |-------------------------------------------------------------------------- 
    | 
    | This is the index name that Elastiquent will use for all 
    | Elastiquent models. 
    */ 

    'default_index' => 'default', 

); 

回答

1

你應該嘗試使用searchByQuery,而不是search和使用query_string查詢

Profile::searchByQuery(array('query_string' => array('query' => Input::get('search_term')))); 
+0

我不得不在Input :: get('search_term')'之前和之後加入''*'來進行適應性調整,然後它就起作用了!謝謝! – Haring10

+0

哦,是的,忘記了。偉大的工作!一旦等待期結束, – Val

+0

將接受正確答案 – Haring10