rifle 0.0.6 → 0.0.7
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.
- data/README.md +73 -1
- data/lib/rifle.rb +1 -0
- data/lib/rifle/rifle_client.rb +18 -0
- data/lib/rifle/rifle_resque.rb +5 -1
- data/lib/rifle/settings.rb +2 -6
- data/lib/rifle/version.rb +1 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -1 +1,73 @@
|
|
1
|
-
# Rifle
|
1
|
+
# Rifle
|
2
|
+
|
3
|
+
Rifle is a search engine backed by [Redis](www.redis.io). It is designed to be very simple and very fast.
|
4
|
+
Unlike other similar projects, it can operate not only in a simple single application mode, but also in a
|
5
|
+
distributed architecture without one single monolithic Rails application or redis instance.
|
6
|
+
|
7
|
+
# Installation
|
8
|
+
|
9
|
+
Just use the gem.
|
10
|
+
|
11
|
+
gem 'rifle'
|
12
|
+
|
13
|
+
Now, all of your Rails based servers can write to and query the search engine using the following commands
|
14
|
+
|
15
|
+
Rifle::Client.store('urn:monty:sketch:MP3242', {
|
16
|
+
quote: 'I would like to buy a cat license'
|
17
|
+
}
|
18
|
+
|
19
|
+
Rifle::Client.search('Cat')
|
20
|
+
|
21
|
+
# => {
|
22
|
+
# urn: 'urn:monty:sketch:MP3242',
|
23
|
+
# payload: {
|
24
|
+
# quote: 'I would like to buy a cat license'
|
25
|
+
# }
|
26
|
+
# }
|
27
|
+
|
28
|
+
# Payloads
|
29
|
+
|
30
|
+
Payloads are expected to be hashes, identified by a company-wide unique id (a urn). These are indexed and can
|
31
|
+
be searched by metaphone. That is, the search term need not be exact.
|
32
|
+
|
33
|
+
E.g, given the following payload
|
34
|
+
|
35
|
+
Is this the right room for an argument?
|
36
|
+
|
37
|
+
Any of the following search terms will match
|
38
|
+
|
39
|
+
Right
|
40
|
+
rite
|
41
|
+
RYTE
|
42
|
+
Argument
|
43
|
+
arguments
|
44
|
+
|
45
|
+
# Client configuration
|
46
|
+
|
47
|
+
You can supply a rifle_config.rb initializer with the following options. Defaults given in comments.
|
48
|
+
|
49
|
+
Rifle.settings.ignored_words # = ["the", "and", "you", "that"]
|
50
|
+
Rifle.settings.min_word_length # = 3
|
51
|
+
Rifle.settings.resque_queue # = :rifle
|
52
|
+
Rifle.settings.redis # = Redis.current (used both by the client in "inline mode" and the server in "standalone mode")
|
53
|
+
Rifle.settings.use_rest_server # = nil
|
54
|
+
|
55
|
+
# Server deployment modes
|
56
|
+
|
57
|
+
Rifle searches happen inline in the current application, or can sent to an instance of Rifle running as a standalone server.
|
58
|
+
|
59
|
+
## Inline mode
|
60
|
+
|
61
|
+
No config necessary.
|
62
|
+
|
63
|
+
## Standalone Server Mode
|
64
|
+
|
65
|
+
Rifle can start on its own as a Rails application. To start the server, run
|
66
|
+
|
67
|
+
rails -s
|
68
|
+
|
69
|
+
To use the standalone server, the clients must have the following in their initializer
|
70
|
+
|
71
|
+
Rifle.settings.use_rest_server = 'http://<standalone.ip>:3000'
|
72
|
+
|
73
|
+
|
data/lib/rifle.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Rifle
|
2
|
+
module Client
|
3
|
+
def self.store(urn, json)
|
4
|
+
Resque.enqueue(RifleResque, urn, json)
|
5
|
+
end
|
6
|
+
def self.search(query)
|
7
|
+
if Rifle.settings.use_rest_server
|
8
|
+
results = RestClient.get("#{Rifle.settings.use_rest_server}/search", {params: {q: query}})
|
9
|
+
if (results.is_a? String)
|
10
|
+
results = JSON.parse(results)
|
11
|
+
end
|
12
|
+
results
|
13
|
+
else
|
14
|
+
Rifle.search(query)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/rifle/rifle_resque.rb
CHANGED
@@ -16,7 +16,11 @@ class RifleResque
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def store
|
19
|
-
|
19
|
+
if Rifle.settings.use_rest_server
|
20
|
+
RestClient.post("#{Rifle.settings.use_rest_server}/store/#{@urn}", @payload, :content_type => :json, :accept => :json)
|
21
|
+
else
|
22
|
+
Rifle.store(@urn, JSON.parse(@payload))
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
def self.perform(urn, payload)
|
data/lib/rifle/settings.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Rifle
|
2
2
|
|
3
3
|
class Settings
|
4
|
-
attr_accessor :ignored_words, :min_word_length, :redis, :
|
4
|
+
attr_accessor :ignored_words, :min_word_length, :redis, :use_rest_server, :resque_queue
|
5
5
|
|
6
6
|
def ignored_words
|
7
7
|
@ignored_words ||= ["the", "and", "you", "that"]
|
@@ -11,16 +11,12 @@ module Rifle
|
|
11
11
|
@min_word_length ||= 3
|
12
12
|
end
|
13
13
|
|
14
|
-
def server
|
15
|
-
@server ||= 'http://localhost:3000'
|
16
|
-
end
|
17
|
-
|
18
14
|
def resque_queue
|
19
15
|
@resque_queue ||= :rifle
|
20
16
|
end
|
21
17
|
|
22
18
|
def redis
|
23
|
-
@redis ||= Redis.
|
19
|
+
@redis ||= Redis.current
|
24
20
|
end
|
25
21
|
end
|
26
22
|
|
data/lib/rifle/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rifle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -148,6 +148,7 @@ extra_rdoc_files: []
|
|
148
148
|
files:
|
149
149
|
- app/controllers/application_controller.rb
|
150
150
|
- app/controllers/searches_controller.rb
|
151
|
+
- lib/rifle/rifle_client.rb
|
151
152
|
- lib/rifle/engine.rb
|
152
153
|
- lib/rifle/settings.rb
|
153
154
|
- lib/rifle/version.rb
|