outoftime-sunspot 0.8.9 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/README.rdoc +13 -21
  2. data/Rakefile +0 -2
  3. data/TODO +2 -15
  4. data/VERSION.yml +2 -2
  5. data/bin/sunspot-configure-solr +46 -0
  6. data/bin/sunspot-solr +15 -7
  7. data/lib/sunspot/adapters.rb +5 -1
  8. data/lib/sunspot/composite_setup.rb +186 -0
  9. data/lib/sunspot/configuration.rb +7 -1
  10. data/lib/sunspot/data_extractor.rb +10 -0
  11. data/lib/sunspot/date_facet.rb +36 -0
  12. data/lib/sunspot/date_facet_row.rb +17 -0
  13. data/lib/sunspot/dsl/field_query.rb +72 -0
  14. data/lib/sunspot/dsl/fields.rb +30 -3
  15. data/lib/sunspot/dsl/query.rb +16 -35
  16. data/lib/sunspot/dsl/query_facet.rb +31 -0
  17. data/lib/sunspot/dsl/scope.rb +76 -20
  18. data/lib/sunspot/dsl/search.rb +30 -0
  19. data/lib/sunspot/dsl.rb +1 -1
  20. data/lib/sunspot/facet.rb +17 -3
  21. data/lib/sunspot/facet_row.rb +4 -4
  22. data/lib/sunspot/field.rb +130 -207
  23. data/lib/sunspot/field_factory.rb +126 -0
  24. data/lib/sunspot/indexer.rb +61 -14
  25. data/lib/sunspot/instantiated_facet.rb +38 -0
  26. data/lib/sunspot/instantiated_facet_row.rb +12 -0
  27. data/lib/sunspot/query/base_query.rb +90 -0
  28. data/lib/sunspot/query/connective.rb +77 -0
  29. data/lib/sunspot/query/dynamic_query.rb +39 -56
  30. data/lib/sunspot/query/field_facet.rb +132 -4
  31. data/lib/sunspot/query/field_query.rb +57 -0
  32. data/lib/sunspot/query/pagination.rb +1 -1
  33. data/lib/sunspot/query/query_facet.rb +72 -0
  34. data/lib/sunspot/query/query_facet_row.rb +19 -0
  35. data/lib/sunspot/query/restriction.rb +9 -7
  36. data/lib/sunspot/query/scope.rb +165 -0
  37. data/lib/sunspot/query/sort.rb +17 -14
  38. data/lib/sunspot/query/sort_composite.rb +33 -0
  39. data/lib/sunspot/query.rb +162 -351
  40. data/lib/sunspot/query_facet.rb +33 -0
  41. data/lib/sunspot/query_facet_row.rb +21 -0
  42. data/lib/sunspot/schema.rb +165 -0
  43. data/lib/sunspot/search/hit.rb +62 -0
  44. data/lib/sunspot/search.rb +104 -41
  45. data/lib/sunspot/session.rb +64 -32
  46. data/lib/sunspot/setup.rb +119 -48
  47. data/lib/sunspot/type.rb +48 -2
  48. data/lib/sunspot.rb +74 -8
  49. data/solr/solr/conf/schema.xml +44 -225
  50. data/spec/api/build_search_spec.rb +557 -63
  51. data/spec/api/indexer_spec.rb +156 -74
  52. data/spec/api/query_spec.rb +55 -31
  53. data/spec/api/search_retrieval_spec.rb +210 -33
  54. data/spec/api/session_spec.rb +81 -26
  55. data/spec/api/sunspot_spec.rb +5 -7
  56. data/spec/integration/faceting_spec.rb +130 -0
  57. data/spec/integration/keyword_search_spec.rb +72 -31
  58. data/spec/integration/scoped_search_spec.rb +13 -0
  59. data/spec/integration/stored_fields_spec.rb +10 -0
  60. data/spec/mocks/blog.rb +3 -0
  61. data/spec/mocks/comment.rb +12 -23
  62. data/spec/mocks/connection.rb +84 -0
  63. data/spec/mocks/mock_adapter.rb +11 -3
  64. data/spec/mocks/mock_record.rb +41 -0
  65. data/spec/mocks/photo.rb +8 -0
  66. data/spec/mocks/post.rb +18 -23
  67. data/spec/spec_helper.rb +29 -14
  68. data/tasks/gemspec.rake +4 -3
  69. data/tasks/rdoc.rake +2 -2
  70. data/tasks/schema.rake +19 -0
  71. data/templates/schema.xml.haml +24 -0
  72. metadata +48 -7
  73. data/spec/mocks/base_class.rb +0 -2
