sonicsearch 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09d2d8a111ea48432da7baf36ecdd4943fa979d5440bd6f8b5dd73a54b32e582'
4
- data.tar.gz: c344c981b1615ee3fdf4c6f1ad5620cbb5f45b80a71e8f1b089512374a0d3fcc
3
+ metadata.gz: 310200a931d056674eaae3a0d968ac41d7d513bff489a3ebd2416c7d411277c4
4
+ data.tar.gz: 7f2a3eccfc3bd5802f3b8f406777c2f8f5bf47bdadc347604e8f2adb3f9db579
5
5
  SHA512:
6
- metadata.gz: 0ea799c0edbbdc2a56c4641fa9a1064c7be985962f9db1ae42e93b7b7bc17f2a5d1fdf0d6c2ad8e1b34526d6ade9f21cb1bf8ca48704938ee97a0f2800cb633d
7
- data.tar.gz: fb81a96b013558a6ca54d6d355d6a9de29e759a2954fc50f75a70b12353b21529b7c6da2082f9d44667183c7883a417eb6f8b9bd1c8eb51eac8e3139709f1dec
6
+ metadata.gz: 7c7cad55d495e7e5d96f2f8c6161a8368a8aa7df3f2c7f9e241b1dba706488a8fc90efdb113099090bdef8666c26bef7dcaf9053e5a44b336e803f887a1afc78
7
+ data.tar.gz: 70ce75742ac929b1793fa6c1919fe5e0b3415b36ff04a0927ab01a69e0162f1204d30c3993d47f4a7fd761250e439d53583d4fd2c855b071e33ed7989df15272
@@ -0,0 +1,2 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # Sonic Search
2
2
 
