redisearch-rb 0.1.7 → 0.1.8

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: 989e86efdc440fc616ee1741256c81b829ca69b0
4
- data.tar.gz: 2f2d59a65e355750b045f317dc7e6619d120bb0b
3
+ metadata.gz: '01498d9fe5aeb06096b245b7045bc558d66edfb7'
4
+ data.tar.gz: 659c1c312134ec3acba593feaa8ab1597d21611f
5
5
  SHA512:
6
- metadata.gz: 3b61fc7f81b2d86c33142c3c01a3b2b79647b5d40c0f5cfdca094ac9710104c439e153f8c8ab68a29503c97cbedc64a7f440824e02521051f7b0a304a59c25e4
7
- data.tar.gz: 9208b2b791c07ce5a0dc7b700e9cefc99030a255444500a5bc99103a053b6af167baa17a14120cd7111c8b55a6804bb65ad81e393406a6e642a4a28a6f2f0253
6
+ metadata.gz: a672c99130602f2461208d94f50e659d77f4e9b38b9b2149ed5e28665b1a5a3283fe6217a4322cdfba4af990849f09bd51fa2b9791f889bdea570458c3d86205
7
+ data.tar.gz: a283066a539ead576d84dd83265f911d090fbc86b340a1f9b26d033305c5943fece67a7fbd51374c59c2ae86984752341ae39a2d551dee7fbbb29d814ceb1baa
@@ -99,6 +99,12 @@ class RediSearch
99
99
  results_to_hash(call(ft_search(query, opts)), opts)
100
100
  end
101
101
 
102
+ # Fetch a document by id
103
+ def get_by_id(id)
104
+ Hash[with_reconnect { @redis.hgetall(id) } || []]
105
+ .tap { |doc| doc['id'] = id unless doc.empty? }
106
+ end
107
+
102
108
  # Return information and statistics on the index.
103
109
  # @return [Hash] info returned by Redis key-value pairs
104
110
  #
@@ -108,6 +114,10 @@ class RediSearch
108
114
 
109
115
  private
110
116
 
117
+ def with_reconnect
118
+ @redis.with_reconnect { yield }
119
+ end
120
+
111
121
  def multi
112
122
  @redis.with_reconnect { @redis.multi { yield } }
113
123
  end
@@ -1,3 +1,3 @@
1
1
  class RediSearch
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
@@ -72,6 +72,16 @@ class RediSearchTest < Minitest::Test
72
72
  assert_includes(search_result.to_s, 'Ex Machina')
73
73
  end
74
74
 
75
+ def test_get_by_id
76
+ assert(@redisearch_client.create_index(@schema))
77
+ docs = [['id_1', ['title', 'Lost in translation', 'director', 'Sofia Coppola', 'year', '2004']],
78
+ ['id_2', ['title', 'Ex Machina', 'director', 'Alex Garland', 'year', '2014']]]
79
+ assert(@redisearch_client.add_docs(docs))
80
+ doc = @redisearch_client.get_by_id('id_1')
81
+ assert_equal('id_1', doc['id'])
82
+ assert_equal('Lost in translation', doc['title'])
83
+ end
84
+
75
85
  def test_search_simple_query
76
86
  assert(@redisearch_client.create_index(@schema))
77
87
  docs = [['id_1', ['title', 'Lost in translation', 'director', 'Sofia Coppola', 'year', '2004']],
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.7
4
+ version: 0.1.8
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-08-08 00:00:00.000000000 Z
11
+ date: 2017-09-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  A simple Ruby client library for RediSearch.
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  requirements: []
55
55
  rubyforge_project:
56
- rubygems_version: 2.6.8
56
+ rubygems_version: 2.6.11
57
57
  signing_key:
58
58
  specification_version: 4
59
59
  summary: A simple Ruby client library for RediSearch