redisearch-rb 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bea8f2a9f8cd93b9af535a88421f7aefda28c5bb
4
- data.tar.gz: d461f7bf50d79534630a4b93fd0325799685d515
3
+ metadata.gz: 223cca42fa38796e6abd0b5780b589dc2d0536bb
4
+ data.tar.gz: ee5aa7e8e327dd933cf8079d02fdbca425abb3aa
5
5
  SHA512:
6
- metadata.gz: 488b7e57c8bf46f3176b1e6d67382e4e51569cf772bb25aae06af7a05c97b079b78830de38e9bdee8ad6509a7bd491a1dcb16721b0ddd2a8484187225c02a24c
7
- data.tar.gz: 6c392435be663bbe350649bf8cd1c037d3829ded1e4ec066ab1db8e1c94c55ee42f20cf4036574ec608d5705f3309bf990bce1b91b1800f046a0382290237b2d
6
+ metadata.gz: 003b2d21b74b25530e9126028e416b003b690a05d29c7e9cee79abb46e5874ca1c9bbb2f4ae532f766897834f993729f3530785220ca66c1426385c8145b3619
7
+ data.tar.gz: 5a9856724a08319139ad6ad9af814f77eca878a247db345248b59ec051afe2016810f5c58f8bce718ce6db62b666493f130eaca390dcbee22730f4c596bb849e
@@ -1,4 +1,4 @@
1
1
  REDIS_TEST_URL=redis://127.0.0.1:6379
2
2
  REDIS_SERVER_PATH=redis-server
3
3
  REDIS_PORT=6379
4
- REDIS_MODULE_PATH=redissearch-0.16.so
4
+ REDIS_MODULE_PATH=module.so
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/redisearch-rb.svg)](https://badge.fury.io/rb/redisearch-rb) ![travis-ci](https://travis-ci.org/vruizext/redisearch-rb.svg?branch=master)
2
+
1
3
  # redisearch-rb
2
4
 
3
5
  A simple Ruby client for RediSearch module
@@ -10,8 +12,8 @@ First of all, you need to install RediSearch, if you haven't yet:
10
12
 
11
13
  1. Install Redis 4.0.0-rc3 https://github.com/antirez/redis/releases/tag/4.0-rc3
12
14
  2. Install RediSearch 0.16 http://redisearch.io/Quick_Start/
13
- 3. Edit your `redis.conf` file and add a `loadmodule` directive to load the RediSearch module.
14
- 4. You have to
15
+ 3. Edit your `redis.conf` file and add a `loadmodule` directive to load the RediSearch module built in the step 2.
16
+
15
17
  To install this gem, add this line to your application's Gemfile:
16
18
 
17
19
  ```ruby
@@ -26,8 +28,24 @@ Or install it yourself as:
26
28
 
27
29
  $ gem install redisearch-rb
28
30
 
29
- ## Usage
30
31
 
32
+ In order to run the tests, it's necessary to set some env variables (see .env.example):
33
+
34
+ - `REDIS_SERVER_PATH`, the path to the `redis-server` executable
35
+
36
+ - `REDIS_MODULE_PATH`, the path to the RediSearch module
37
+
38
+ - `REDIS_PORT`, the TCP port used by Redis server
39
+
40
+ - `REDIS_TEST_URL` is the Redis url where the server will be available. The port has to match the port specified in
41
+ `REDIS_PORT` or in the redis config file
42
+
43
+ - `REDIS_CONF_PATH`, is the path to your redis conf file. You can configure the port and the path to RediSearch module in
44
+ a config file if you prefer. If the path to the config file is given, `REDIS_MODULE_PATH` and `REDIS_PORT` will be
45
+ ignored
46
+
47
+
48
+ ## Usage
31
49
 
32
50
  ```ruby
33
51
  require 'redisearch-rb'
@@ -50,14 +68,12 @@ redisearch_client.add_docs(docs)
50
68
  # See query syntax here: http://redisearch.io/Query_Syntax/
51
69
  redisearch_client.search('lost|machina', { withscores: true })
52
70
  # => [{"title"=>"Ex Machina", "director"=>"Alex Garland", "year"=>"2014", "score"=>"2", "id"=>"id_2"},
53
- {"title"=>"Lost in translation", "director"=>"Sofia Coppola", "year"=>"2004", "score"=>"1", "id"=>"id_1"}]
71
+ # {"title"=>"Lost in translation", "director"=>"Sofia Coppola", "year"=>"2004", "score"=>"1", "id"=>"id_1"}]
54
72
 
