blurrily 0.3.0 → 1.0.0
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/lib/blurrily/client.rb +31 -24
- data/lib/blurrily/command_processor.rb +1 -2
- data/lib/blurrily/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10d0da3c08622113e1580e66c8dce70c440e5c84
|
4
|
+
data.tar.gz: ca80fdcd586ba8b9723799523e5eaef766116a0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d563833faf1eb740600d6f628e378de3b4252a512a03758b8dc1e7dfd604837818ea7f53d8a6fef67522eabd355cd8d556e429406d09856a4151d48b232f8a5f
|
7
|
+
data.tar.gz: f46114e88375943a7423f094fe0b4c9a8fa2d28e22165434456b0b5d46758b175bb6106569738a3d118cd43fddcf174e04c51161287c3ce7683fb8583349e88a
|
data/lib/blurrily/client.rb
CHANGED
@@ -8,64 +8,71 @@ module Blurrily
|
|
8
8
|
class Client
|
9
9
|
Error = Class.new(RuntimeError)
|
10
10
|
|
11
|
-
#
|
11
|
+
# Initialize a new {Blurrily::Client} connection to {Blurrily::Server}.
|
12
12
|
#
|
13
|
-
# host
|
13
|
+
# @param host IP Address or FQDN of the Blurrily::Server.
|
14
14
|
# Defaults to Blurrily::DEFAULT_HOST.
|
15
|
-
# port
|
15
|
+
# @param port Port Blurrily::Server is listening on.
|
16
16
|
# Defaults to Blurrily::DEFAULT_PORT.
|
17
|
-
# db_name
|
17
|
+
# @param db_name Name of the data store being targeted.
|
18
18
|
# Defaults to Blurrily::DEFAULT_DATABASE.
|
19
19
|
#
|
20
20
|
# Examples
|
21
21
|
#
|
22
|
-
#
|
23
|
-
#
|
22
|
+
# ```
|
23
|
+
# Blurrily::Client.new('127.0.0.1', 12021, 'location_en')
|
24
|
+
# # => #<Blurrily::Client:0x007fcd0d33e708 @host="127.0.0.1", @port=12021, @db_name="location_en">
|
25
|
+
# ```
|
24
26
|
#
|
25
|
-
#
|
27
|
+
# @returns the instance of {Blurrily::Client}
|
26
28
|
def initialize(options = {})
|
27
29
|
@host = options.fetch(:host, DEFAULT_HOST)
|
28
30
|
@port = options.fetch(:port, DEFAULT_PORT)
|
29
31
|
@db_name = options.fetch(:db_name, DEFAULT_DATABASE)
|
30
32
|
end
|
31
33
|
|
32
|
-
#
|
34
|
+
# Find record references based on a given string (needle)
|
33
35
|
#
|
34
|
-
# needle
|
36
|
+
# @param needle The string you're searching for matches on.
|
35
37
|
# Must not contain tabs.
|
36
38
|
# Required
|
37
|
-
# limit
|
38
|
-
#
|
39
|
+
# @param limit Limit the number of results retruned (default: 10).
|
40
|
+
# Must be numeric.
|
39
41
|
# Optional
|
40
42
|
#
|
41
43
|
# Examples
|
42
44
|
#
|
43
|
-
#
|
44
|
-
#
|
45
|
+
# ```
|
46
|
+
# @client.find('London')
|
47
|
+
# # => [[123,6,3],[124,5,3]...]
|
48
|
+
# ```
|
45
49
|
#
|
46
|
-
#
|
50
|
+
# @returns an Array of matching [`ref`,`score`,`weight`] ordered by score. `ref` is the identifying value of the original record.
|
51
|
+
# Note that unless modified, `weight` is simply the string length.
|
47
52
|
def find(needle, limit = nil)
|
48
53
|
limit ||= LIMIT_DEFAULT
|
49
54
|
check_valid_needle(needle)
|
50
55
|
raise(ArgumentError, "LIMIT value must be in #{LIMIT_RANGE}") unless LIMIT_RANGE.include?(limit)
|
51
56
|
|
52
57
|
cmd = ["FIND", @db_name, needle, limit]
|
53
|
-
send_cmd_and_get_results(cmd).map(&:to_i)
|
58
|
+
send_cmd_and_get_results(cmd).map(&:to_i).each_slice(3).to_a
|
54
59
|
end
|
55
60
|
|
56
|
-
#
|
61
|
+
# Index a given record.
|
57
62
|
#
|
58
|
-
# db_name
|
59
|
-
# needle
|
60
|
-
# ref
|
61
|
-
# weight
|
63
|
+
# @param db_name The name of the data store being targeted. Required
|
64
|
+
# @param needle The string you wish to index. Must not contain tabs. Required
|
65
|
+
# @param ref The indentifying value of the record being indexed. Must be numeric. Required
|
66
|
+
# @param weight Weight of this particular reference. Default 0. Don't change unless you know what you're doing. Optional.
|
62
67
|
#
|
63
68
|
# Examples
|
64
69
|
#
|
65
|
-
#
|
66
|
-
#
|
70
|
+
# ```
|
71
|
+
# @client.put('location_en', 'London', 123, 0)
|
72
|
+
# # => OK
|
73
|
+
# ```
|
67
74
|
#
|
68
|
-
#
|
75
|
+
# @returns something to let you know that all is well.
|
69
76
|
def put(needle, ref, weight = 0)
|
70
77
|
check_valid_needle(needle)
|
71
78
|
check_valid_ref(ref)
|
@@ -126,4 +133,4 @@ module Blurrily
|
|
126
133
|
end
|
127
134
|
|
128
135
|
end
|
129
|
-
end
|
136
|
+
end
|
@@ -42,8 +42,7 @@ module Blurrily
|
|
42
42
|
raise ProtocolError, 'Limit must be a number' if limit && !LIMIT_RANGE.include?(limit.to_i)
|
43
43
|
|
44
44
|
results = @map_group.map(map_name).find(*[needle, limit && limit.to_i].compact)
|
45
|
-
|
46
|
-
return refs
|
45
|
+
return results.flatten
|
47
46
|
end
|
48
47
|
|
49
48
|
def on_CLEAR(map_name)
|
data/lib/blurrily/version.rb
CHANGED