lunar 0.4.1 → 0.5.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.
Files changed (69) hide show
  1. data/.gitignore +2 -1
  2. data/LICENSE +1 -1
  3. data/README.markdown +116 -0
  4. data/Rakefile +6 -5
  5. data/VERSION +1 -1
  6. data/lib/lunar.rb +112 -24
  7. data/lib/lunar/connection.rb +51 -0
  8. data/lib/lunar/fuzzy_matches.rb +24 -0
  9. data/lib/lunar/fuzzy_word.rb +2 -2
  10. data/lib/lunar/index.rb +200 -94
  11. data/lib/lunar/keyword_matches.rb +32 -0
  12. data/lib/lunar/lunar_nest.rb +19 -0
  13. data/lib/lunar/range_matches.rb +28 -0
  14. data/lib/lunar/result_set.rb +85 -28
  15. data/lib/lunar/scoring.rb +4 -2
  16. data/lib/lunar/stopwords.rb +15 -0
  17. data/lib/lunar/words.rb +6 -3
  18. data/lunar.gemspec +31 -60
  19. data/test/helper.rb +4 -5
  20. data/test/test_fuzzy_indexing.rb +105 -0
  21. data/test/test_index.rb +150 -0
  22. data/test/test_lunar.rb +178 -1
  23. data/test/test_lunar_fuzzy_word.rb +4 -4
  24. data/test/test_lunar_nest.rb +46 -0
  25. data/test/{test_lunar_scoring.rb → test_scoring.rb} +5 -5
  26. metadata +72 -68
  27. data/.document +0 -5
  28. data/DATA +0 -41
  29. data/README.md +0 -80
  30. data/examples/ohm.rb +0 -40
  31. data/lib/lunar/search.rb +0 -68
  32. data/lib/lunar/sets.rb +0 -86
  33. data/test/test_lunar_fuzzy.rb +0 -118
  34. data/test/test_lunar_index.rb +0 -191
  35. data/test/test_lunar_search.rb +0 -261
  36. data/test/test_sets.rb +0 -48
  37. data/vendor/nest/nest.rb +0 -7
  38. data/vendor/redis/.gitignore +0 -9
  39. data/vendor/redis/LICENSE +0 -20
  40. data/vendor/redis/README.markdown +0 -120
  41. data/vendor/redis/Rakefile +0 -75
  42. data/vendor/redis/benchmarking/logging.rb +0 -62
  43. data/vendor/redis/benchmarking/pipeline.rb +0 -44
  44. data/vendor/redis/benchmarking/speed.rb +0 -21
  45. data/vendor/redis/benchmarking/suite.rb +0 -24
  46. data/vendor/redis/benchmarking/worker.rb +0 -71
  47. data/vendor/redis/bin/distredis +0 -33
  48. data/vendor/redis/examples/basic.rb +0 -15
  49. data/vendor/redis/examples/dist_redis.rb +0 -43
  50. data/vendor/redis/examples/incr-decr.rb +0 -17
  51. data/vendor/redis/examples/list.rb +0 -26
  52. data/vendor/redis/examples/pubsub.rb +0 -25
  53. data/vendor/redis/examples/sets.rb +0 -36
  54. data/vendor/redis/lib/edis.rb +0 -3
  55. data/vendor/redis/lib/redis.rb +0 -496
  56. data/vendor/redis/lib/redis/client.rb +0 -265
  57. data/vendor/redis/lib/redis/dist_redis.rb +0 -118
  58. data/vendor/redis/lib/redis/distributed.rb +0 -460
  59. data/vendor/redis/lib/redis/hash_ring.rb +0 -131
  60. data/vendor/redis/lib/redis/pipeline.rb +0 -13
  61. data/vendor/redis/lib/redis/raketasks.rb +0 -1
  62. data/vendor/redis/lib/redis/subscribe.rb +0 -79
  63. data/vendor/redis/profile.rb +0 -22
  64. data/vendor/redis/tasks/redis.tasks.rb +0 -140
  65. data/vendor/redis/test/db/.gitignore +0 -1
  66. data/vendor/redis/test/distributed_test.rb +0 -1131
  67. data/vendor/redis/test/redis_test.rb +0 -1134
  68. data/vendor/redis/test/test.conf +0 -8
  69. data/vendor/redis/test/test_helper.rb +0 -113
