Skip to content

Instantly share code, notes, and snippets.

@nz nz/indextank.rb
Created Oct 17, 2011

Embed
What would you like to do?
IndexTank vs RSolr Ruby client syntax.
# config/initializers/indextank.rb
CLIENT = IndexTank::Client.new('http://:67xN9mHBV7BV8w@iej.api.indextank.com')
INDEX = CLIENT.indexes('idx')
# app/models/user.rb
INDEX.document("User:id:#{self.id}").add(:text => "#{self.name} #{self.address}")
# basically what ever I want
results = INDEX.search("something")
=> {"matches"=>2, "query"=>"something",
"facets"=>{}, "search_time"=>"0.009",
"results"=>[{"docid"=>"User:id:33", "query_relevance_score"=>-2217269.0},
{"docid"=>"User:id:38", "query_relevance_score"=>-2739353.0}]}
results = INDEX.search("something")
=> {"matches"=>2, "query"=>"something",
"facets"=>{}, "search_time"=>"0.009",
"results"=>[{"docid"=>"User:id:33", "query_relevance_score"=>-2217269.0},
{"docid"=>"User:id:38", "query_relevance_score"=>-2739353.0}]}
INDEX.document("User:id:#{self.id}").add(:text => "#{self.name} #{self.address}",
:categories => {:type => 'admin'})
results = INDEX.search("something")
=> {"matches"=>2, "query"=>"something",
"facets"=>{'type' => {'admin' => 1, 'user' => 1}}, "search_time"=>"0.009",
"results"=>[{"docid"=>"User:id:33", "query_relevance_score"=>-2217269.0},
{"docid"=>"User:id:38", "query_relevance_score"=>-2739353.0}]}
results = INDEX.search("something", :category_filters => { :type => 'admin'}))
=> {"matches"=>1, "query"=>"something",
"facets"=>{'type' => {'admin' => 1}, "search_time"=>"0.007",
"results"=>[{"docid"=>"User:id:33", "query_relevance_score"=>-2217269.0}
]}
>> require "rsolr"
=> true
>> INDEX = RSolr.connect :url => "http://index.websolr.com/solr/0a1b2c3d4e5f"
=> #<RSolr::Client:0x007fe5d99a64d0 @connection=#<RSolr::Connection:0x007fe5d99a64f8>, uri#<URI::HTTP:0x007fe5d9841f18 URL:http://ec2-west.websolr.com/solr/0a1b2c3d4e5f/, @options={:url=>"http://ec2-west.websolr.com/solr/0a1b2c3d4e5f"}
>> INDEX.add id: "User:id:#{1}",
?> name_text: "Foo Inc",
?> address_text: "123 Main Street"
=> {"responseHeader"=>{"status"=>0, "QTime"=>0}}
>> INDEX.get "select", params: { q: "something" }
=> {"responseHeader"=>{"status"=>0, "QTime"=>0, "params"=>{"wt"=>"ruby", "q"=>"something", "api"=>"0a1b2c3d4e5f"}}, "response"=>{"numFound"=>0, "start"=>0, "docs"=>[]}}
>> INDEX.add id: "User:id:#{1}",
?> name_text: "Foo Inc", address_text: "123 Main Street",
?> category_s: "admin"
=> {"responseHeader"=>{"status"=>0, "QTime"=>10}}
>> INDEX.get "select", params: { q: "something", fq: "category_s:admin" }
=> {"responseHeader"=>{"status"=>0, "QTime"=>0, "params"=>{"wt"=>"ruby", "q"=>"something", "api"=>"0a1b2c3d4e5f", "fq"=>"category_s:admin"}}, "response"=>{"numFound"=>0, "start"=>0, "docs"=>[]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.