seasy 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/seasy.rb +2 -2
- data/lib/{fragmentizer.rb → seasy/fragmentizer.rb} +0 -0
- data/lib/{index.rb → seasy/index.rb} +34 -12
- data/seasy.gemspec +62 -0
- data/spec/fragmentizer_spec.rb +1 -1
- data/spec/index_spec.rb +43 -14
- metadata +7 -8
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/lib/seasy.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require 'fragmentizer'
|
2
|
-
require 'index'
|
1
|
+
require 'seasy/fragmentizer'
|
2
|
+
require 'seasy/index'
|
File without changes
|
@@ -38,19 +38,11 @@ module Seasy
|
|
38
38
|
@@indices[stringed_name]
|
39
39
|
end
|
40
40
|
|
41
|
-
def add searchee, target
|
42
|
-
|
41
|
+
def add searchee, target, options = {}
|
42
|
+
options[:source] = target if options[:source].nil?
|
43
|
+
save target, fragmentize( searchee ), options
|
43
44
|
end
|
44
45
|
|
45
|
-
def fragmentize searchee
|
46
|
-
f = Fragmentizer.new
|
47
|
-
f.fragmentize searchee
|
48
|
-
end
|
49
|
-
|
50
|
-
def save target, weights
|
51
|
-
@storage.save target, weights
|
52
|
-
end
|
53
|
-
|
54
46
|
def search query
|
55
47
|
@storage.search query
|
56
48
|
end
|
@@ -58,6 +50,22 @@ module Seasy
|
|
58
50
|
def clear
|
59
51
|
@storage.clear
|
60
52
|
end
|
53
|
+
|
54
|
+
def remove target
|
55
|
+
@storage.remove target
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def fragmentize searchee
|
61
|
+
f = Fragmentizer.new
|
62
|
+
f.fragmentize searchee
|
63
|
+
end
|
64
|
+
|
65
|
+
def save target, weights, options
|
66
|
+
@storage.save target, weights, options
|
67
|
+
end
|
68
|
+
|
61
69
|
end
|
62
70
|
|
63
71
|
# a store got search queries as keys and an array of
|
@@ -65,12 +73,17 @@ module Seasy
|
|
65
73
|
class InMemoryStorage
|
66
74
|
def initialize
|
67
75
|
@store = {}
|
76
|
+
@sources = {}
|
68
77
|
end
|
69
78
|
|
70
79
|
# target is a simple value - we care not what
|
71
80
|
# weights are all fragments (indices) and their weight
|
72
81
|
# eg. { "aba" => 1, "ab" => 1, "ba" => 1, "b" => 1, "a" => 2 } for the string "aba"
|
73
|
-
def save target, weights
|
82
|
+
def save target, weights, options = {}
|
83
|
+
raise ":source need to be set" if options[:source].nil?
|
84
|
+
source = options[:source]
|
85
|
+
@sources[source] ||= []
|
86
|
+
@sources[source] << target
|
74
87
|
weights.keys.each do |key|
|
75
88
|
add weights[key], key, target
|
76
89
|
end
|
@@ -93,6 +106,15 @@ module Seasy
|
|
93
106
|
|
94
107
|
def clear
|
95
108
|
@store = {}
|
109
|
+
@sources = {}
|
110
|
+
end
|
111
|
+
|
112
|
+
def remove source
|
113
|
+
targets = @sources[source]
|
114
|
+
puts "deleting #{source}"
|
115
|
+
@store.delete_if {|key,value| !value[targets.first].nil?}
|
116
|
+
puts "#{@store}"
|
117
|
+
puts "#{@sources}"
|
96
118
|
end
|
97
119
|
|
98
120
|
end
|
data/seasy.gemspec
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "seasy"
|
8
|
+
s.version = "0.0.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Fredrik Rubensson"]
|
12
|
+
s.date = "2011-09-28"
|
13
|
+
s.description = "An easy to use search index (requiring no external servers) with a pluggable design for index storage."
|
14
|
+
s.email = "fredrik@eldfluga.se"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rvmrc",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/seasy.rb",
|
29
|
+
"lib/seasy/fragmentizer.rb",
|
30
|
+
"lib/seasy/index.rb",
|
31
|
+
"seasy.gemspec",
|
32
|
+
"spec/fragmentizer_spec.rb",
|
33
|
+
"spec/index_spec.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/froderik/seasy"
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = "1.8.10"
|
39
|
+
s.summary = "server less search"
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_development_dependency(%q<rspec>, [">= 2.5.0"])
|
46
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
47
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
48
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<rspec>, [">= 2.5.0"])
|
51
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
53
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rspec>, [">= 2.5.0"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
59
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/spec/fragmentizer_spec.rb
CHANGED
data/spec/index_spec.rb
CHANGED
@@ -1,33 +1,38 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
|
4
|
-
require '
|
5
|
-
require 'index'
|
4
|
+
require 'seasy'
|
6
5
|
|
7
6
|
include Seasy
|
8
7
|
|
9
8
|
describe Index do
|
10
9
|
before :each do
|
11
10
|
subject.clear
|
11
|
+
configure do |config|
|
12
|
+
config.storage = InMemoryStorage
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
16
|
it "should default and have some basic behaviour" do
|
15
17
|
i = subject
|
16
|
-
|
17
|
-
|
18
|
-
i.add '
|
19
|
-
i.search( "red").should == {
|
20
|
-
i.
|
18
|
+
target_one = "1"
|
19
|
+
target_two = "2"
|
20
|
+
i.add 'fredrik den store', target_one
|
21
|
+
i.search( "red" ).should == {target_one => 1}
|
22
|
+
i.add 'red red wine', target_two
|
23
|
+
i.search( "red").should == {target_two => 2 ,target_one => 1}
|
24
|
+
i.search( "e" ).should == {target_one => 3, target_two => 3}
|
21
25
|
end
|
22
26
|
|
23
27
|
it "should be possible to add complex strings twice" do
|
24
28
|
i = subject
|
25
|
-
|
26
|
-
i.
|
27
|
-
i.
|
28
|
-
i.
|
29
|
-
i.search( '
|
30
|
-
i.search( '
|
29
|
+
target = 1
|
30
|
+
i.add 'fluff', target
|
31
|
+
i.search( 'f' ).should == {target => 3}
|
32
|
+
i.add 'fluffluff', target
|
33
|
+
i.search( 'fluff' ).should == {target => 3}
|
34
|
+
i.search( 'lu' ).should == {target => 3}
|
35
|
+
i.search( 'f' ).should == {target => 8}
|
31
36
|
end
|
32
37
|
|
33
38
|
it "should have named indices" do
|
@@ -47,6 +52,29 @@ describe Index do
|
|
47
52
|
another_index.search( 'ean' ).should == { }
|
48
53
|
end
|
49
54
|
|
55
|
+
it "should handle source also" do
|
56
|
+
i = subject
|
57
|
+
i.add 'landsnora', 'edsberg'
|
58
|
+
i.add 'landsnora', 'edsberg', :source => 'sollentuna'
|
59
|
+
i.search( 'landsnora' ).should == {'edsberg' => 2}
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should remove targets" do
|
63
|
+
i = subject
|
64
|
+
i.add 'searchentry', 'gooo', :source => 'gooo'
|
65
|
+
i.search( 'entry' ).should == {'gooo' => 1}
|
66
|
+
i.remove 'gooo'
|
67
|
+
i.search( 'entry' ).should == {}
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should remove sources" do
|
71
|
+
i = subject
|
72
|
+
i.add 'searchentry', 'target', :source => 'hoola'
|
73
|
+
i.search( 'entry' ).should == {'target' => 1}
|
74
|
+
i.remove 'hoola'
|
75
|
+
i.search( 'entry' ).should == {}
|
76
|
+
end
|
77
|
+
|
50
78
|
it "should have a configurable storage" do
|
51
79
|
configure do |config|
|
52
80
|
config.storage = DummyStorage
|
@@ -58,6 +86,7 @@ describe Index do
|
|
58
86
|
DummyStorage.should be_saved_once
|
59
87
|
DummyStorage.should be_searched_once
|
60
88
|
end
|
89
|
+
|
61
90
|
end
|
62
91
|
|
63
92
|
class DummyStorage
|
@@ -66,7 +95,7 @@ class DummyStorage
|
|
66
95
|
@@searched_count = 0
|
67
96
|
end
|
68
97
|
|
69
|
-
def save target, weights
|
98
|
+
def save target, weights, options = {}
|
70
99
|
@@saved_count += 1
|
71
100
|
end
|
72
101
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: seasy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Fredrik Rubensson
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-09-
|
14
|
-
default_executable:
|
13
|
+
date: 2011-09-28 00:00:00 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: rspec
|
@@ -75,12 +74,12 @@ files:
|
|
75
74
|
- README.rdoc
|
76
75
|
- Rakefile
|
77
76
|
- VERSION
|
78
|
-
- lib/fragmentizer.rb
|
79
|
-
- lib/index.rb
|
80
77
|
- lib/seasy.rb
|
78
|
+
- lib/seasy/fragmentizer.rb
|
79
|
+
- lib/seasy/index.rb
|
80
|
+
- seasy.gemspec
|
81
81
|
- spec/fragmentizer_spec.rb
|
82
82
|
- spec/index_spec.rb
|
83
|
-
has_rdoc: true
|
84
83
|
homepage: http://github.com/froderik/seasy
|
85
84
|
licenses:
|
86
85
|
- MIT
|
@@ -94,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
93
|
requirements:
|
95
94
|
- - ">="
|
96
95
|
- !ruby/object:Gem::Version
|
97
|
-
hash:
|
96
|
+
hash: 2921882298232585062
|
98
97
|
segments:
|
99
98
|
- 0
|
100
99
|
version: "0"
|
@@ -107,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
106
|
requirements: []
|
108
107
|
|
109
108
|
rubyforge_project:
|
110
|
-
rubygems_version: 1.
|
109
|
+
rubygems_version: 1.8.10
|
111
110
|
signing_key:
|
112
111
|
specification_version: 3
|
113
112
|
summary: server less search
|