Thursday, December 29, 2011

[Workaround] Ripple Riak Access via Solr Interface

Riak and Ripple are both undergoing heavy development. If you are relying on using Ripple to enable_searching on a new bucket, you'll need my fork or the monkey-patch below.

# Monkey-patch a broken Solr interface...                                                                                                   
module Riak                                                                                                                                 
  class Bucket                                                                                                                              
    def is_indexed?                                                                                                                         
      props['search'] == true || (props['precommit'] && props['precommit'].include?(SEARCH_PRECOMMIT_HOOK))                                 
    end                                                                                                                                     
    def enable_index!                                                                                                                       
      unless is_indexed?                                                                                                                    
        self.props = {"precommit" => ((props['precommit']||[]) + [SEARCH_PRECOMMIT_HOOK]), "search" => true}                                
      end                                                                                                                                   
    end                                                                                                                                     
    def disable_index!                                                                                                                      
      if is_indexed?                                                                                                                        
        self.props = {"precommit" => ((props['precommit']||[]) - [SEARCH_PRECOMMIT_HOOK]), "search" => false}                               
      end                                                                                                                                   
    end                                                                                                                                     
  end                                                                                                                                       
end     

0 comments: