benjaminkrause-sunspot 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/History.txt +107 -0
  2. data/LICENSE +18 -0
  3. data/README.rdoc +159 -0
  4. data/Rakefile +9 -0
  5. data/TODO +11 -0
  6. data/VERSION.yml +4 -0
  7. data/bin/sunspot-configure-solr +46 -0
  8. data/bin/sunspot-solr +86 -0
  9. data/lib/light_config.rb +40 -0
  10. data/lib/sunspot/adapters.rb +265 -0
  11. data/lib/sunspot/composite_setup.rb +184 -0
  12. data/lib/sunspot/configuration.rb +49 -0
  13. data/lib/sunspot/data_extractor.rb +50 -0
  14. data/lib/sunspot/dsl/field_query.rb +77 -0
  15. data/lib/sunspot/dsl/fields.rb +95 -0
  16. data/lib/sunspot/dsl/fulltext.rb +106 -0
  17. data/lib/sunspot/dsl/query.rb +107 -0
  18. data/lib/sunspot/dsl/query_facet.rb +31 -0
  19. data/lib/sunspot/dsl/restriction.rb +25 -0
  20. data/lib/sunspot/dsl/scope.rb +193 -0
  21. data/lib/sunspot/dsl/search.rb +30 -0
  22. data/lib/sunspot/dsl.rb +4 -0
  23. data/lib/sunspot/facet.rb +24 -0
  24. data/lib/sunspot/facet_data.rb +152 -0
  25. data/lib/sunspot/facet_row.rb +12 -0
  26. data/lib/sunspot/field.rb +148 -0
  27. data/lib/sunspot/field_factory.rb +141 -0
  28. data/lib/sunspot/indexer.rb +129 -0
  29. data/lib/sunspot/instantiated_facet.rb +45 -0
  30. data/lib/sunspot/instantiated_facet_row.rb +27 -0
  31. data/lib/sunspot/query/base_query.rb +55 -0
  32. data/lib/sunspot/query/boost_query.rb +20 -0
  33. data/lib/sunspot/query/connective.rb +148 -0
  34. data/lib/sunspot/query/dynamic_query.rb +61 -0
  35. data/lib/sunspot/query/field_facet.rb +129 -0
  36. data/lib/sunspot/query/field_query.rb +69 -0
  37. data/lib/sunspot/query/fulltext_base_query.rb +86 -0
  38. data/lib/sunspot/query/highlighting.rb +36 -0
  39. data/lib/sunspot/query/local.rb +24 -0
  40. data/lib/sunspot/query/pagination.rb +39 -0
  41. data/lib/sunspot/query/query_facet.rb +78 -0
  42. data/lib/sunspot/query/query_facet_row.rb +19 -0
  43. data/lib/sunspot/query/query_field_facet.rb +20 -0
  44. data/lib/sunspot/query/restriction.rb +272 -0
  45. data/lib/sunspot/query/scope.rb +185 -0
  46. data/lib/sunspot/query/sort.rb +105 -0
  47. data/lib/sunspot/query/sort_composite.rb +33 -0
  48. data/lib/sunspot/query/text_field_boost.rb +15 -0
  49. data/lib/sunspot/query.rb +108 -0
  50. data/lib/sunspot/schema.rb +147 -0
  51. data/lib/sunspot/search/highlight.rb +38 -0
  52. data/lib/sunspot/search/hit.rb +113 -0
  53. data/lib/sunspot/search.rb +240 -0
  54. data/lib/sunspot/session.rb +206 -0
  55. data/lib/sunspot/setup.rb +312 -0
  56. data/lib/sunspot/text_field_setup.rb +29 -0
  57. data/lib/sunspot/type.rb +200 -0
  58. data/lib/sunspot/util.rb +190 -0
  59. data/lib/sunspot.rb +459 -0
  60. data/solr/etc/jetty.xml +212 -0
  61. data/solr/etc/webdefault.xml +379 -0
  62. data/solr/lib/jetty-6.1.3.jar +0 -0
  63. data/solr/lib/jetty-util-6.1.3.jar +0 -0
  64. data/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
  65. data/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
  66. data/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
  67. data/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
  68. data/solr/lib/servlet-api-2.5-6.1.3.jar +0 -0
  69. data/solr/solr/conf/elevate.xml +36 -0
  70. data/solr/solr/conf/protwords.txt +21 -0
  71. data/solr/solr/conf/schema.xml +64 -0
  72. data/solr/solr/conf/solrconfig.xml +726 -0
  73. data/solr/solr/conf/stopwords.txt +57 -0
  74. data/solr/solr/conf/synonyms.txt +31 -0
  75. data/solr/start.jar +0 -0
  76. data/solr/webapps/solr.war +0 -0
  77. data/spec/api/adapters_spec.rb +33 -0
  78. data/spec/api/indexer/attributes_spec.rb +100 -0
  79. data/spec/api/indexer/batch_spec.rb +46 -0
  80. data/spec/api/indexer/dynamic_fields_spec.rb +33 -0
  81. data/spec/api/indexer/fixed_fields_spec.rb +57 -0
  82. data/spec/api/indexer/fulltext_spec.rb +43 -0
  83. data/spec/api/indexer/removal_spec.rb +46 -0
  84. data/spec/api/indexer/spec_helper.rb +1 -0
  85. data/spec/api/indexer_spec.rb +4 -0
  86. data/spec/api/query/connectives_spec.rb +161 -0
  87. data/spec/api/query/dsl_spec.rb +12 -0
  88. data/spec/api/query/dynamic_fields_spec.rb +148 -0
  89. data/spec/api/query/faceting_spec.rb +272 -0
  90. data/spec/api/query/fulltext_spec.rb +152 -0
  91. data/spec/api/query/highlighting_spec.rb +82 -0
  92. data/spec/api/query/local_spec.rb +37 -0
  93. data/spec/api/query/ordering_pagination_spec.rb +95 -0
  94. data/spec/api/query/scope_spec.rb +253 -0
  95. data/spec/api/query/spec_helper.rb +1 -0
  96. data/spec/api/query/text_field_scoping_spec.rb +30 -0
  97. data/spec/api/query/types_spec.rb +20 -0
  98. data/spec/api/search/dynamic_fields_spec.rb +27 -0
  99. data/spec/api/search/faceting_spec.rb +206 -0
  100. data/spec/api/search/highlighting_spec.rb +65 -0
  101. data/spec/api/search/hits_spec.rb +62 -0
  102. data/spec/api/search/results_spec.rb +52 -0
  103. data/spec/api/search/search_spec.rb +11 -0
  104. data/spec/api/search/spec_helper.rb +1 -0
  105. data/spec/api/session_spec.rb +157 -0
  106. data/spec/api/spec_helper.rb +1 -0
  107. data/spec/api/sunspot_spec.rb +18 -0
  108. data/spec/helpers/indexer_helper.rb +29 -0
  109. data/spec/helpers/query_helper.rb +13 -0
  110. data/spec/helpers/search_helper.rb +78 -0
  111. data/spec/integration/dynamic_fields_spec.rb +55 -0
  112. data/spec/integration/faceting_spec.rb +169 -0
  113. data/spec/integration/highlighting_spec.rb +22 -0
  114. data/spec/integration/keyword_search_spec.rb +148 -0
  115. data/spec/integration/local_search_spec.rb +47 -0
  116. data/spec/integration/scoped_search_spec.rb +303 -0
  117. data/spec/integration/spec_helper.rb +1 -0
  118. data/spec/integration/stored_fields_spec.rb +10 -0
  119. data/spec/integration/test_pagination.rb +32 -0
  120. data/spec/mocks/adapters.rb +32 -0
  121. data/spec/mocks/blog.rb +3 -0
  122. data/spec/mocks/comment.rb +19 -0
  123. data/spec/mocks/connection.rb +84 -0
  124. data/spec/mocks/mock_adapter.rb +30 -0
  125. data/spec/mocks/mock_record.rb +48 -0
  126. data/spec/mocks/photo.rb +8 -0
  127. data/spec/mocks/post.rb +75 -0
  128. data/spec/mocks/super_class.rb +2 -0
  129. data/spec/mocks/user.rb +8 -0
  130. data/spec/spec_helper.rb +60 -0
  131. data/tasks/gemspec.rake +35 -0
  132. data/tasks/rcov.rake +28 -0
  133. data/tasks/rdoc.rake +22 -0
  134. data/tasks/schema.rake +19 -0
  135. data/tasks/spec.rake +24 -0
  136. data/tasks/todo.rake +4 -0
  137. data/templates/schema.xml.erb +36 -0
  138. metadata +312 -0