3
- [![Gem version](https://badge.fury.io/gh/oshanz%2Fsonicsearch.svg)](https://badge.fury.io/gh/oshanz%2Fsonicsearch.svg) [![Build Status](https://travis-ci.org/oshanz/sonicsearch.svg?branch=master)](https://travis-ci.org/oshanz/sonicsearch) [![Code Climate](https://codeclimate.com/github/oshanz/sonicsearch/badges/gpa.svg)](https://codeclimate.com/github/oshanz/sonicsearch)
4
- Rails friendly driver for the sonic search backend.
5
- This is a very early stage of the package, bugfixes and api changes are welcome
3
+ [![Gem Version](https://badge.fury.io/rb/sonicsearch.svg)](https://badge.fury.io/rb/sonicsearch) [![Build Status](https://travis-ci.org/oshanz/sonicsearch.svg?branch=master)](https://travis-ci.org/oshanz/sonicsearch) [![Code Climate](https://codeclimate.com/github/oshanz/sonicsearch/badges/gpa.svg)](https://codeclimate.com/github/oshanz/sonicsearch)
4
+
5
+ Rails friendly driver for the [sonic search](https://github.com/valeriansaliou/sonic) backend.
6
+ ![Alt text](https://gist.githubusercontent.com/oshanz/7b3278dacbcaa82fac9084d9386523c3/raw/c500e27e5e18f0cc20dd5a76fad424ef3d453ce3/colortext.svg?sanitize=true)
6
7
 
7
8
  ## Installation
8
9
 
@@ -19,9 +20,3 @@ And then execute:
19
20
  ## Usage
20
21
 
21
22
  - sonarsearch will always try to maintain the API compatibility with [searchkick](https://github.com/ankane/searchkick), so you can switch between search engines with less effort as your requirements.
22
-
23
- ## Development
24
-
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
-
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
@@ -1,6 +1,34 @@
1
- require 'sonicsearch/version'
1
+ # frozen_string_literal: true
2
2
 
3
+ require 'sonicsearch/version'
4
+ require 'async/io'
3
5
  module Sonicsearch
4
6
  class Error < StandardError; end
5
- # Your code goes here...
7
+
8
+ class ChannelFactory
9
+ def search_channel
10
+ connect(mode: 'search')
11
+ end
12
+
13
+ def ingest_channel
14
+ connect(mode: 'ingest')
15
+ end
16
+
17
+ def control_channel
18
+ connect(mode: 'control')
19
+ end
20
+
21
+ def connect(mode: nil)
22
+ client = Async::IO::Endpoint.tcp('localhost', 1491)
23
+ client.connect do |peer|
24
+ result = peer.write("START #{mode} password")
25
+ message = peer.read(512)
26
+ puts "Sent #{data}, got response: #{message}"
27
+ end
28
+ end
29
+
30
+ def close
31
+ # tcp_clien.send('QUIT')
32
+ end
33
+ end
6
34
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sonicsearch
4
+ class Control
5
+ def connection
6
+ ChannelFactory.new.control_channel
7
+ end
8
+
9
+ def trigger(action)
10
+ connection.connect do |peer|
11
+ peer.write("TRIGGER #{action}")
12
+ message = peer.read(512)
13
+
14
+ puts "Sent #{data}, got response: #{message}"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sonicsearch
4
+ class Ingest
5
+ def push(collection_id, bucket_id, object_id, text)
6
+ cmd = "PUSH #{collection_id} #{bucket_id} #{object_id} #{text}"
7
+ connection.connect do |peer|
8
+ peer.write(cmd)
9
+ end
10
+ end
11
+
12
+ def pop(collection_id, bucket_id, object_id, text)
13
+ cmd = "POP #{collection_id} #{bucket_id} #{object_id} #{text}"
14
+ connection.connect do |peer|
15
+ peer.write(cmd)
16
+ end
17
+ end
18
+
19
+ def count(collection_id, bucket_id, object_id)
20
+ cmd = "COUNT #{collection_id} #{bucket_id} #{object_id} #{text}"
21
+ connection.connect do |peer|
22
+ peer.write(cmd)
23
+ end
24
+ end
25
+
26
+ def flushc(collection_id)
27
+ cmd = "FLUSHC #{collection_id}"
28
+ connection.connect do |peer|
29
+ peer.write(cmd)
30
+ end
31
+ end
32
+
33
+ def flushb(collection_id, _bucket_id)
34
+ cmd = "FLUSHB #{collection_id}"
35
+ connection.connect do |peer|
36
+ peer.write(cmd)
37
+ end
38
+ end
39
+
40
+ def flusho(collection_id, _bucket_id, _object_id)
41
+ cmd = "FLUSHO #{collection_id}"
42
+ connection.connect do |peer|
43
+ peer.write(cmd)
44
+ end
45
+ end
46
+
47
+ def connection
48
+ ChannelFactory.new.ingest_channel
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'async/io'
4
+
5
+ module Sonicsearch
6
+ class Search
7
+ def connection
8
+ ChannelFactory.new.search_channel
9
+ end
10
+
11
+ def query(collection_id, bucket_id, terms_text, limit, offset)
12
+ cmd = "QUERY #{collection_id} #{bucket_id} #{terms_text}"
13
+ cmd += " LIMIT(#{limit})" unless limit.nil?
14
+ cmd += " OFFSET(#{limit})" unless offset.nil?
15
+ connection.connect do |peer|
16
+ peer.write(cmd)
17
+ message = peer.read(512) # PENDING CjPvE5t9
18
+ puts "Sent #{data}, got response: #{message}"
19
+ end
20
+ search_done = false
21
+ while search_done
22
+ Async do |_task|
23
+ endpoint.connect do |peer|
24
+ message = peer.read(512) # received EVENT QUERY CjPvE5t9
25
+ puts "Sent #{data}, got response: #{message}"
26
+ search_done = true
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ def suggest(collection_id, bucket_id, word_text, limit, offset)
33
+ cmd = "SUGGEST #{collection_id} #{bucket_id} #{word_text}"
34
+ cmd += " LIMIT(#{limit})" unless limit.nil?
35
+ cmd += " OFFSET(#{limit})" unless offset.nil?
36
+ connection.connect do |peer|
37
+ peer.write(cmd)
38
+ message = peer.read(512) # PENDING CjPvE5t9
39
+ puts "Sent #{data}, got response: #{message}"
40
+ end
41
+ search_done = false
42
+ while search_done
43
+ Async do |_task|
44
+ endpoint.connect do |peer|
45
+ message = peer.read(512) # received EVENT SUGGEST CjPvE5t9
46
+ puts "Sent #{data}, got response: #{message}"
47
+ search_done = true
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module Sonicsearch
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'sonicsearch/version'
@@ -35,7 +37,9 @@ Gem::Specification.new do |spec|
35
37
  spec.required_ruby_version = '>= 2.5'
36
38
 
37
39
  spec.add_dependency 'activemodel', '>= 4.2'
38
- spec.add_dependency 'faraday', '~> 0.9.2'
40
+ spec.add_dependency 'async-io', '~> 1.20'
41
+ # spec.add_dependency 'connection_pool', '~> 2.2'
42
+ # spec.add_dependency 'concurrent-ruby', '~> 1.1'
39
43
 
40
44
  spec.add_development_dependency 'bundler', '~> 2.0'
41
45
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sonicsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oshan Wisumperuma
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: faraday
28
+ name: async-io
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.2
33
+ version: '1.20'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.9.2
40
+ version: '1.20'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +89,7 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
91
  - ".rspec"
92
+ - ".rubocop.yml"
92
93
  - ".travis.yml"
93
94
  - CHANGELOG.md
94
95
  - CODE_OF_CONDUCT.md
@@ -99,6 +100,9 @@ files:
99
100
  - bin/console
100
101
  - bin/setup
101
102
  - lib/sonicsearch.rb
103
+ - lib/sonicsearch/control.rb
104
+ - lib/sonicsearch/ingest.rb
105
+ - lib/sonicsearch/search.rb
102
106
  - lib/sonicsearch/version.rb
103
107
  - sonicsearch.gemspec
104
108
  homepage: https://github.com/oshanz/sonicsearch