我有一个名为偏差属性的"文档"(activerecords).该属性的值为"Bin X""Bin $""Bin q""Bin%"等.
我正在尝试使用tire/elasticsearch来搜索属性.我正在使用空白分析器来索引偏差属性.这是我创建索引的代码:
settings :analysis => {
:filter => {
:ngram_filter => {
:type => "nGram",
:min_gram => 2,
:max_gram => 255
},
:deviation_filter => {
:type => "word_delimiter",
:type_table => ['$ => ALPHA']
}
},
:analyzer => {
:ngram_analyzer => {
:type => "custom",
:tokenizer => "standard",
:filter => ["lowercase", "ngram_filter"]
},
:deviation_analyzer => {
:type => "custom",
:tokenizer => "whitespace",
:filter => ["lowercase"]
}
}
} do
mapping do
indexes :id, :type => 'integer'
[:equipment, :step, …Run Code Online (Sandbox Code Playgroud) 我在我网站的主页上使用ElasticSearch.在我的验收测试中,当用户登录时,他被重定向到主页.
但是在测试中使用ES是昂贵的(需要创建和删除索引),因此我不希望每次用户浏览主页时都这样做.
我想只在测试有一些元数据时才进行实际的ES搜索:
config.before(:each) do
if example.metadata[:elastic]
Model.create_elasticsearch_index
end
end
scenario "Results should be ordered by distance", :elastic do
# tests...
end
Run Code Online (Sandbox Code Playgroud)
因此,我需要"模拟"搜索,而不是在测试没有弹性元数据时使用ES.
什么是实现这一目标的好方法?
我正在开发一个rails应用程序.使用宝石轮胎作为弹性研究的纽带.在多步形式我想在程序结束时索引.
有没有一种方法可以在create上跳过索引.
猜:Post.create(:indexing => false)或其他什么
或者在轮胎配置中说:只有索引具有属性的帖子:已发布设置为true
希望我清楚自己.提前谢谢你的答案.
干杯.
运行:Ruby 1.9.3p0(2011-10-30修订版33570)[x86_64-darwin11.2.0],Rails 3.2.0
我正试图通过各种协会的TIRE宝石进行弹性搜索.出于某种原因,我在TIRE导入或偶尔在视图上执行rake时不断收到以下错误/错误:
Daves-MacBook-Pro:outdoor dave$ rake environment tire:import CLASS=Gear FORCE=true
[IMPORT] Deleting index 'gears'
[IMPORT] Creating index 'gears' with mapping:
{"gear":{"properties":{}}}
[IMPORT] Starting import for the 'Gear' class
--------------------------------------------------------------------------------
101/101 | 100% rake aborted!######################################
undefined method `last_name' for nil:NilClass
Tasks: TOP => tire:import
Run Code Online (Sandbox Code Playgroud)
这是我的模型: GEAR
class Gear < ActiveRecord::Base
attr_accessible :title, :size, :price, :image_url, :sub_category_id, :user_id
belongs_to :user
belongs_to :sub_category
validates :title, presence: true
validates :size, presence: true
validates :price, presence: true
validates :sub_category_id, presence: true
validates :user_id, presence: …Run Code Online (Sandbox Code Playgroud) 我在elasticsearch(轮胎)与阵列字段和自定义分析器用于与min_ngram = 1和max_ngram = 10的ngram的索引.
现场示例
field1: [foo, bar, bof]
Run Code Online (Sandbox Code Playgroud)
我使用field1'f'的值构造一个查询,并返回field1中的一个值中包含'f'的文档.
问题:是否有可能只返回数组中匹配的值,例如在field1和查询'f'的情况下,只有'foo'和'bof'将返回并且'bar'将被省略,例如field1:[foo,bof ]?
我无法在Rails应用程序中使用Elasticsearch(和Tire)进行突出显示.我可以成功索引PDF附件并查询它们但我无法突出显示工作.
不熟悉ES所以不确定在哪里进行故障排除.将从映射和卷曲查询开始,但随时可以要求更多信息.
class Article < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
attr_accessible :title, :content, :published_on, :filename
mapping do
indexes :id, :type =>'integer'
indexes :title
indexes :content
indexes :published_on, :type => 'date'
indexes :attachment, :type => 'attachment',
:fields => {
:name => { :store => 'yes' },
:content => { :store => 'yes' },
:title => { :store => 'yes' },
:file => { :term_vector => 'with_positions_offsets', :store => 'yes' },
:date => { :store => 'yes' }
}
end
def to_indexed_json …Run Code Online (Sandbox Code Playgroud) 我试着用Post.search(keyword, :size => 10)和Post.search(keyword).size(10).但这些都不起作用.
我有一个关于突出显示嵌套对象字段的问题.
考虑这样的记录:
_source: {
id: 286
translations: [
{
id: 568
language: lang1
value: foo1 bar1
}
{
id: 569
language: lang2
value: foo2 bar2
}
]
}
Run Code Online (Sandbox Code Playgroud)
如果translations.value有ngram过滤器,是否可以突出显示嵌套对象中的匹配项?突出显示查询将如何显示.
非常感谢您的回复.
例如,如果某些东西具有更高的favorites_count,我希望它更具相关性,或者如果它最近更新它更相关.有没有办法做到这一点?这与标准的boost功能不同,因为这些字段不包含关键字,它们包含数值.