Module: Scripsi
- Defined in:
- lib/scripsi.rb
Defined Under Namespace
Classes: SortedSuffixIndexer
Constant Summary collapse
- @@partition_size =
10
Class Method Summary collapse
-
.connect(options = {}) ⇒ Object
connect to a redis server.
- .find(id) ⇒ Object
-
.indexer(id) ⇒ Object
get the indexer with the given id.
- .partition_size ⇒ Object
- .redis ⇒ Object
-
.score(str) ⇒ Number
generate a ‘score’ for a string used for storing it in a sorted set.
Class Method Details
.connect(options = {}) ⇒ Object
connect to a redis server
6 7 8 |
# File 'lib/scripsi.rb', line 6 def self.connect( = {}) @@redis = Redis.new() end |
.find(id) ⇒ Object
52 53 54 |
# File 'lib/scripsi.rb', line 52 def self.find(id) indexer(id) end |
.indexer(id) ⇒ Object
get the indexer with the given id
44 45 46 47 48 49 |
# File 'lib/scripsi.rb', line 44 def self.indexer(id) type = Scripsi.redis.hget "scripsi:used", id.to_s if type == "ssi" SortedSuffixIndexer.build(id) end end |
.partition_size ⇒ Object
16 17 18 |
# File 'lib/scripsi.rb', line 16 def self.partition_size @@partition_size end |
.redis ⇒ Object
10 11 12 |
# File 'lib/scripsi.rb', line 10 def self.redis @@redis end |
.score(str) ⇒ Number
generate a ‘score’ for a string used for storing it in a sorted set
This method effectively turns a string into a base 27 floating point number, where 0 corresponds to no letter, 1 to A, 2 to B, etc.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/scripsi.rb', line 28 def self.score(str) str = str.downcase scrs = [] str.split('').each_slice(partition_size) do |s| mult = 1.0 scr = 0.0 s.each do |char| mult /= 27 scr += (char.ord-'a'.ord+1)*mult if ('a'..'z').include? char end scrs << scr end scrs end |