ElasticSearch and Tire:如何使用html_strip [英] ElasticSearch and Tire : how to use html_strip

查看:228
本文介绍了ElasticSearch and Tire:如何使用html_strip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Rails项目中添加 char_filter html_strip 。但我不知道如何和在哪里做(轮胎宝石)。我不知道这可能是我的方式。



我现在的代码:

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

mapping do
索引:作者,类型:'string'
索引:content,type:'string',index_options:offsets,analyzer:'snowball',language:French,char_filter:'html_strip'
索引:名称,类型:'string',index_options:offsets,analyzer:'snowball',language:French,:boost => 5
索引: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
应该{string query,fields:[:name],default_operator:AND,分析器:'snowball'}
应该{string query,fields:[:content ],default_operator:AND,分析器:'snowball'}
应该{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的答案,我更改了我的代码:

 设置分析:{
分析器:{
html_analyzer:{
type:'custom',
tokenizer:'standard',
filter:['classic'],
char_filter :['html_strip']
}
}
} do
mapping do
索引:作者,键入:'string'
索引:内容,类型:'string',index_options:offsets,analyzer:'html_analyzer',search_analyzer:'snowball',language:French
索引:名称,类型:'string',index_options:offsets,search_analyzer: 'snowball',language:French,boost:5
索引:topic_id,type::integer,index::not_analyzed
end
end

我发贴在这里,如果这有助于某人:)

解决方案

你可以尝试如下:

 设置分析:{
analyzer:{
some_custom_analyzer:{
type:'custom',
tokenizer:'standard'
过滤器:['classic'],
char_filter:['html_strip']
}
}
}
/ pre>

然后:

 索引:内容,类型: string',index_options:offsets,analyzer:'snowball',search_analyzer:'some_custom_analyzer'

a href =http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis.html =nofollow>分析,分析仪 tokenizers 过滤器 char filters


I'd like to add the char_filter html_strip in my Rails Project. But I'm not sure how and where to do it with the (re)tire gem. I'm not even sure it's possible the way I'm doing it.

My code for the moment :

  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

I'm not really sure how to implement it. I tried many things but with no results for now!

Thanks!

EDIT

I changed my code, following IS04's answer, to that :

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

I post it here, if it helps somebody someday :)

解决方案

you could try something like:

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

then:

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

analysis, analyzer, tokenizers, filters, char filters

这篇关于ElasticSearch and Tire:如何使用html_strip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