solr_mapper 0.1.3

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.
@@ -0,0 +1,87 @@
1
+ # Copyright 2010 The Skunkworx.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require File.dirname(__FILE__) + '/base'
16
+ require 'rest_client'
17
+
18
+ describe SolrMapper::SolrDocument do
19
+ before(:all) do
20
+ url = Thing::base_url
21
+ resource = RestClient::Resource.new("#{url}/update")
22
+ resource.post("<delete><query>id:[* TO *]</query></delete>", {:content_type => 'text/xml'})
23
+ resource.post("<commit/>", {:content_type => 'text/xml'})
24
+
25
+ thing = Thing.new({:_id => '04787560-bc23-012d-817c-60334b2add60', :content => 'sample content 1', :name => 'sample item 1'})
26
+ thing.save
27
+ thing = Thing.new({:_id => '04787560-bc23-012d-817c-60334b2add61', :content => 'sample content 2', :name => 'sample item 2'})
28
+ thing.save
29
+ end
30
+
31
+ it "should return results" do
32
+ Thing.query("*:*").count.should > 0
33
+ end
34
+
35
+ it "should have identical query and search methods until search is removed" do
36
+ Thing.query("*:*").count.should == Thing.search("*:*").count
37
+ Thing.query("name:content").count.should == Thing.search("name:content").count
38
+ end
39
+
40
+ it "should save new and recall" do
41
+ id = UUID.new().generate()
42
+
43
+ thing = Thing.new
44
+ thing._id = id
45
+ thing.content = 'sample content'
46
+
47
+ thing.save()
48
+
49
+ saved_thing = Thing.find(id)
50
+ saved_thing.content.should == thing.content
51
+ end
52
+
53
+ it "should be able to change data" do
54
+ id = '04787560-bc23-012d-817c-60334b2add60'
55
+
56
+ thing = Thing.find(id)
57
+ thing.content << ' additional content'
58
+ thing.save()
59
+
60
+ saved_thing = Thing.find(id)
61
+ saved_thing.content.should == thing.content
62
+ end
63
+
64
+ it "should be able to delete" do
65
+ id = '04787560-bc23-012d-817c-60334b2add61'
66
+
67
+ thing = Thing.find(id)
68
+ thing.destroy
69
+
70
+ deleted_thing = Thing.find(id)
71
+ deleted_thing.should be(nil)
72
+ end
73
+
74
+ it "should be able to update a subset of attributes" do
75
+ id = '04787560-bc23-012d-817c-60334b2add60'
76
+ new_content = 'changed content'
77
+
78
+ thing = Thing.find(id)
79
+ name = thing.name
80
+ thing.update_attributes({:content => new_content})
81
+
82
+ saved_thing = Thing.find(id)
83
+ saved_thing.content.should == new_content # make sure the content HAS changed
84
+ saved_thing.name.should == name # make sure the name HASN'T changed
85
+ end
86
+ end
87
+
@@ -0,0 +1,193 @@
1
+ # Copyright 2010 The Skunkworx.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require File.dirname(__FILE__) + '/base'
16
+ require 'rest_client'
17
+
18
+ describe SolrMapper::SolrDocument do
19
+ before(:all) do
20
+ url = Thing::base_url
21
+ resource = RestClient::Resource.new("#{url}/update")
22
+ resource.post("<delete><query>id:[* TO *]</query></delete>", {:content_type => 'text/xml'})
23
+ resource.post("<commit/>", {:content_type => 'text/xml'})
24
+
25
+ url = Stuff::base_url
26
+ resource = RestClient::Resource.new("#{url}/update")
27
+ resource.post("<delete><query>id:[* TO *]</query></delete>", {:content_type => 'text/xml'})
28
+ resource.post("<commit/>", {:content_type => 'text/xml'})
29
+
30
+
31
+ url = Widget::base_url
32
+ resource = RestClient::Resource.new("#{url}/update")
33
+ resource.post("<delete><query>id:[* TO *]</query></delete>", {:content_type => 'text/xml'})
34
+ resource.post("<commit/>", {:content_type => 'text/xml'})
35
+
36
+
37
+ stuff = Stuff.new({:_id => '04787560-bc23-012d-817c-60334b2add63', :name => 'stuff 1'})
38
+ stuff.save
39
+
40
+ stuff = Stuff.new({:_id => '04787560-bc23-012d-817c-60334b2add64', :name => 'stuff 2'})
41
+ stuff.save
42
+
43
+ stuff = Stuff.new({:_id => '04787560-bc23-012d-817c-60334b2add65', :name => 'stuff 3'})
44
+ stuff.save
45
+
46
+ widget = Widget.new({:_id => '04787560-bc23-012d-817c-60334b2add66', :name => 'widget 1'})
47
+ widget.save
48
+
49
+ thing = Thing.new({:_id => '04787560-bc23-012d-817c-60334b2add60', :content => 'sample content 1',
50
+ :stuff_id => ['04787560-bc23-012d-817c-60334b2add63', '04787560-bc23-012d-817c-60334b2add64'],
51
+ :widget_id => '04787560-bc23-012d-817c-60334b2add66'})
52
+ thing.save
53
+
54
+ thing = Thing.new({:_id => '04787560-bc23-012d-817c-60334b2add61', :content => 'sample content 2',
55
+ :stuff_id => ['04787560-bc23-012d-817c-60334b2add65']})
56
+ thing.save
57
+
58
+
59
+ end
60
+
61
+ it "should recall has_many relations" do
62
+ thing = Thing.find('04787560-bc23-012d-817c-60334b2add60')
63
+
64
+ thing.stuffs.count.should == 2
65
+ thing.stuffs[0].name.should == 'stuff 1'
66
+ thing.stuffs[1].name.should == 'stuff 2'
67
+
68
+ thing = Thing.find('04787560-bc23-012d-817c-60334b2add61')
69
+
70
+ thing.stuffs.count.should == 1
71
+ thing.stuffs[0].name.should == 'stuff 3'
72
+ end
73
+
74
+ it "should recall has_one relations" do
75
+ thing = Thing.find('04787560-bc23-012d-817c-60334b2add60')
76
+ thing.widget.should_not be(nil)
77
+ thing.widget.name.should == 'widget 1'
78
+ end
79
+
80
+ it "should store has_many relations by object by direct assignment" do
81
+ thing = Thing.find('04787560-bc23-012d-817c-60334b2add60')
82
+
83
+ stuff1 = Stuff.new({:_id => '04787560-bc23-012d-817c-60334b2add80', :name => 'brand new stuff 1'})
84
+ stuff1.save
85
+
86
+ stuff2 = Stuff.new({:_id => '04787560-bc23-012d-817c-60334b2add81', :name => 'brand new stuff 2'})
87
+ stuff2.save
88
+
89
+ thing.stuffs = [stuff1, stuff2]
90
+
91
+ thing.save()
92
+ thing = Thing.find('04787560-bc23-012d-817c-60334b2add60')
93
+
94
+ thing.stuffs.count.should == 2
95
+ thing.stuffs[0]._id.should == '04787560-bc23-012d-817c-60334b2add80'
96
+ thing.stuffs[1]._id.should == '04787560-bc23-012d-817c-60334b2add81'
97
+ end
98
+
99
+ it "should be able to mix update methods" do
100
+ thing = Thing.find('04787560-bc23-012d-817c-60334b2add60')
101
+
102
+ stuff1 = Stuff.new({:_id => '04787560-bc23-012d-817c-60334b2add80', :name => 'brand new stuff 1'})
103
+ stuff1.save
104
+
105
+ stuff2 = Stuff.new({:_id => '04787560-bc23-012d-817c-60334b2add81', :name => 'brand new stuff 2'})
106
+ stuff2.save
107
+
108
+ thing.stuffs = [stuff1]
109
+
110
+ thing.save()
111
+
112
+ thing.stuffs << stuff2
113
+
114
+ thing = Thing.find('04787560-bc23-012d-817c-60334b2add60')
115
+
116
+ thing.stuffs.count.should == 2
117
+ thing.stuffs[0]._id.should == '04787560-bc23-012d-817c-60334b2add80'
118
+ thing.stuffs[1]._id.should == '04787560-bc23-012d-817c-60334b2add81'
119
+ end
120
+
121
+
122
+ it "should store has_many relations by object by left shift" do
123
+ thing = Thing.find('04787560-bc23-012d-817c-60334b2add61')
124
+
125
+ stuff = Stuff.new({:_id => '04787560-bc23-012d-817c-60334b2add81', :name => 'brand new stuff'})
126
+
127
+ thing.stuffs << stuff
128
+
129
+ thing = Thing.find('04787560-bc23-012d-817c-60334b2add61')
130
+ thing.stuffs.count.should == 2
131
+ end
132
+
133
+ it "should be able to delete from a relation" do
134
+ thing = Thing.find('04787560-bc23-012d-817c-60334b2add61')
135
+
136
+ ct = thing.stuffs.count
137
+
138
+ thing.stuffs.delete(thing.stuffs[0])
139
+ thing.save()
140
+
141
+ thing = Thing.find('04787560-bc23-012d-817c-60334b2add61')
142
+ thing.stuffs.count.should == ct - 1
143
+ end
144
+
145
+ it "shouldn't destroy a child when deleting it" do
146
+ thing = Thing.find('04787560-bc23-012d-817c-60334b2add61')
147
+ stuff = Stuff.new({:_id => '04787560-bc23-012d-817c-60334b2add80', :name => 'brand new stuff 1'})
148
+ thing.stuffs << stuff
149
+
150
+ stuff_id = stuff._id
151
+
152
+ thing.stuffs.delete(stuff)
153
+ thing.save()
154
+
155
+ stuff = Stuff.find(stuff_id)
156
+ stuff.should_not be(nil)
157
+ end
158
+
159
+ it "should be able to destroy a relation" do
160
+ thing = Thing.find('04787560-bc23-012d-817c-60334b2add61')
161
+
162
+ stuff = Stuff.new({:_id => '04787560-bc23-012d-817c-60334b2add80', :name => 'brand new stuff 1'})
163
+ stuff.save
164
+
165
+ thing.stuffs << stuff
166
+
167
+ stuff_id = stuff._id
168
+
169
+ thing.stuffs.destroy(stuff)
170
+ thing.save()
171
+
172
+ stuff = Stuff.find(stuff_id)
173
+ stuff.should be(nil)
174
+ end
175
+
176
+ it "should support a navigation member for belongs_to" do
177
+ thing = Thing.new(:_id => '04787560-bc23-012d-817c-60334b2add90')
178
+ stuff = Stuff.new(:_id => '04787560-bc23-012d-817c-60334b2add95', :name => 'brand new stuff 1')
179
+ thing.stuffs << stuff
180
+
181
+ stuff.thing._id.should == thing._id
182
+ end
183
+
184
+ it "should support assignment via belongs_to" do
185
+ thing = Thing.new(:_id => '04787560-bc23-012d-817c-60334b2add91')
186
+ stuff = Stuff.new(:_id => '04787560-bc23-012d-817c-60334b2add96', :name => 'brand new stuff 1')
187
+
188
+ stuff.thing = thing
189
+ stuff.save()
190
+
191
+ Stuff.find('04787560-bc23-012d-817c-60334b2add96').thing._id.should == thing._id
192
+ end
193
+ end
@@ -0,0 +1,58 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <!--
3
+ Copyright 2010 The Skunkworx.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ -->
17
+
18
+ <schema name="items" version="1.2">
19
+ <types>
20
+ <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
21
+ <fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
22
+ <fieldType name="text" class="solr.TextField" positionIncrementGap="100">
23
+ <analyzer type="index">
24
+ <tokenizer class="solr.WhitespaceTokenizerFactory"/>
25
+ <filter class="solr.StopFilterFactory"
26
+ ignoreCase="true"
27
+ words="stopwords.txt"
28
+ enablePositionIncrements="true"
29
+ />
30
+ <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
31
+ <filter class="solr.LowerCaseFilterFactory"/>
32
+ <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt"/>
33
+ </analyzer>
34
+ <analyzer type="query">
35
+ <tokenizer class="solr.WhitespaceTokenizerFactory"/>
36
+ <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
37
+ <filter class="solr.StopFilterFactory"
38
+ ignoreCase="true"
39
+ words="stopwords.txt"
40
+ enablePositionIncrements="true"
41
+ />
42
+ <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
43
+ <filter class="solr.LowerCaseFilterFactory"/>
44
+ <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt"/>
45
+ </analyzer>
46
+ </fieldType>
47
+ </types>
48
+
49
+ <fields>
50
+ <field name="id" type="string" indexed="true" stored="true" required="true" />
51
+ <field name="name" type="string" indexed="true" stored="true"/>
52
+ </fields>
53
+
54
+ <uniqueKey>id</uniqueKey>
55
+ <defaultSearchField>name</defaultSearchField>
56
+ <solrQueryParser defaultOperator="OR"/>
57
+ </schema>
58
+
@@ -0,0 +1,64 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <!--
3
+ Copyright 2010 The Skunkworx.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ -->
17
+
18
+ <schema name="items" version="1.2">
19
+ <types>
20
+ <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
21
+ <fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
22
+ <fieldType name="text" class="solr.TextField" positionIncrementGap="100">
23
+ <analyzer type="index">
24
+ <tokenizer class="solr.WhitespaceTokenizerFactory"/>
25
+ <filter class="solr.StopFilterFactory"
26
+ ignoreCase="true"
27
+ words="stopwords.txt"
28
+ enablePositionIncrements="true"
29
+ />
30
+ <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
31
+ <filter class="solr.LowerCaseFilterFactory"/>
32
+ <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt"/>
33
+ </analyzer>
34
+ <analyzer type="query">
35
+ <tokenizer class="solr.WhitespaceTokenizerFactory"/>
36
+ <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
37
+ <filter class="solr.StopFilterFactory"
38
+ ignoreCase="true"
39
+ words="stopwords.txt"
40
+ enablePositionIncrements="true"
41
+ />
42
+ <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
43
+ <filter class="solr.LowerCaseFilterFactory"/>
44
+ <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt"/>
45
+ </analyzer>
46
+ </fieldType>
47
+ </types>
48
+
49
+ <fields>
50
+ <field name="id" type="string" indexed="true" stored="true" required="true" />
51
+ <field name="name" type="string" indexed="true" stored="true"/>
52
+ <field name="widget_id" type="string" indexed="true" stored="true"/>
53
+ <field name="content" type="text" indexed="true" stored="true"/>
54
+ <field name="stuff_id" type="string" indexed="true" stored="true" multiValued="true"/>
55
+ <field name="text" type="text" indexed="true" stored="false" multiValued="true"/>
56
+ </fields>
57
+
58
+ <uniqueKey>id</uniqueKey>
59
+ <defaultSearchField>text</defaultSearchField>
60
+ <solrQueryParser defaultOperator="OR"/>
61
+ <copyField source="content" dest="text"/>
62
+ <copyField source="name" dest="text"/>
63
+ </schema>
64
+
@@ -0,0 +1,58 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <!--
3
+ Copyright 2010 The Skunkworx.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ -->
17
+
18
+ <schema name="items" version="1.2">
19
+ <types>
20
+ <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
21
+ <fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
22
+ <fieldType name="text" class="solr.TextField" positionIncrementGap="100">
23
+ <analyzer type="index">
24
+ <tokenizer class="solr.WhitespaceTokenizerFactory"/>
25
+ <filter class="solr.StopFilterFactory"
26
+ ignoreCase="true"
27
+ words="stopwords.txt"
28
+ enablePositionIncrements="true"
29
+ />
30
+ <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
31
+ <filter class="solr.LowerCaseFilterFactory"/>
32
+ <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt"/>
33
+ </analyzer>
34
+ <analyzer type="query">
35
+ <tokenizer class="solr.WhitespaceTokenizerFactory"/>
36
+ <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
37
+ <filter class="solr.StopFilterFactory"
38
+ ignoreCase="true"
39
+ words="stopwords.txt"
40
+ enablePositionIncrements="true"
41
+ />
42
+ <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
43
+ <filter class="solr.LowerCaseFilterFactory"/>
44
+ <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt"/>
45
+ </analyzer>
46
+ </fieldType>
47
+ </types>
48
+
49
+ <fields>
50
+ <field name="id" type="string" indexed="true" stored="true" required="true" />
51
+ <field name="name" type="string" indexed="true" stored="true"/>
52
+ </fields>
53
+
54
+ <uniqueKey>id</uniqueKey>
55
+ <defaultSearchField>name</defaultSearchField>
56
+ <solrQueryParser defaultOperator="OR"/>
57
+ </schema>
58
+