@@ -1,231 +1,50 @@
1
- <?xml version="1.0" ?>
2
- <!--
3
- Licensed to the Apache Software Foundation (ASF) under one or more
4
- contributor license agreements. See the NOTICE file distributed with
5
- this work for additional information regarding copyright ownership.
6
- The ASF licenses this file to You under the Apache License, Version 2.0
7
- (the "License"); you may not use this file except in compliance with
8
- the License. You may obtain a copy of the License at
9
-
10
- http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- Unless required by applicable law or agreed to in writing, software
13
- distributed under the License is distributed on an "AS IS" BASIS,
14
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- See the License for the specific language governing permissions and
16
- limitations under the License.
17
- -->
18
-
19
- <!-- This is the Solr schema file. This file should be named "schema.xml" and
20
- should be in the conf directory under the solr home
21
- (i.e. ./solr/conf/schema.xml by default)
22
- or located where the classloader for the Solr webapp can find it.
23
-
24
- For more information, on how to customize this file, please see
25
- http://wiki.apache.org/solr/SchemaXml
26
- -->
27
-
28
- <schema name="sunspot" version="1.1">
29
- <!-- attribute "name" is the name of this schema and is only used for display purposes.
30
- Applications should change this to reflect the nature of the search collection.
31
- version="1.1" is Solr's version number for the schema syntax and semantics. It should
32
- not normally be changed by applications.
33
- 1.0: multiValued attribute did not exist, all fields are multiValued by nature
34
- 1.1: multiValued attribute introduced, false by default -->
35
-
1
+ <?xml version='1.0' encoding='utf-8' ?>
2
+ <schema name='sunspot' version='0.9'>
36
3
  <types>