data/History.txt ADDED
@@ -0,0 +1,107 @@
1
+ == 0.10.0 2009-09-04
2
+ * Informative, non-firehose Search#inspect and Hit#inspect
3
+ * Soften up #paginate options
4
+ * Silently ignore keyword calls with nil/blank/whitespace keywords
5
+ * Boost queries
6
+ * Query facets support all facet options
7
+ * Remove dependency on haml and use erb since it is only used to generate one file
8
+ * Restrict field facet to a set of desired values
9
+ * Phrase fields
10
+ * Search-time field boost
11
+ * Don't require that all searched types have a field
12
+ * Remove support for :other option in time faceting
13
+ * Remove order_by_random() method
14
+ * Support for prefix queries
15
+ * Quote values in range restrictions if they contain spaces
16
+ * Allow scoping by text fields
17
+ * Correct backwards ranges
18
+ * Raise descriptive error if no types passed to search
19
+ * Handle empty query facets, query facet rows, and connectives
20
+ * Text fields only stored when explicitly set
21
+ * Removed options and Query from public API
22
+ * Geographical search using LocalSolr
23
+ * Keyword highlighting
24
+
25
+ == 0.9.0 2009-07-21
26
+ * Use Dismax parser for keyword search
27
+ * Field and document boosting
28
+ * Specify which fields to search in keyword search
29
+ * Allow indexing of multiple values in text fields
30
+ * Access keyword relevance score in Hit objects
31
+ * Allow stored fields, retrieve stored values from Hit objects
32
+ * Support more values in shorthand restrictions
33
+ * Disjunctions and conjunctions
34
+ * Random ordering
35
+ * Control all options for field facets
36
+ * Time range facets
37
+ * Get referenced objects from facets on foreign keys
38
+ * Facet by class
39
+ * Batch indexing
40
+ * New Date field type
41
+ * Direct access to data accessors
42
+ * Executable to configure production Solr instances
43
+ * Replace solr-ruby with RSolr
44
+ * Remove accidental ActiveSupport dependency
45
+
46
+ == 0.8.9 2009-06-23
47
+ * Fix OrderedHash bug in older versions of ActiveSupport
48
+
49
+ == 0.8.8 2009-06-15
50
+ * Escape type names to support namespaced classes
51
+ * Fix bug with anonymous modules in Ruby 1.9
52
+
53
+ == 0.8.7 2009-06-10
54
+ * Add --pid-dir option for sunspot-solr executable
55
+
56
+ == 0.8.5 2009-06-09
57
+ * Added dependencies for sunspot-solr executable to gem dependencies
58
+ * Search for adapters using class ancestors rather than superclasses
59
+
60
+ == 0.8.3 2009-06-03
61
+ * Index objects passed as a collection in a single HTTP request
62
+
63
+ == 0.8.2 2009-05-27
64
+ * Allow specification of Solr home when using sunspot-solr
65
+
66
+ == 0.8.1 2009-05-26
67
+ * Add Search#execute! to public API
68
+
69
+ == 0.8.0 2009-05-22
70
+ * Access query API directly; instantiate search without running it
71
+ * Dynamic fields
72
+ * Search blocks can be evaluated in calling context
73
+
74
+ == 0.7.3 2009-05-06
75
+ * Better exception handling when class doesn't have adapter/setup
76
+
77
+ == 0.7.2 2009-04-29
78
+ * Dirty sessions
79
+
80
+ == 0.7.1 2009-04-29
81
+ * Removed extlib dependency from gemspec
82
+
83
+ == 0.7.0 2009-04-28
84
+ * Less magic in the DSL
85
+ * Restrict by empty values
86
+ * Negative scoping using without() method
87
+ * Exclusion by object identity using without(instance)
88
+ * Support for faceting
89
+ * Explicit commits
90
+ * Boolean field type
91
+ * Attribute field flexibility
92
+ * Virtual field blocks can be evaluated in calling context
93
+ * Order available by multiple fields
94
+ * New adapter API
95
+ * Got rid of builder API
96
+ * Full documentation
97
+
98
+ == 0.0.2 2009-02-14
99
+ * Run sunspot's built-in Solr instance using
100
+ sunspot-solr executable
101
+ * Search hash interpretation delegated to
102
+ Builder object
103
+
104
+ == 0.0.1 2008-12-11
105
+ * Initial release
106
+ * Define indexing for any class using DSL
107
+ * Search indexed classes using DSL
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Permission is hereby granted, free of charge, to any person obtaining
2
+ a copy of this software and associated documentation files (the
3
+ 'Software'), to deal in the Software without restriction, including
4
+ without limitation the rights to use, copy, modify, merge, publish,
5
+ distribute, sublicense, and/or sell copies of the Software, and to
6
+ permit persons to whom the Software is furnished to do so, subject to
7
+ the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be
10
+ included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
13
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
15
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
16
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
17
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,159 @@
1
+ = Sunspot
2
+
3
+ http://outoftime.github.com/sunspot
4
+
5
+ Sunspot is a Ruby library for expressive, powerful interaction with the Solr search engine.
6
+ Sunspot is built on top of the RSolr gem, which provides a low-level interface for Solr
7
+ interaction; Sunspot provides a simple, intuitive, expressive DSL backed by powerful
8
+ features for indexing objects and searching for them.
9
+
10
+ Sunspot is designed to be easily plugged in to any ORM, or even non-database-backed
11
+ objects such as the filesystem.
12
+
13
+ This README is intended as a quick primer on what Sunspot is capable of; for
14
+ detailed treatment of Sunspot's full feature range, check out the wiki:
15
+ http://wiki.github.com/outoftime/sunspot
16
+
17
+
18
+ === Features:
19
+
20
+ * Define indexing strategy for each searchable class using intuitive block-based API
21
+ * Clean separation between keyword-searchable fields and fields for scoping/ordering
22
+ * Define fields based on existing attributes or "virtual fields" for custom indexing
23
+ * Indexes each object's entire superclass hierarchy, for easy searching for all objects inheriting from a parent class
24
+ * Intuitive DSL for scoping searches, with all the usual boolean operators available
25
+ * Intuitive interface for requesting facets on indexed fields
26
+ * Extensible adapter architecture for easy integration of other ORMs or non-model classes
27
+ * Refine search using field facets, date range facets, or ultra-powerful query facets
28
+ * Full compatibility with will_paginate
29
+ * Ordering
30
+
31
+ == Installation
32
+
33
+ gem sources -a http://gems.github.com
34
+ gem install outoftime-sunspot
35
+
36
+ In order to start the packaged Solr installation, run:
37
+
38
+ sunspot-solr start -- [-d /path/to/data/directory] [-p port] [-s path/to/solr/home] [--pid-dir=path/to/pid/dir]
39
+
40
+ If you don't specify a data directory, your Solr index will be stored in your operating system's temporary directory.
41
+
42
+ If you specify a solr home, the directory must contain a <code>conf</code>
43
+ directory, which should contain at least <code>schema.xml</code> and
44
+ <code>solrconfig.xml</code>. Be sure to copy the <code>schema.xml</code> out of
45
+ the Sunspot gem's <code>solr/solr/conf</code> directory. Sunspot relies on the
46
+ field name patterns defined in the packaged <code>schema.xml</code>, so those
47
+ cannot be modified.
48
+
49
+ You can also run your own instance of Solr wherever you'd like; just copy the solr/config/schema.xml file out of the gem's solr into your installation.
50
+ You can change the URL at which Sunspot accesses Solr with:
51
+
52
+ Sunspot.config.solr.url = 'http://solr.my.host:9818/solr'
53
+
54
+ == Rails Integration
55
+
56
+ The {Sunspot::Rails}[http://github.com/outoftime/sunspot_rails] plugin makes
57
+ integrating Sunspot into Rails drop-in easy.
58
+
59
+ == Using Sunspot
60
+
61
+ === Define an index:
62
+
63
+ class Post
64
+ #...
65
+ end
66
+
67
+ Sunspot.setup(Post) do
68
+ text :title, :body
69
+ string :author_name
70
+ integer :blog_id
71
+ integer :category_ids
72
+ float :average_rating, :using => :ratings_average
73
+ time :published_at
74
+ string :sort_title do
75
+ title.downcase.sub(/^(an?|the)\W+/, ''/) if title = self.title
76
+ end
77
+ end
78
+
79
+ See Sunspot.setup for more information.
80
+
81
+ Note that in order for a class to be searchable, it must have an adapter
82
+ registered for itself or one of its subclasses. Adapters allow Sunspot to load
83
+ objects out of persistent storage, and to determine their primary key for
84
+ indexing. {Sunspot::Rails}[http://github.com/outoftime/sunspot_rails] comes with
85
+ an adapter for ActiveRecord objects, but for other types of models you will need
86
+ to define your own. See Sunspot::Adapters for more information.
87
+
88
+ === Search for objects:
89
+
90
+ search = Sunspot.search Post do
91
+ keywords 'great pizza'
92
+ with :author_name, 'Mark Twain'
93
+ with(:blog_id).any_of [2, 14]
94
+ with(:category_ids).all_of [4, 10]
95
+ with(:published_at).less_than Time.now
96
+ any_of do
97
+ with(:expired_at).greater_than(Time.now)
98
+ with(:expired_at, nil)
99
+ end
100
+ without :title, 'Bad Title'
101
+ without bad_instance # specifically exclude this instance from results
102
+
103
+ paginate :page => 3, :per_page => 15
104
+ order_by :average_rating, :desc
105
+
106
+ facet :blog_id
107
+ end
108
+
109
+ See Sunspot.search for more information.
110
+
111
+ === Get data from search:
112
+
113
+ search.results
114
+ search.total
115
+ search.page
116
+ search.per_page
117
+ search.facet(:blog_id)
118
+
119
+ == About the API documentation
120
+
121
+ All of the methods documented in the RDoc are considered part of Sunspot's
122
+ public API. Methods that are not part of the public API are documented in the
123
+ code, but excluded from the RDoc. If you find yourself needing to access methods
124
+ that are not part of the public API in order to do what you need, please contact
125
+ me so I can rectify the situation!
126
+
127
+ == Dependencies
128
+
129
+ 1. RSolr
130
+ 2. Daemons
131
+ 3. OptiFlag
132
+ 4. Java
133
+
134
+ Sunspot has been tested with MRI 1.8.6 and 1.8.7, REE 1.8.6, YARV 1.9.1, and
135
+ JRuby 1.2.0
136
+
137
+ == Bugs
138
+
139
+ Please submit bug reports to
140
+ http://outoftime.lighthouseapp.com/projects/20339-sunspot
141
+
142
+ == Further Reading
143
+
144
+ * Sunspot Discussion: http://groups.google.com/group/ruby-sunspot
145
+ * IRC: #sunspot-ruby @ Freenode
146
+ * Posts about Sunspot from my tumblog: http://outofti.me/tagged/sunspot
147
+ * Read about it on Linux Magazine: http://www.linux-mag.com/id/7341
148
+
149
+ == Contributors
150
+
151
+ * Mat Brown (mat@patch.com)
152
+ * Peer Allan (peer.allan@gmail.com)
153
+ * Dmitriy Dzema (dima@dzema.name)
154
+ * Benjamin Krause (bk@benjaminkrause.com)
155
+ * Brandon Keepers (brandon@opensoul.org)
156
+
157
+ == License
158
+
159
+ Sunspot is distributed under the MIT License, copyright (c) 2008-2009 Mat Brown
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ ENV['RUBYOPT'] = '-W1'
2
+
3
+ task :environment do
4
+ require File.dirname(__FILE__) + '/lib/sunspot'
5
+ end
6
+
7
+ Dir['tasks/**/*.rake'].each { |t| load t }
8
+
9
+ task :default => 'spec:api'
data/TODO ADDED
@@ -0,0 +1,11 @@
1
+ === 0.10 ===
2
+ * Pass highlight fields into #highlight varargs
3
+ * Allow boosting without field constraints
4
+ * Allow coordinates to be specified with block in setup
5
+ === 0.11 ===
6
+ * Support all operations in batches. Make it smart.
7
+ * Don't use more than one commits when one is equivalent
8
+ * Preserve adds/deletes that are done after last commit
9
+ * Don't do adds and deletes for the same document out of order
10
+ * Don't do more than one add for the same document
11
+ * Do use as few requests as possible within those constraints
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 9
3
+ :patch: 7
4
+ :major: 0
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ using_gems = false
4
+ begin
5
+ require 'fileutils'
6
+ require 'optiflag'
7
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'sunspot', 'schema')
8
+ rescue LoadError => e
9
+ if using_gems
10
+ raise(e)
11
+ else
12
+ using_gems = true
13
+ require 'rubygems'
14
+ retry
15
+ end
16
+ end
17
+
18
+ module ConfigureSolrFlags extend OptiFlagSet
19
+ optional_flag 'tokenizer'
20
+ optional_flag 'extra_filters'
21
+ optional_flag 'dir'
22
+ and_process!
23
+ end
24
+
25
+ solr_directory = ARGV.flags.dir || FileUtils.pwd
26
+ conf_directory = File.join(solr_directory, 'conf')
27
+ schema_file = File.join(conf_directory, 'schema.xml')
28
+ FileUtils.mkdir_p(conf_directory)
29
+
30
+ schema = Sunspot::Schema.new
31
+ schema.tokenizer = ARGV.flags.tokenizer if ARGV.flags.tokenizer
32
+ if ARGV.flags.extra_filters
33
+ for filter in ARGV.flags.extra_filters.split(',')
34
+ schema.add_filter(filter)
35
+ end
36
+ end
37
+
38
+ if File.exist?(schema_file)
39
+ backup_file = File.join(conf_directory, "schema-#{File.mtime(schema_file).strftime('%Y%m%d%H%M%S')}.xml")
40
+ STDERR.puts("Backing up current schema file to #{File.expand_path(backup_file)}")
41
+ FileUtils.mv(schema_file, backup_file)
42
+ end
43
+
44
+ File.open(File.join(conf_directory, 'schema.xml'), 'w') do |file|
45
+ file << schema.to_xml
46
+ end
data/bin/sunspot-solr ADDED
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env ruby
2
+ using_gems = false
3
+ begin
4
+ require 'fileutils'
5
+ require 'tempfile'
6
+ require 'tmpdir'
7
+ require 'daemons'
8
+ require 'optiflag'
9
+ rescue LoadError => e
10
+ if using_gems
11
+ raise(e)
12
+ else
13
+ using_gems = true
14
+ require 'rubygems'
15
+ retry
16
+ end
17
+ end
18
+
19
+ working_directory = FileUtils.pwd
20
+ solr_home = File.join(File.dirname(__FILE__), '..', 'solr')
21
+
22
+ module SolrFlags extend OptiFlagSet
23
+ optional_flag 'p' do
24
+ description 'Port on which to run Solr (default 8983)'
25
+ long_form 'port'
26
+ end
27
+
28
+ optional_flag 'd' do
29
+ description 'Solr data directory'
30
+ end
31
+
32
+ optional_flag 's' do
33
+ description 'Solr home (should contain conf/ directory)'
34
+ end
35
+
36
+ optional_flag 'pd' do
37
+ long_form 'pid-dir'
38
+ description 'Directory for pid files'
39
+ end
40
+
41
+ optional_flag 'l' do
42
+ long_form 'log-level'
43
+ description 'log level to pass to solr'
44
+ end
45
+
46
+ optional_flag 'lf' do
47
+ long_form 'log-file'
48
+ description 'location of the log files'
49
+ end
50
+
51
+ and_process!
52
+ end
53
+
54
+ port = ARGV.flags.p || '8983'
55
+ data_dir = File.expand_path(ARGV.flags.d || File.join(Dir.tmpdir, 'solr_data'))
56
+ home = File.expand_path(ARGV.flags.s) if ARGV.flags.s
57
+ pid_dir = File.expand_path(ARGV.flags.pd || working_directory)
58
+ log_file = ARGV.flags.lf || nil
59
+ log_level = ARGV.flags.l || 'OFF'
60
+
61
+ options = { :dir_mode => :normal, :dir => pid_dir }
62
+
63
+ def logging_properties( log_file, log_level )
64
+ temp_file = Tempfile.new 'logging.properties'
65
+ temp_file << ".level = #{log_level}\n"
66
+ temp_file << "handlers = java.util.logging.FileHandler\n"
67
+ temp_file << "java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter\n"
68
+ temp_file << "java.util.logging.FileHandler.pattern = #{log_file}\n"
69
+ temp_file.flush
70
+ temp_file.path
71
+ end
72
+
73
+ Daemons.run_proc('sunspot-solr', options) do
74
+ FileUtils.cd(working_directory) do
75
+ FileUtils.cd(solr_home) do
76
+ args = ['java']
77
+ args << "-Djetty.port=#{port}" if port
78
+ args << "-Dsolr.data.dir=#{data_dir}" if data_dir
79
+ args << "-Dsolr.solr.home=#{home}" if home
80
+ args << "-Djava.util.logging.config.file=#{logging_properties(log_file, log_level)}" if log_file and log_file != 'OFF'
81
+ args << '-jar' << 'start.jar'
82
+ STDERR.puts(args * ' ')
83
+ Kernel.exec(*args)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,40 @@
1
+ module LightConfig
2
+ class Configuration
3
+ def initialize(&block)
4
+ @properties = {}
5
+ ::LightConfig::Builder.new(self).instance_eval(&block)
6
+ singleton = (class <<self; self; end)
7
+ @properties.keys.each do |property|
8
+ singleton.module_eval do
9
+ define_method property do
10
+ @properties[property]
11
+ end
12
+
13
+ define_method "#{property}=" do |value|
14
+ @properties[property] = value
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ class Builder
22
+ def initialize(configuration)
23
+ @configuration = configuration
24
+ end
25
+
26
+ def method_missing(method, *args, &block)
27
+ raise ArgumentError("wrong number of arguments(#{args.length} for 1)") unless args.length < 2
28
+ value = if block then ::LightConfig::Configuration.new(&block)
29
+ else args.first
30
+ end
31
+ @configuration.instance_variable_get(:@properties)[method] = value
32
+ end
33
+ end
34
+
35
+ class <<self
36
+ def build(&block)
37
+ LightConfig::Configuration.new(&block)
38
+ end
39
+ end
40
+ end