55
73
  redisearch_client.search('@year:[2003 2004]')
56
74
  # => [{"title"=>"Lost in translation", "director"=>"Sofia Coppola", "year"=>"2004", "id"=>"id_1"}]
57
75
  ```
58
76
 
59
-
60
-
61
77
  ## Contributing
62
78
 
63
79
  Bug reports and pull requests are welcome on GitHub at https://github.com/vruizext/redisearch-rb.
@@ -5,8 +5,6 @@ require 'redis'
5
5
  # http://redisearch.io/
6
6
  #
7
7
  class RediSearch
8
- # VERSION = '0.1.0'
9
-
10
8
  # Create RediSearch client instance
11
9
  #
12
10
  # @param [String] idx_name name of the index
@@ -89,12 +87,7 @@ class RediSearch
89
87
  # @return [Hash] info returned by Redis key-value pairs
90
88
  #
91
89
  def info
92
- result = call(ft_info)
93
- return unless result.size > 0
94
- nr_of_rows = result.size / 2
95
- (0..nr_of_rows-1).map do |n|
96
-
97
- end
90
+ Hash[*call(ft_info)]
98
91
  end
99
92
 
100
93
  private
@@ -133,12 +126,12 @@ class RediSearch
133
126
  command << 'VERBATIM' if opts[:verbatim]
134
127
  if opts[:offset] || opts[:limit]
135
128
  limit = opts[:limit].to_i > 0 ? opts[:limit].to_i : -1
136
- command << "LIMIT #{opts[:offset].to_i} #{limit}"
129
+ command << ["LIMIT", opts[:offset], limit]
137
130
  end
138
131
  command << 'WITHSCORES' if opts[:withscores]
139
- command << "SCORER #{opts[:scorer]}" unless opts[:scorer].to_s.empty?
140
- command << "SLOP #{opts[:slop]}" if opts[:slop].to_i > 0
141
- command
132
+ command << ["SCORER", opts[:scorer]] unless opts[:scorer].to_s.empty?
133
+ command << ["SLOP", opts[:slop]] if opts[:slop].to_i > 0
134
+ command.flatten
142
135
  end
143
136
 
144
137
  def results_to_hash(results)
@@ -1,3 +1,3 @@
1
1
  class RediSearch
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -79,4 +79,15 @@ class RediSearchTest < Minitest::Test
79
79
  assert_empty @redisearch_client.search('@director:lost')
80
80
  assert_equal 1, @redisearch_client.search('@year:[2004 2005]').count
81
81
  end
82
+
83
+ def test_index_info
84
+ assert(@redisearch_client.create_index(@schema))
85
+ doc = ['id_1', ['title', 'Lost in translation', 'director', 'Sofia Coppola', 'year', '2004']]
86
+ assert(@redisearch_client.add_doc(*doc))
87
+ info = @redisearch_client.info
88
+ assert info.any?
89
+ assert_equal 1, info['num_docs'].to_i
90
+ assert_equal 1, info['max_doc_id'].to_i
91
+ assert_equal 5, info['num_terms'].to_i
92
+ end
82
93
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redisearch-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-04 00:00:00.000000000 Z
11
+ date: 2017-06-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  A simple Ruby client library for RediSearc. RediSearch is a Full-Text search index over Redis,