2013-03-10 1 views
3

인덱싱 된 요소를 편집하는 방법을 알아낼 수 없습니다. Google은 나에게도 답변을 제공하지 않습니다. 그래서, 그것이 가능하다면 나는 확신하지 못한다. 이전에 모든 작업을 다시 색인하기 만하면 데이터가 커짐에 따라 느리고 느려집니다. 하나의 요소가 편집 된 후에 어떻게 다시 색인화합니까?타이어 및 탄성 검색을 사용하여 하나의 요소 만 다시 색인하려면 어떻게합니까?

내가 지금하고있는 일은 다음과 같습니다.

def add_ele(ele) 

    Tire.index ELE_INDEX do 
     store :id => ele.ele_id, :title => ele.title, :tags => ele.tags, :itunes_description => ele.itunes_description 

     refresh 
    end 
end 

def delete_ele_index 
    Tire.index ELE_INDEX do 
     delete 
    end 
end 

전체 색인을 삭제하고 데이터베이스의 모든 요소를 ​​반복하면 다시 추가 할 수 있습니다. 도움을 많이 주셔서 감사합니다.

답변

3

을 향후 참고로, 여기

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] 
+0

내가 새로 고침을 호출해야합니까 업데이트를 사용하는 방법의 완벽한 예를 게다가. 나는 그것이 작동하도록 새로 고침을 호출해야합니다. – toy

+1

예. 색인에 즉시 액세스하려는 경우 – peter

2

색인을 삭제하지 않아도됩니다. 동일한 ID로 문서를 두 번 저장하면 기존 색인이 업데이트됩니다.

update api도 있습니다. 일부 필드를 변경하려는 경우 & 전체 문서를 전송하지 않아도됩니다. 가장 단순한 형태의 당신은 예를 들어, 업데이트하는 속성을 포함하는 해시를 전달합니다

update type, id, :doc => {:title => 'new title'}