pms 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ class PMS
2
+
3
+ module Version
4
+
5
+ MAJOR = 0
6
+ MINOR = 0
7
+ TINY = 1
8
+
9
+ class << self
10
+
11
+ # Returns array representation.
12
+ def to_a
13
+ [MAJOR, MINOR, TINY]
14
+ end
15
+
16
+ # Short-cut for version string.
17
+ def to_s
18
+ to_a.join('.')
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+ VERSION = Version.to_s
26
+
27
+ end
@@ -0,0 +1,70 @@
1
+ require 'pms/ext'
2
+
3
+ shared_examples_for 'any Searchable' do
4
+
5
+ before :each do
6
+ @args ||= []
7
+ end
8
+
9
+ it 'should be searchable by a String' do
10
+ @searchable.search(*@args << 'fox').results.sort.should == [0, 3, 4, 6]
11
+ end
12
+
13
+ it 'should be searchable by a Regexp' do
14
+ @searchable.search(*@args << /[au]ck/).results.sort.should == [1, 2, 5]
15
+ end
16
+
17
+ it 'should allow boolean combination with AND' do
18
+ @searchable.search(*@args << 'fox').and('goose').results.sort.should == [3, 6]
19
+ end
20
+
21
+ it 'should allow boolean combination with OR' do
22
+ @searchable.search(*@args << 'fox').or('goose').results.sort.should == [0, 2, 3, 4, 6]
23
+ end
24
+
25
+ it 'should allow boolean combination with NOT' do
26
+ @searchable.search(*@args << 'fox').not('goose').results.sort.should == [0, 4]
27
+ end
28
+
29
+ end
30
+
31
+ describe String, ' when extended by pms' do
32
+
33
+ before :each do
34
+ @searchable = File.read(FOX)
35
+ end
36
+
37
+ it_should_behave_like 'any Searchable'
38
+
39
+ end
40
+
41
+ describe IO, ' when extended by pms' do
42
+
43
+ before :each do
44
+ @searchable = File.open(FOX)
45
+ end
46
+
47
+ it_should_behave_like 'any Searchable'
48
+
49
+ end
50
+
51
+ describe Array, ' when extended by pms' do
52
+
53
+ before :each do
54
+ @searchable = File.readlines(FOX)
55
+ end
56
+
57
+ it_should_behave_like 'any Searchable'
58
+
59
+ end
60
+
61
+ describe File, ' when extended by pms' do
62
+
63
+ before :each do
64
+ @searchable = File
65
+ @args = [FOX]
66
+ end
67
+
68
+ it_should_behave_like 'any Searchable'
69
+
70
+ end
@@ -0,0 +1,30 @@
1
+ describe PMS::Index do
2
+
3
+ before :each do
4
+ @index = PMS::Index.new(File.read(FOX))
5
+ end
6
+
7
+ it 'should raise an error for an invalid token in #results_with_positions' do
8
+ lambda {
9
+ @index.results_with_positions(123)
10
+ }.should raise_error(TypeError)
11
+ end
12
+
13
+ it 'should return the document for a given doc_num' do
14
+ @index.doc(3).should == File.readlines(FOX)[3]
15
+ end
16
+
17
+ end
18
+
19
+ describe PMS::Index, ' with exhaustable input' do
20
+
21
+ before :each do
22
+ # already seeks to EOF in #build_index
23
+ @index = PMS::Index.new(File.open(FOX))
24
+ end
25
+
26
+ it 'should return the documents anyway' do
27
+ @index.documents.size.should == 7
28
+ end
29
+
30
+ end
@@ -0,0 +1,13 @@
1
+ describe PMS::Proxy do
2
+
3
+ before :each do
4
+ @proxy = PMS::Proxy.new(PMS.new(File.read(FOX)))
5
+ end
6
+
7
+ it 'should raise an error for an invalid operator in #apply_operator' do
8
+ lambda {
9
+ @proxy.send(:apply_operator, 'foo', [])
10
+ }.should raise_error(ArgumentError)
11
+ end
12
+
13
+ end
data/spec/pms_spec.rb ADDED
@@ -0,0 +1,65 @@
1
+ describe PMS do
2
+
3
+ before :each do
4
+ @pms = PMS.new(File.read(FOX))
5
+ end
6
+
7
+ it 'should return the original documents' do
8
+ @pms.matches.should == File.readlines(FOX)
9
+ end
10
+
11
+ it 'should return the query matches (with token)' do
12
+ @pms.search('fox').and('goose').matches.sort.should == File.readlines(FOX).values_at(3, 6).sort
13
+ end
14
+
15
+ it 'should return the query matches (with sub-query)' do
16
+ @pms.search { |q| q.search('goose').or('night') }.matches.sort.should == File.readlines(FOX).values_at(0, 2, 3, 6).sort
17
+ end
18
+
19
+ it 'should support boolean operator AND' do
20
+ @pms.search('fox').and('goose').results.sort.should == [3, 6]
21
+ end
22
+
23
+ it 'should support boolean operator OR' do
24
+ @pms.search('fox').or('goose').results.sort.should == [0, 2, 3, 4, 6]
25
+ end
26
+
27
+ it 'should support boolean operator NOT' do
28
+ @pms.search('fox').not('goose').results.sort.should == [0, 4]
29
+ end
30
+
31
+ it 'should allow chaining of operators' do
32
+ @pms.search('fox').and('goose').not('knife').results.sort.should == [3]
33
+ end
34
+
35
+ it 'should allow grouping in sub-queries (for AND)' do
36
+ @pms.search('fox').and { |q| q.search('goose').or('night') }.results.sort.should == [0, 3, 6]
37
+ end
38
+
39
+ it 'should allow grouping in sub-queries (for OR)' do
40
+ @pms.search('fox').or { |q| q.search('geese').and('ran') }.results.sort.should == [0, 1, 3, 4, 6]
41
+ end
42
+
43
+ it 'should allow grouping in sub-queries (for NOT)' do
44
+ @pms.search('fox').not { |q| q.search('goose').or('night') }.results.sort.should == [4]
45
+ end
46
+
47
+ it 'should allow grouping in sub-queries (w/o token)' do
48
+ @pms.search { |q| q.search('goose').or('night') }.results.sort.should == [0, 2, 3, 6]
49
+ end
50
+
51
+ it 'should raise an error when block returns an invalid sub-query in #apply_operator_with_block' do
52
+ lambda {
53
+ @pms.search('fox').and { |q| q.class }
54
+ }.should raise_error(RuntimeError)
55
+ end
56
+
57
+ it 'should support proximity operator NEAR' do
58
+ @pms.search('fox').near('goose', 10).results.sort.should == [3, 6]
59
+ end
60
+
61
+ it 'should support proximity operator ADJACENT' do
62
+ @pms.search('fox').adjacent('goose', 10).results.sort.should == [6]
63
+ end
64
+
65
+ end
@@ -0,0 +1,8 @@
1
+ unless Object.const_defined?(:BASE)
2
+ BASE = File.join(File.dirname(__FILE__), '..')
3
+
4
+ $: << File.join(BASE, 'lib')
5
+ require 'pms'
6
+
7
+ FOX = File.join(BASE, 'test_data', 'fox.txt')
8
+ end
data/test_data/fox.txt ADDED
@@ -0,0 +1,7 @@
1
+ The fox went out on a chilly night / Prayed for the moon to give him light / For he had many a mile to go that night / Before he reached the town o
2
+ He ran til he came to a great big bin / Where the ducks and the geese were kept therein / Said, a couple of you are going to grease my chin / Before I leave this town o
3
+ He grabbed the grey goose by the neck / Throwed a duck across his back / He didn't mind the quack, quack, quack / And the legs all dangling down o
4
+ Then old mother Flipper-flopper jumped out of bed / Out of the window she cocked her head / Crying, John, John the grey goose is gone / and the fox is on the town o
5
+ Then John he went to the top of the hill / Blew his horn both loud and shrill / The fox, he said, I better flee with my kill / Or they'll soon be on my trail o
6
+ He ran till he came to his cozy den / There were the little ones, eight, nine, ten / Saying, Daddy, daddy, Better go back again / For it must be a mighty fine town o
7
+ Then the fox and his wife, without any strife / Cut up the goose with a carving knife / They never had such a supper in their life / And the little ones chewed on the bones o
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jens Wille
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-08 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Poor Man's Search
17
+ email: jens.wille@uni-koeln.de
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - COPYING
24
+ - ChangeLog
25
+ - README
26
+ files:
27
+ - lib/pms.rb
28
+ - lib/pms/proxy.rb
29
+ - lib/pms/ext.rb
30
+ - lib/pms/version.rb
31
+ - lib/pms/index.rb
32
+ - Rakefile
33
+ - COPYING
34
+ - ChangeLog
35
+ - README
36
+ - spec/spec_helper.rb
37
+ - spec/pms/proxy_spec.rb
38
+ - spec/pms/index_spec.rb
39
+ - spec/pms/ext_spec.rb
40
+ - spec/pms_spec.rb
41
+ - test_data/fox.txt
42
+ has_rdoc: true
43
+ homepage: http://pms.rubyforge.org/
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --line-numbers
47
+ - --inline-source
48
+ - --title
49
+ - pms Application documentation
50
+ - --main
51
+ - README
52
+ - --charset
53
+ - UTF-8
54
+ - --all
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project: pms
72
+ rubygems_version: 1.3.1
73
+ signing_key:
74
+ specification_version: 2
75
+ summary: Poor Man's Search
76
+ test_files: []
77
+