37
- <!-- field type definitions. The "name" attribute is
38
- just a label to be used by field definitions. The "class"
39
- attribute and any other attributes determine the real
40
- behavior of the fieldtype.
41
- Class names starting with "solr" refer to java classes in the
42
- org.apache.solr.analysis package.
43
- -->
44
-
45
- <!-- The StrField type is not analyzed, but indexed/stored verbatim.
46
- - StrField and TextField support an optional compressThreshold which
47
- limits compression (if enabled in the derived fields) to values which
48
- exceed a certain size (in characters).
49
- -->
50
- <fieldtype name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
51
-
52
- <!-- boolean type: "true" or "false" -->
53
- <fieldtype name="boolean" class="solr.BoolField" sortMissingLast="true" omitNorms="true"/>
54
-
55
- <!-- The optional sortMissingLast and sortMissingFirst attributes are
56
- currently supported on types that are sorted internally as strings.
57
- - If sortMissingLast="true", then a sort on this field will cause documents
58
- without the field to come after documents with the field,
59
- regardless of the requested sort order (asc or desc).
60
- - If sortMissingFirst="true", then a sort on this field will cause documents
61
- without the field to come before documents with the field,
62
- regardless of the requested sort order.
63
- - If sortMissingLast="false" and sortMissingFirst="false" (the default),
64
- then default lucene sorting will be used which places docs without the
65
- field first in an ascending sort and last in a descending sort.
66
- -->
67
-
68
-
69
- <!-- numeric field types that store and index the text
70
- value verbatim (and hence don't support range queries, since the
71
- lexicographic ordering isn't equal to the numeric ordering) -->
72
- <fieldtype name="integer" class="solr.IntField" omitNorms="true"/>
73
- <fieldtype name="long" class="solr.LongField" omitNorms="true"/>
74
- <fieldtype name="float" class="solr.FloatField" omitNorms="true"/>
75
- <fieldtype name="double" class="solr.DoubleField" omitNorms="true"/>
76
-
77
-
78
- <!-- Numeric field types that manipulate the value into
79
- a string value that isn't human-readable in its internal form,
80
- but with a lexicographic ordering the same as the numeric ordering,
81
- so that range queries work correctly. -->
82
- <fieldtype name="sint" class="solr.SortableIntField" sortMissingLast="true" omitNorms="true"/>
83
- <fieldtype name="slong" class="solr.SortableLongField" sortMissingLast="true" omitNorms="true"/>
84
- <fieldtype name="sfloat" class="solr.SortableFloatField" sortMissingLast="true" omitNorms="true"/>
85
- <fieldtype name="sdouble" class="solr.SortableDoubleField" sortMissingLast="true" omitNorms="true"/>
86
-
87
-
88
- <!-- The format for this date field is of the form 1995-12-31T23:59:59Z, and
89
- is a more restricted form of the canonical representation of dateTime
90
- http://www.w3.org/TR/xmlschema-2/#dateTime
91
- The trailing "Z" designates UTC time and is mandatory.
92
- Optional fractional seconds are allowed: 1995-12-31T23:59:59.999Z
93
- All other components are mandatory.
94
-
95
- Expressions can also be used to denote calculations that should be
96
- performed relative to "NOW" to determine the value, ie...
97
-
98
- NOW/HOUR
99
- ... Round to the start of the current hour
100
- NOW-1DAY
101
- ... Exactly 1 day prior to now
102
- NOW/DAY+6MONTHS+3DAYS
103
- ... 6 months and 3 days in the future from the start of
104
- the current day
105
-
106
- Consult the DateField javadocs for more information.
107
- -->
108
- <fieldtype name="date" class="solr.DateField" sortMissingLast="true" omitNorms="true"/>
109
-
110
- <!-- solr.TextField allows the specification of custom text analyzers
111
- specified as a tokenizer and a list of token filters. Different
112
- analyzers may be specified for indexing and querying.
113
-
114
- The optional positionIncrementGap puts space between multiple fields of
115
- this type on the same document, with the purpose of preventing false phrase
116
- matching across fields.
117
-
118
- For more info on customizing your analyzer chain, please see
119
- http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters
120
- -->
121
-
122
- <!-- One can also specify an existing Analyzer class that has a
123
- default constructor via the class attribute on the analyzer element
124
- <fieldtype name="text_greek" class="solr.TextField">
125
- <analyzer class="org.apache.lucene.analysis.el.GreekAnalyzer"/>
126
- </fieldType>
127
- -->
128
-
129
- <!-- A text field that only splits on whitespace for exact matching of words -->
130
- <fieldtype name="text_ws" class="solr.TextField" positionIncrementGap="100">
4
+ <fieldtype class='solr.TextField' name='text' positionIncrementGap='100'>
131
5
  <analyzer>
132
- <tokenizer class="solr.WhitespaceTokenizerFactory"/>
6
+ <tokenizer class='solr.StandardTokenizerFactory' />
7
+ <filter class='solr.StandardFilterFactory' />
8
+ <filter class='solr.LowerCaseFilterFactory' />
133
9
  </analyzer>
134
10
  </fieldtype>
135
-
136
- <fieldtype name="text" class="solr.TextField" positionIncrementGap="100">
137
- <analyzer>
138
- <tokenizer class="solr.StandardTokenizerFactory"/>
139
- <filter class="solr.StandardFilterFactory"/>
140
- <filter class="solr.LowerCaseFilterFactory"/>
141
- </analyzer>
142
- </fieldtype>
143
-
144
- <fieldtype name="text_zh" class="solr.TextField">
145
- <analyzer class="org.apache.lucene.analysis.cn.ChineseAnalyzer"/>
146
- </fieldtype>
147
-
148
-
149
- <!-- Less flexible matching, but less false matches. Probably not ideal for product names,
150
- but may be good for SKUs. Can insert dashes in the wrong place and still match. -->
151
- <fieldtype name="textTight" class="solr.TextField" positionIncrementGap="100" >
152
- <analyzer>
153
- <tokenizer class="solr.WhitespaceTokenizerFactory"/>
154
- <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="false"/>
155
- <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
156
- <filter class="solr.WordDelimiterFilterFactory" generateWordParts="0" generateNumberParts="0" catenateWords="1" catenateNumbers="1" catenateAll="0"/>
157
- <filter class="solr.LowerCaseFilterFactory"/>
158
- <filter class="solr.EnglishPorterFilterFactory" protected="protwords.txt"/>
159
- <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
160
- </analyzer>
161
- </fieldtype>
162
-
11
+ <fieldtype class='solr.RandomSortField' name='rand'></fieldtype>
12
+ <fieldtype class='solr.BoolField' name='boolean' omitNorms='true' />
13
+ <fieldtype class='solr.SortableFloatField' name='sfloat' omitNorms='true' />
14
+ <fieldtype class='solr.DateField' name='date' omitNorms='true' />
15
+ <fieldtype class='solr.SortableIntField' name='sint' omitNorms='true' />
16
+ <fieldtype class='solr.StrField' name='string' omitNorms='true' />
163
17
  </types>
164
-
165
-
166
18
  <fields>
167
- <!-- Valid attributes for fields:
168
- name: mandatory - the name for the field
169
- type: mandatory - the name of a previously defined type from the <types> section
170
- indexed: true if this field should be indexed (searchable or sortable)
171
- stored: true if this field should be retrievable
172
- compressed: [false] if this field should be stored using gzip compression
173
- (this will only apply if the field type is compressable; among
174
- the standard field types, only TextField and StrField are)
175
- multiValued: true if this field may contain multiple values per document
176
- omitNorms: (expert) set to true to omit the norms associated with
177
- this field (this disables length normalization and index-time
178
- boosting for the field, and saves some memory). Only full-text
179
- fields or fields that need an index-time boost need norms.
180
- -->
181
-
182
- <field name="id" type="string" indexed="true" stored="true"/>
183
- <field name="pk" type="string" indexed="true" stored="true"/>
184
- <field name="type" type="string" indexed="true" stored="false" multiValued="true"/>
185
-
186
- <!-- catchall field, containing all other searchable text fields (implemented
187
- via copyField further on in this schema -->
188
- <field name="text" type="text" indexed="true" stored="false" multiValued="true"/>
189
-
190
- <!-- Dynamic field definitions. If a field name is not found, dynamicFields
191
- will be used if the name matches any of the patterns.
192
- RESTRICTION: the glob-like pattern in the name attribute must have
193
- a "*" only at the start or the end.
194
- EXAMPLE: name="*_i" will match any field ending in _i (like myid_i, z_i)
195
- Longer patterns will be matched first. if equal size patterns
196
- both match, the first appearing in the schema will be used. -->
197
- <dynamicField name="*_text" type="text" indexed="true" stored="false" multiValued="true"/>
198
-
199
- <dynamicField name="*_s" type="string" indexed="true" stored="false" multiValued="false"/>
200
- <dynamicField name="*_i" type="sint" indexed="true" stored="false" multiValued="false"/>
201
- <dynamicField name="*_f" type="sfloat" indexed="true" stored="false" multiValued="false"/>
202
- <dynamicField name="*_d" type="date" indexed="true" stored="false" multiValued="false"/>
203
- <dynamicField name="*_b" type="boolean" indexed="true" stored="false" multiValued="false"/>
204
-
205
- <dynamicField name="*_sm" type="string" indexed="true" stored="false" multiValued="true"/>
206
- <dynamicField name="*_im" type="sint" indexed="true" stored="false" multiValued="true"/>
207
- <dynamicField name="*_fm" type="sfloat" indexed="true" stored="false" multiValued="true"/>
208
- <dynamicField name="*_dm" type="date" indexed="true" stored="false" multiValued="true"/>
209
- <dynamicField name="*_bm" type="boolean" indexed="true" stored="false" multiValued="true"/>
210
- </fields>
211
-
212
- <!-- field to use to determine and enforce document uniqueness. -->
213
- <uniqueKey>id</uniqueKey>
214
-
215
- <!-- field for the QueryParser to use when an explicit fieldname is absent -->
216
- <defaultSearchField>text</defaultSearchField>
217
-
218
- <!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
219
- <solrQueryParser defaultOperator="AND"/>
220
-
221
- <!-- copyField commands copy one field to another at the time a document
222
- is added to the index. It's used either to index the same field differently,
223
- or to add multiple fields to the same field for easier/faster searching. -->
224
- <copyField source="*_text" dest="text"/>
225
-
226
- <!-- Similarity is the scoring routine for each document vs. a query.
227
- A custom similarity may be specified here, but the default is fine
228
- for most applications. -->
229
- <!-- <similarity class="org.apache.lucene.search.DefaultSimilarity"/> -->
230
-
231
- </schema>
19
+ <field indexed='true' multiValued='false' name='id' stored='true' type='string' />
20
+ <field indexed='true' multiValued='true' name='type' stored='false' type='string' />
21
+ <field indexed='true' multiValued='false' name='class_name' stored='false' type='string' />
22
+ <field indexed='true' multiValued='true' name='text' stored='false' type='text' />
23
+ <dynamicField indexed='true' multiValued='true' name='*_text' stored='false' type='text' />
24
+ <dynamicField indexed='true' name='random_*' stored='false' type='rand' />
25
+ <dynamicField indexed='true' multiValued='false' name='*_b' stored='false' type='boolean' />
26
+ <dynamicField indexed='true' multiValued='false' name='*_f' stored='false' type='sfloat' />
27
+ <dynamicField indexed='true' multiValued='false' name='*_d' stored='false' type='date' />
28
+ <dynamicField indexed='true' multiValued='false' name='*_i' stored='false' type='sint' />
29
+ <dynamicField indexed='true' multiValued='false' name='*_s' stored='false' type='string' />
30
+ <dynamicField indexed='true' multiValued='true' name='*_bm' stored='false' type='boolean' />
31
+ <dynamicField indexed='true' multiValued='true' name='*_fm' stored='false' type='sfloat' />
32
+ <dynamicField indexed='true' multiValued='true' name='*_dm' stored='false' type='date' />
33
+ <dynamicField indexed='true' multiValued='true' name='*_im' stored='false' type='sint' />
34
+ <dynamicField indexed='true' multiValued='true' name='*_sm' stored='false' type='string' />
35
+ <dynamicField indexed='true' multiValued='false' name='*_bs' stored='true' type='boolean' />
36
+ <dynamicField indexed='true' multiValued='false' name='*_fs' stored='true' type='sfloat' />
37
+ <dynamicField indexed='true' multiValued='false' name='*_ds' stored='true' type='date' />
38
+ <dynamicField indexed='true' multiValued='false' name='*_is' stored='true' type='sint' />
39
+ <dynamicField indexed='true' multiValued='false' name='*_ss' stored='true' type='string' />
40
+ <dynamicField indexed='true' multiValued='true' name='*_bms' stored='true' type='boolean' />
41
+ <dynamicField indexed='true' multiValued='true' name='*_fms' stored='true' type='sfloat' />
42
+ <dynamicField indexed='true' multiValued='true' name='*_dms' stored='true' type='date' />
43
+ <dynamicField indexed='true' multiValued='true' name='*_ims' stored='true' type='sint' />
44
+ <dynamicField indexed='true' multiValued='true' name='*_sms' stored='true' type='string' />
45
+ </fields>
46
+ <uniqueKey>id</uniqueKey>
47
+ <defaultSearchField>text</defaultSearchField>
48
+ <solrQueryParser defaultOperator='AND' />
49
+ <copyField dest='text' source='*_text' />
50
+ </schema>