2014-08-30 7 views
1

내 레일 프로젝트에 char_filterhtml_strip을 추가하고 싶습니다. 그러나 (재) 타이어 보석으로 어떻게 그리고 어디에서해야하는지 잘 모르겠습니다. 내가 할 수있는 방법조차도 가능하지 않다. 순간에 대한ElasticSearch and Tire : html_strip 사용 방법

내 코드 :

include Tire::Model::Search 
    include Tire::Model::Callbacks 

    mapping do 
    indexes :author, type: 'string' 
    indexes :content, type: 'string', index_options: "offsets", analyzer: 'snowball', language: "French", char_filter: 'html_strip' 
    indexes :name, type: 'string', index_options: "offsets", analyzer: 'snowball', language: "French", :boost => 5 
    indexes :topic_id, type: :integer, :index => :not_analyzed 
    end 

    def self.search params 
    query = params[:query] 

    tire.search do 
     query do 
     boolean minimum_number_should_match: 1 do 
      should { string query, fields: [:name], default_operator: "AND", analyzer: 'snowball' } 
      should { string query, fields: [:content], default_operator: "AND", analyzer: 'snowball' } 
      should { string query, fields: [:author], default_operator: "AND" } 
      must { range :topic_id, gt: 0 } 
     end 
     end 

     highlight :content, :author, :name, options: {pre_tags: ['<em style="background-color: yellow">'], post_tags: ['</em>'], :number_of_fragments => 50} 
    end 
    end 

나는 그것을 구현하는 방법을 정말 모르겠어요. 나는 많은 결과를 보았지만 결과는 아직 없었다.

감사합니다.

편집 것과

내가 IS04의 대답 다음 내 코드를 변경

:

settings analysis: { 
     analyzer: { 
      html_analyzer: { 
       type: 'custom', 
       tokenizer: 'standard', 
       filter: ['classic'], 
       char_filter: ['html_strip'] 
      } 
     } 
    } do 
    mapping do 
     indexes :author, type: 'string' 
     indexes :content, type: 'string', index_options: "offsets", analyzer: 'html_analyzer', search_analyzer: 'snowball', language: "French" 
     indexes :name, type: 'string', index_options: "offsets", search_analyzer: 'snowball', language: "French", boost: 5 
     indexes :topic_id, type: :integer, index: :not_analyzed 
    end 
    end 

는 누군가가 언젠가는 도움이된다면 내가 여기에 게시 :

+0

당신이 무엇을 시도했다 설명하고 당신이 말은 아마 가치가 char filters "결과가 없습니다"로. 나는. 그것은'content' 검색은 html 태그 (필터가 작동하지 않음을 나타냄)를 검색 할 때 여전히 결과를 반환한다는 것을 의미합니다 - 또는 'content'는 es에서 반환 될 때 HTML 태그를 여전히 포함합니다. 반환되는 콘텐츠). – Shadwell

+0

솔루션은 모든 버전의 Elasticsearch에서 작동합니까? – SsouLlesS

답변

2

당신이 뭔가를 시도 할 수 있습니다 : 다음

settings analysis: {    
    analyzer: {      
     some_custom_analyzer: { 
     type: 'custom', 
     tokenizer: 'standard',  
     filter: ['classic'],   
     char_filter: ['html_strip'] 
     } 
    } 
    } 

:

indexes :content, type: 'string', index_options: "offsets", analyzer: 'snowball', search_analyzer: 'some_custom_analyzer' 

analysis, analyzer, tokenizers, filters,