data/test/test_sets.rb DELETED
@@ -1,48 +0,0 @@
1
- require "helper"
2
-
3
- class LunarSetsTest < Test::Unit::TestCase
4
- setup do
5
- Lunar.redis(Redis.new(:host => "127.0.0.1", :port => "6380"))
6
- Lunar.redis.flushdb
7
-
8
- @keys = [
9
- "Lunar:Item:name:#{ Lunar.encode('iphone') }",
10
- "Lunar:Item:desc:#{ Lunar.encode('iphone') }",
11
- "Lunar:Item:tags:#{ Lunar.encode('asian') }",
12
- "Lunar:Item:tags:#{ Lunar.encode('hacker') }",
13
- "Lunar:Item:tags:#{ Lunar.encode('ninja') }",
14
- "Lunar:Item:body:#{ Lunar.encode('ninja') }",
15
- "Lunar:Item:body:#{ Lunar.encode('assassin') }"
16
- ]
17
-
18
- @keys.each { |key| Lunar.redis.zadd key, 1, 1001 }
19
- end
20
-
21
- context "given prefix Item, keywords iphone" do
22
- should "return both keys" do
23
- sets = Lunar::Sets.new("Item", "iphone")
24
-
25
- assert sets.include?(@keys[0])
26
- assert sets.include?(@keys[1])
27
- end
28
- end
29
-
30
- context "given prefix Item, keywords iphone, field name" do
31
- should "return only the name key" do
32
- sets = Lunar::Sets.new("Item", "iphone", "name")
33
-
34
- assert sets.include?(@keys[0])
35
- assert ! sets.include?(@keys[1])
36
- end
37
- end
38
-
39
- context "given asian ninja assassin" do
40
- should "return all relevant keys" do
41
- sets = Lunar::Sets.new("Item", "asian ninja assassin", "tags")
42
-
43
- assert sets.include?(@keys[2])
44
- assert sets.include?(@keys[4])
45
- end
46
- end
47
-
48
- end
data/vendor/nest/nest.rb DELETED
@@ -1,7 +0,0 @@
1
- class Nest < String
2
- VERSION = "0.0.2"
3
-
4
- def [](key)
5
- self.class.new("#{self}:#{key}")
6
- end
7
- end
@@ -1,9 +0,0 @@
1
- nohup.out
2
- redis/*
3
- rdsrv
4
- pkg/*
5
- coverage/*
6
- .idea
7
- *.gemspec
8
- *.rdb
9
- *.swp
data/vendor/redis/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 Ezra Zygmuntowicz
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,120 +0,0 @@
1
- # redis-rb
2
-
3
- A Ruby client library for the [Redis](http://code.google.com/p/redis) key-value store.
4
-
5
- ## A note about versions
6
-
7
- Versions *1.0.x* target all versions of Redis. You have to use this one if you are using Redis < 1.2.
8
-
9
- Version *2.0* is a big refactoring of the previous version and makes little effort to be
10
- backwards-compatible when it shouldn't. It does not support Redis' original protocol, favoring the
11
- new, binary-safe one. You should be using this version if you're running Redis 1.2+.
12
-
13
- ## Information about Redis
14
-
15
- Redis is a key-value store with some interesting features:
16
-
17
- 1. It's fast.
18
- 2. Keys are strings but values are typed. Currently Redis supports strings, lists, sets, sorted sets and hashes. [Atomic operations](http://code.google.com/p/redis/wiki/CommandReference) can be done on all of these types.
19
-
20
- See [the Redis homepage](http://code.google.com/p/redis/wiki/README) for more information.
21
-
22
- ## Getting started
23
-
24
- You can connect to Redis by instantiating the `Redis` class:
25
-
26
- require "redis"
27
-
28
- redis = Redis.new
29
-
30
- This assumes Redis was started with default values listening on `localhost`, port 6379. If you need to connect to a remote server or a different port, try:
31
-
32
- redis = Redis.new(:host => "10.0.1.1", :port => 6380)
33
-
34
- Once connected, you can start running commands against Redis:
35
-
36
- >> redis.set "foo", "bar"
37
- => "OK"
38
-
39
- >> redis.get "foo"
40
- => "bar"
41
-
42
- >> redis.sadd "users", "albert"
43
- => true
44
-
45
- >> redis.sadd "users", "bernard"
46
- => true
47
-
48
- >> redis.sadd "users", "charles"
49
- => true
50
-
51
- How many users?
52
-
53
- >> redis.scard "users"
54
- => 3
55
-
56
- Is `albert` a user?
57
-
58
- >> redis.sismember "users", "albert"
59
- => true
60
-
61
- Is `isabel` a user?
62
-
63
- >> redis.sismember "users", "isabel"
64
- => false
65
-
66
- Handle groups:
67
-
68
- >> redis.sadd "admins", "albert"
69
- => true
70
-
71
- >> redis.sadd "admins", "isabel"
72
- => true
73
-
74
- Users who are also admins:
75
-
76
- >> redis.sinter "users", "admins"
77
- => ["albert"]
78
-
79
- Users who are not admins:
80
-
81
- >> redis.sdiff "users", "admins"
82
- => ["bernard", "charles"]
83
-
84
- Admins who are not users:
85
-
86
- >> redis.sdiff "admins", "users"
87
- => ["isabel"]
88
-
89
- All users and admins:
90
-
91
- >> redis.sunion "admins", "users"
92
- => ["albert", "bernard", "charles", "isabel"]
93
-
94
-
95
- ## Storing objects
96
-
97
- Redis only stores strings as values. If you want to store an object inside a key, you can use a serialization/deseralization mechanism like JSON:
98
-
99
- >> redis.set "foo", [1, 2, 3].to_json
100
- => OK
101
-
102
- >> JSON.parse(redis.get("foo"))
103
- => [1, 2, 3]
104
-
105
- ## Executing multiple commands atomically
106
-
107
- You can use `MULTI/EXEC` to run arbitrary commands in an atomic fashion:
108
-
109
- redis.multi do
110
- redis.set "foo", "bar"
111
- redis.incr "baz"
112
- end
113
-
114
- ## More info
115
-
116
- Check the [Redis Command Reference](http://code.google.com/p/redis/wiki/CommandReference) or check the tests to find out how to use this client.
117
-
118
- ## Contributing
119
-
120
- [Fork the project](http://github.com/ezmobius/redis-rb) and send pull requests. You can also ask for help at `#redis` on Freenode.
@@ -1,75 +0,0 @@
1
- require 'rubygems'
2
- require 'rake/gempackagetask'
3
- require 'rake/testtask'
4
- require 'tasks/redis.tasks'
5
-
6
- $:.unshift File.join(File.dirname(__FILE__), 'lib')
7
- require 'redis'
8
-
9
- GEM = 'redis'
10
- GEM_NAME = 'redis'
11
- GEM_VERSION = Redis::VERSION
12
- AUTHORS = ['Ezra Zygmuntowicz', 'Taylor Weibley', 'Matthew Clark', 'Brian McKinney', 'Salvatore Sanfilippo', 'Luca Guidi']
13
- EMAIL = "ez@engineyard.com"
14
- HOMEPAGE = "http://github.com/ezmobius/redis-rb"
15
- SUMMARY = "Ruby client library for Redis, the key value storage server"
16
-
17
- spec = Gem::Specification.new do |s|
18
- s.name = GEM
19
- s.version = GEM_VERSION
20
- s.platform = Gem::Platform::RUBY
21
- s.has_rdoc = true
22
- s.extra_rdoc_files = ["LICENSE"]
23
- s.summary = SUMMARY
24
- s.description = s.summary
25
- s.authors = AUTHORS
26
- s.email = EMAIL
27
- s.homepage = HOMEPAGE
28
- s.require_path = 'lib'
29
- s.autorequire = GEM
30
- s.files = %w(LICENSE README.markdown Rakefile) + Dir.glob("{lib,tasks,spec}/**/*")
31
- end
32
-
33
- REDIS_DIR = File.expand_path(File.join("..", "test"), __FILE__)
34
- REDIS_CNF = File.join(REDIS_DIR, "test.conf")
35
- REDIS_PID = File.join(REDIS_DIR, "db", "redis.pid")
36
-
37
- task :default => :run
38
-
39
- desc "Run tests and manage server start/stop"
40
- task :run => [:start, :test, :stop]
41
-
42
- desc "Start the Redis server"
43
- task :start do
44
- unless File.exists?(REDIS_PID)
45
- system "redis-server #{REDIS_CNF}"
46
- end
47
- end
48
-
49
- desc "Stop the Redis server"
50
- task :stop do
51
- if File.exists?(REDIS_PID)
52
- system "kill #{File.read(REDIS_PID)}"
53
- system "rm #{REDIS_PID}"
54
- end
55
- end
56
-
57
- Rake::TestTask.new(:test) do |t|
58
- t.pattern = 'test/**/*_test.rb'
59
- end
60
-
61
- Rake::GemPackageTask.new(spec) do |pkg|
62
- pkg.gem_spec = spec
63
- end
64
-
65
- desc "install the gem locally"
66
- task :install => [:package] do
67
- sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
68
- end
69
-
70
- desc "create a gemspec file"
71
- task :gemspec do
72
- File.open("#{GEM}.gemspec", "w") do |file|
73
- file.puts spec.to_ruby
74
- end
75
- end
@@ -1,62 +0,0 @@
1
- # Run with
2
- #
3
- # $ ruby -Ilib benchmarking/logging.rb
4
- #
5
-
6
- begin
7
- require "bench"
8
- rescue LoadError
9
- $stderr.puts "`gem install bench` and try again."
10
- exit 1
11
- end
12
-
13
- require "redis"
14
- require "logger"
15
-
16
- def log(level, namespace = nil)
17
- logger = (namespace || Kernel).const_get(:Logger).new("/dev/null")
18
- logger.level = (namespace || Logger).const_get(level)
19
- logger
20
- end
21
-
22
- def stress(redis)
23
- redis.flushdb
24
-
25
- n = (ARGV.shift || 2000).to_i
26
-
27
- n.times do |i|
28
- key = "foo:#{i}"
29
- redis.set key, i
30
- redis.get key
31
- end
32
- end
33
-
34
- default = Redis.new
35
-
36
- logging_redises = [
37
- Redis.new(:logger => log(:DEBUG)),
38
- Redis.new(:logger => log(:INFO)),
39
- ]
40
-
41
- begin
42
- require "log4r"
43
-
44
- logging_redises += [
45
- Redis.new(:logger => log(:DEBUG, Log4r)),
46
- Redis.new(:logger => log(:INFO, Log4r)),
47
- ]
48
- rescue LoadError
49
- $stderr.puts "Log4r not installed. `gem install log4r` if you want to compare it against Ruby's Logger (spoiler: it's much faster)."
50
- end
51
-
52
- benchmark "Default options (no logger)" do
53
- stress(default)
54
- end
55
-
56
- logging_redises.each do |redis|
57
- benchmark "#{redis.client.logger.class} on #{Logger::SEV_LABEL[redis.client.logger.level]}" do
58
- stress(redis)
59
- end
60
- end
61
-
62
- run 10
@@ -1,44 +0,0 @@
1
- require 'benchmark'
2
- $:.push File.join(File.dirname(__FILE__), 'lib')
3
- require 'redis'
4
-
5
- times = 20000
6
-
7
- @r = Redis.new#(:debug => true)
8
- @r['foo'] = "The first line we sent to the server is some text"
9
-
10
- Benchmark.bmbm do |x|
11
- x.report("set") do
12
- 20000.times do |i|
13
- @r["set#{i}"] = "The first line we sent to the server is some text"; @r["foo#{i}"]
14
- end
15
- end
16
-
17
- x.report("set (pipelined)") do
18
- @r.pipelined do |pipeline|
19
- 20000.times do |i|
20
- pipeline["set_pipelined#{i}"] = "The first line we sent to the server is some text"; @r["foo#{i}"]
21
- end
22
- end
23
- end
24
-
25
- x.report("push+trim") do
26
- 20000.times do |i|
27
- @r.push_head "push_trim#{i}", i
28
- @r.list_trim "push_trim#{i}", 0, 30
29
- end
30
- end
31
-
32
- x.report("push+trim (pipelined)") do
33
- @r.pipelined do |pipeline|
34
- 20000.times do |i|
35
- pipeline.push_head "push_trim_pipelined#{i}", i
36
- pipeline.list_trim "push_trim_pipelined#{i}", 0, 30
37
- end
38
- end
39
- end
40
- end
41
-
42
- @r.keys('*').each do |k|
43
- @r.delete k
44
- end
@@ -1,21 +0,0 @@
1
- # Run with
2
- #
3
- # $ ruby -Ilib benchmarking/speed.rb
4
- #
5
-
6
- require "benchmark"
7
- require "redis"
8
-
9
- r = Redis.new
10
- n = (ARGV.shift || 20000).to_i
11
-
12
- elapsed = Benchmark.realtime do
13
- # n sets, n gets
14
- n.times do |i|
15
- key = "foo#{i}"
16
- r[key] = key * 10
17
- r[key]
18
- end
19
- end
20
-
21
- puts '%.2f Kops' % (2 * n / 1000 / elapsed)
@@ -1,24 +0,0 @@
1
- require 'fileutils'
2
-
3
- def run_in_background(command)
4
- fork { system command }
5
- end
6
-
7
- def with_all_segments(&block)
8
- 0.upto(9) do |segment_number|
9
- block_size = 100000
10
- start_index = segment_number * block_size
11
- end_index = start_index + block_size - 1
12
- block.call(start_index, end_index)
13
- end
14
- end
15
-
16
- #with_all_segments do |start_index, end_index|
17
- # puts "Initializing keys from #{start_index} to #{end_index}"
18
- # system "ruby worker.rb initialize #{start_index} #{end_index} 0"
19
- #end
20
-
21
- with_all_segments do |start_index, end_index|
22
- run_in_background "ruby worker.rb write #{start_index} #{end_index} 10"
23
- run_in_background "ruby worker.rb read #{start_index} #{end_index} 1"
24
- end