2016-05-24 27 views
0

我對elasticsearch和FOSElastica很陌生, 我想得到maped field的相關結果,它代表學校的名字。FOS Elastica,全文檢索

我的配置:

fos_elastica: 
clients: 
    default: { host: localhost, port: 9200 } 
indexes: 
    app: 
     settings: 
       index: 
        analysis: 
        analyzer: 
         czech : 
         tokenizer: standard 
         filter : [czech_stop, czech_stemmer ,lowercase, asciifolding] 
        filter: 
         czech_stop: 
         type: stop 
         stopwords: _czech_ 
         czech_stemmer: 
         type: stemmer 
         languague: czech 

     types: 
      school: 
       mappings: 
        name: 
         type: string 
         analyzer : czech 
         boost : 10 
       persistence: 
        driver: orm 
        model: Yearbook\SUBundle\Entity\School 
        provider: ~ 
        listener: 
         immediate: ~ 
        finder: ~ 

在名稱字段中存儲學校名稱。我得到零結果使用命令行fos:elastica:search school "Hi",但是搜索整個單詞工作正常fos:elastica:search school "High"

我也找到了不同的方式來獲得在控制器的結果,但沒有任何工作。我認爲這個問題可能在配置文件中。

我沒有找到任何相關的問題。 謝謝你們的答覆

回答

0

找到解決方案,

加入custom_filter EdgeNGram到confing文件:

fos_elastica: 
clients: 
    default: { host: localhost, port: 9200 } 
indexes: 
    app: 
     settings: 
       index: 
        analysis: 
        analyzer: 
         custom_search_analyzer : 
         type  : custom 
         tokenizer: standard 
         filter : [czech_stop, czech_stemmer ,lowercase, asciifolding,standard] 
         custom_index_analyzer : 
         tokenizer: standard 
         type  : custom 
         filter : [czech_stop, czech_stemmer ,lowercase, asciifolding,standard,custom_filter] 
        filter: 
         custom_filter: 
          type: edgeNGram 
          side: front 
          min_gram: 1 
          max_gram: 20 
         czech_stop: 
         type: stop 
         stopwords: _czech_ 
         czech_stemmer: 
         type: stemmer 
         languague: czech 

     types: 
      school: 
       mappings: 
        name: 
         type: string 
         search_analyzer : custom_search_analyzer 
         index_analyzer : custom_index_analyzer 
         boost : 10 
        urlFriendly: 
         type: string 
       persistence: 
        driver: orm 
        model: Yearbook\SUBundle\Entity\School 
        provider: ~ 
        listener: 
         immediate: ~ 
        finder: ~ 

獲得在控制器的結果列表:

  $needle=$request->request->get('needle'); 

     $index =$this->container->get('fos_elastica.index.app.school'); 

     $searchQuery=new QueryString(); 
     $searchQuery->setParam('query',$needle); 
     $searchQuery->setDefaultOperator('OR'); 
     $searchQuery->setParam('fields',array('name','urlFriendly')); 
     $results=$index->search($searchQuery,10)->getResults();