为了将来参考,这里有一个完整的例子来说明如何使用更新
require 'tire'
require 'yajl/json_gem'
Tire.index 'articles' do
delete
create
articles = [
{ :id => '1', :type => 'article', :title => 'one', :tags => ['ruby'] },
{ :id => '2', :type => 'article', :title => 'two', :tags => ['ruby', 'python'] },
{ :id => '3', :type => 'article', :title => 'three', :tags => ['java'] },
{ :id => '4', :type => 'article', :title => 'four', :tags => ['ruby', 'php'] }
]
Tire.index 'articles' do
import articles
end
refresh
Tire.index 'articles' do
update 'article', 1, :doc => { :title => 'tone' }
end
refresh
s = Tire.search 'articles' do
query do
string 'title:T*'
end
filter :terms, :tags => ['ruby']
sort { by :title, 'desc' }
end
s.results.each do |document|
puts "* #{ document.title } [tags: #{document.tags.join(', ')}]"
end
end
gives
* two [tags: ruby, python]
* tone [tags: ruby]