A Ruby client for Sonic search backend.
Add following line to your Gemfile:
gem 'sonic-ruby'
And then execute:
$ bundle
Or install it system-wide:
$ gem install sonic-ruby
Start with creating new client:
client = Sonic::Client.new('localhost', 1491, 'SecretPassword')
Now you can use #channel
method in order to connect to specific channels:
control = client.channel(:control)
ingest = client.channel(:ingest)
search = client.channel(:search)
Learn more about Sonic Channels.
# Init `ingest` channel
ingest = client.channel(:ingest)
# Add data to index
ingest.push('users', 'all', 1, 'Alexander Tipugin')
# => true
# Remove data from index
ingest.pop('users', 'all', 1, 'Alexander Tipugin')
# => 2
# Count collection/bucket/object items
ingest.count('users', 'all', 1)
# => 1
# Flush entire collection
ingest.flushc('users')
# => 1
# Flush entire bucket inside collection
ingest.flushb('users', 'all')
# => 1
# Flush specific object inside bucket
ingest.flusho('users', 'all', 1)
# => 2
# Init `search` channel
search = client.channel(:search)
# Find indexed object by term
search.query('users', 'all', 'tipugin')
# => 1
# Auto-complete word
search.suggest('users', 'all', 'alex')
# => alexander
- Take into account maximum buffer size.
- Consider using connection pool.
- Return more meaningful responses from commands (i.e. bool
true
instead of stringOK
, int1
instead of stringRESULT 1
etc).