redisearch-rb 0.1.4 → 0.1.5
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 +4 -4
- data/.env.example +1 -1
- data/README.md +22 -6
- data/lib/redisearch.rb +5 -12
- data/lib/redisearch/version.rb +1 -1
- data/test/redisearch_test.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 223cca42fa38796e6abd0b5780b589dc2d0536bb
|
4
|
+
data.tar.gz: ee5aa7e8e327dd933cf8079d02fdbca425abb3aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 003b2d21b74b25530e9126028e416b003b690a05d29c7e9cee79abb46e5874ca1c9bbb2f4ae532f766897834f993729f3530785220ca66c1426385c8145b3619
|
7
|
+
data.tar.gz: 5a9856724a08319139ad6ad9af814f77eca878a247db345248b59ec051afe2016810f5c58f8bce718ce6db62b666493f130eaca390dcbee22730f4c596bb849e
|
data/.env.example
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](https://badge.fury.io/rb/redisearch-rb) 
|
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
|
-
|
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.
|
data/lib/redisearch.rb
CHANGED
@@ -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
|
-
|
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
|
129
|
+
command << ["LIMIT", opts[:offset], limit]
|
137
130
|
end
|
138
131
|
command << 'WITHSCORES' if opts[:withscores]
|
139
|
-
command << "SCORER
|
140
|
-
command << "SLOP
|
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)
|
data/lib/redisearch/version.rb
CHANGED
data/test/redisearch_test.rb
CHANGED
@@ -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
|
+
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-
|
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,
|