ultrasphinx 1

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,3 @@
1
+
2
+ 1. documentation, refactoring
3
+ 0. spike
data/LICENSE ADDED
@@ -0,0 +1,184 @@
1
+ Academic Free License (AFL) v. 3.0
2
+
3
+ This Academic Free License (the "License") applies to any original work
4
+ of authorship (the "Original Work") whose owner (the "Licensor") has
5
+ placed the following licensing notice adjacent to the copyright notice
6
+ for the Original Work:
7
+
8
+ Licensed under the Academic Free License version 3.0
9
+
10
+ 1) Grant of Copyright License. Licensor grants You a worldwide,
11
+ royalty-free, non-exclusive, sublicensable license, for the duration of
12
+ the copyright, to do the following:
13
+
14
+ a) to reproduce the Original Work in copies, either alone or as part of
15
+ a collective work;
16
+
17
+ b) to translate, adapt, alter, transform, modify, or arrange the
18
+ Original Work, thereby creating derivative works ("Derivative Works")
19
+ based upon the Original Work;
20
+
21
+ c) to distribute or communicate copies of the Original Work and
22
+ Derivative Works to the public, under any license of your choice that
23
+ does not contradict the terms and conditions, including Licensor's
24
+ reserved rights and remedies, in this Academic Free License;
25
+
26
+ d) to perform the Original Work publicly; and
27
+
28
+ e) to display the Original Work publicly.
29
+
30
+ 2) Grant of Patent License. Licensor grants You a worldwide,
31
+ royalty-free, non-exclusive, sublicensable license, under patent claims
32
+ owned or controlled by the Licensor that are embodied in the Original
33
+ Work as furnished by the Licensor, for the duration of the patents, to
34
+ make, use, sell, offer for sale, have made, and import the Original Work
35
+ and Derivative Works.
36
+
37
+ 3) Grant of Source Code License. The term "Source Code" means the
38
+ preferred form of the Original Work for making modifications to it and
39
+ all available documentation describing how to modify the Original Work.
40
+ Licensor agrees to provide a machine-readable copy of the Source Code of
41
+ the Original Work along with each copy of the Original Work that
42
+ Licensor distributes. Licensor reserves the right to satisfy this
43
+ obligation by placing a machine-readable copy of the Source Code in an
44
+ information repository reasonably calculated to permit inexpensive and
45
+ convenient access by You for as long as Licensor continues to distribute
46
+ the Original Work.
47
+
48
+ 4) Exclusions From License Grant. Neither the names of Licensor, nor the
49
+ names of any contributors to the Original Work, nor any of their
50
+ trademarks or service marks, may be used to endorse or promote products
51
+ derived from this Original Work without express prior permission of the
52
+ Licensor. Except as expressly stated herein, nothing in this License
53
+ grants any license to Licensor's trademarks, copyrights, patents, trade
54
+ secrets or any other intellectual property. No patent license is granted
55
+ to make, use, sell, offer for sale, have made, or import embodiments of
56
+ any patent claims other than the licensed claims defined in Section 2.
57
+ No license is granted to the trademarks of Licensor even if such marks
58
+ are included in the Original Work. Nothing in this License shall be
59
+ interpreted to prohibit Licensor from licensing under terms different
60
+ from this License any Original Work that Licensor otherwise would have a
61
+ right to license.
62
+
63
+ 5) External Deployment. The term "External Deployment" means the use,
64
+ distribution, or communication of the Original Work or Derivative Works
65
+ in any way such that the Original Work or Derivative Works may be used
66
+ by anyone other than You, whether those works are distributed or
67
+ communicated to those persons or made available as an application
68
+ intended for use over a network. As an express condition for the grants
69
+ of license hereunder, You must treat any External Deployment by You of
70
+ the Original Work or a Derivative Work as a distribution under section
71
+ 1(c).
72
+
73
+ 6) Attribution Rights. You must retain, in the Source Code of any
74
+ Derivative Works that You create, all copyright, patent, or trademark
75
+ notices from the Source Code of the Original Work, as well as any
76
+ notices of licensing and any descriptive text identified therein as an
77
+ "Attribution Notice." You must cause the Source Code for any Derivative
78
+ Works that You create to carry a prominent Attribution Notice reasonably
79
+ calculated to inform recipients that You have modified the Original
80
+ Work.
81
+
82
+ 7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants
83
+ that the copyright in and to the Original Work and the patent rights
84
+ granted herein by Licensor are owned by the Licensor or are sublicensed
85
+ to You under the terms of this License with the permission of the
86
+ contributor(s) of those copyrights and patent rights. Except as
87
+ expressly stated in the immediately preceding sentence, the Original
88
+ Work is provided under this License on an "AS IS" BASIS and WITHOUT
89
+ WARRANTY, either express or implied, including, without limitation, the
90
+ warranties of non-infringement, merchantability or fitness for a
91
+ particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL
92
+ WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential
93
+ part of this License. No license to the Original Work is granted by this
94
+ License except under this disclaimer.
95
+
96
+ 8) Limitation of Liability. Under no circumstances and under no legal
97
+ theory, whether in tort (including negligence), contract, or otherwise,
98
+ shall the Licensor be liable to anyone for any indirect, special,
99
+ incidental, or consequential damages of any character arising as a
100
+ result of this License or the use of the Original Work including,
101
+ without limitation, damages for loss of goodwill, work stoppage,
102
+ computer failure or malfunction, or any and all other commercial damages
103
+ or losses. This limitation of liability shall not apply to the extent
104
+ applicable law prohibits such limitation.
105
+
106
+ 9) Acceptance and Termination. If, at any time, You expressly assented
107
+ to this License, that assent indicates your clear and irrevocable
108
+ acceptance of this License and all of its terms and conditions. If You
109
+ distribute or communicate copies of the Original Work or a Derivative
110
+ Work, You must make a reasonable effort under the circumstances to
111
+ obtain the express assent of recipients to the terms of this License.
112
+ This License conditions your rights to undertake the activities listed
113
+ in Section 1, including your right to create Derivative Works based upon
114
+ the Original Work, and doing so without honoring these terms and
115
+ conditions is prohibited by copyright law and international treaty.
116
+ Nothing in this License is intended to affect copyright exceptions and
117
+ limitations (including "fair use" or "fair dealing"). This License shall
118
+ terminate immediately and You may no longer exercise any of the rights
119
+ granted to You by this License upon your failure to honor the conditions
120
+ in Section 1(c).
121
+
122
+ 10) Termination for Patent Action. This License shall terminate
123
+ automatically and You may no longer exercise any of the rights granted
124
+ to You by this License as of the date You commence an action, including
125
+ a cross-claim or counterclaim, against Licensor or any licensee alleging
126
+ that the Original Work infringes a patent. This termination provision
127
+ shall not apply for an action alleging patent infringement by
128
+ combinations of the Original Work with other software or hardware.
129
+
130
+ 11) Jurisdiction, Venue and Governing Law. Any action or suit relating
131
+ to this License may be brought only in the courts of a jurisdiction
132
+ wherein the Licensor resides or in which Licensor conducts its primary
133
+ business, and under the laws of that jurisdiction excluding its
134
+ conflict-of-law provisions. The application of the United Nations
135
+ Convention on Contracts for the International Sale of Goods is expressly
136
+ excluded. Any use of the Original Work outside the scope of this License
137
+ or after its termination shall be subject to the requirements and
138
+ penalties of copyright or patent law in the appropriate jurisdiction.
139
+ This section shall survive the termination of this License.
140
+
141
+ 12) Attorneys' Fees. In any action to enforce the terms of this License
142
+ or seeking damages relating thereto, the prevailing party shall be
143
+ entitled to recover its costs and expenses, including, without
144
+ limitation, reasonable attorneys' fees and costs incurred in connection
145
+ with such action, including any appeal of such action. This section
146
+ shall survive the termination of this License.
147
+
148
+ 13) Miscellaneous. If any provision of this License is held to be
149
+ unenforceable, such provision shall be reformed only to the extent
150
+ necessary to make it enforceable.
151
+
152
+ 14) Definition of "You" in This License. "You" throughout this License,
153
+ whether in upper or lower case, means an individual or a legal entity
154
+ exercising rights under, and complying with all of the terms of, this
155
+ License. For legal entities, "You" includes any entity that controls, is
156
+ controlled by, or is under common control with you. For purposes of this
157
+ definition, "control" means (i) the power, direct or indirect, to cause
158
+ the direction or management of such entity, whether by contract or
159
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
160
+ outstanding shares, or (iii) beneficial ownership of such entity.
161
+
162
+ 15) Right to Use. You may use the Original Work in all ways not
163
+ otherwise restricted or conditioned by this License or by law, and
164
+ Licensor promises not to interfere with or be responsible for such uses
165
+ by You.
166
+
167
+ 16) Modification of This License. This License is Copyright (c) 2005
168
+ Lawrence Rosen. Permission is granted to copy, distribute, or
169
+ communicate this License without modification. Nothing in this License
170
+ permits You to modify this License as applied to the Original Work or to
171
+ Derivative Works. However, You may modify the text of this License and
172
+ copy, distribute or communicate your modified version (the "Modified
173
+ License") and apply it to other original works of authorship subject to
174
+ the following conditions: (i) You may not indicate in any way that your
175
+ Modified License is the "Academic Free License" or "AFL" and you may not
176
+ use those names in the name of your Modified License; (ii) You must
177
+ replace the notice specified in the first paragraph above with the
178
+ notice "Licensed under <insert your license name here>" or with a notice
179
+ of your own that is not confusingly similar to the notice in this
180
+ License; and (iii) You may not claim that your original works are open
181
+ source software unless your Modified License has been approved by Open
182
+ Source Initiative (OSI) and You comply with its license review and
183
+ certification process.
184
+
@@ -0,0 +1,21 @@
1
+ ./CHANGELOG
2
+ ./LICENSE
3
+ ./Manifest
4
+ ./README
5
+ ./Rakefile
6
+ ./examples/app.multi
7
+ ./examples/default.base
8
+ ./init.rb
9
+ ./lib/ultrasphinx/autoload.rb
10
+ ./lib/ultrasphinx/core_extensions.rb
11
+ ./lib/ultrasphinx/fields.rb
12
+ ./lib/ultrasphinx/is_indexed.rb
13
+ ./lib/ultrasphinx/search.rb
14
+ ./lib/ultrasphinx/spell.rb
15
+ ./lib/ultrasphinx/ultrasphinx.rb
16
+ ./lib/ultrasphinx.rb
17
+ ./tasks/ultrasphinx.rake
18
+ ./vendor/sphinx/README
19
+ ./vendor/sphinx/Rakefile
20
+ ./vendor/sphinx/init.rb
21
+ ./vendor/sphinx/lib/client.rb
data/README ADDED
@@ -0,0 +1,94 @@
1
+
2
+ Ultrasphinx
3
+
4
+ Ruby on Rails configurator and client to the Sphinx full text search engine.
5
+
6
+ == License
7
+
8
+ Copyright 2007 Cloudburst, LLC. Licensed under the AFL 3. See included LICENSE file. Portions copyright Dmytro Shteflyuk and Alexey Kovyrin, distributed under the Ruby License, and used with permission.
9
+
10
+ == Requirements
11
+
12
+ * MySQL (or Postgres, experimental)
13
+ * Sphinx 0.97
14
+
15
+ == Features
16
+
17
+ Advanced Sphinx usage:
18
+ * multi-source merging
19
+ * excerpt highlighting
20
+ * field weighting
21
+
22
+ ActiveRecord-style SQL generation:
23
+ * belongs_to and has_many includes
24
+ * field merging
25
+ * field aliasing
26
+
27
+ Good Rails integration:
28
+ * automatic memcached loads via cache_fu
29
+ * query spellcheck
30
+ * Google-style query parser
31
+ * multiple deployment environments
32
+ * comprehensive rake tasks
33
+
34
+ And some other things.
35
+
36
+ == Basic setup
37
+
38
+ Install the plugin, and also Sphinx itself (http://www.sphinxsearch.com).
39
+
40
+ Next, copy the <tt>example/default.base</tt> file to <tt>RAILS_ROOT/config/ultrasphinx/default.base</tt>.
41
+
42
+ If you need per-environment configuration, you can use <tt>RAILS_ROOT/config/ultrasphinx/development.base</tt>, etc. This file sets up the basic Sphinx and Ultrasphinx options such as ports, hosts, and index locations.
43
+
44
+ Now, in your models, use the <tt>is_indexed</tt> macro to configure a model as searchable. For example:
45
+
46
+ class Post
47
+ is_indexed :fields => ["created_at", "title", "body"]
48
+ end
49
+
50
+ For more index options, see ActiveRecord::Base .is_indexed.
51
+
52
+ == Building the index
53
+
54
+ Run:
55
+
56
+ rake ultrasphinx:configure
57
+ rake ultrasphinx:index
58
+ rake ultrasphinx:daemon:start
59
+
60
+ To rotate the index, just rerun <tt>rake ultrasphinx:index</tt>. If the search daemon is running, it will have its index rotated. Otherwise the new index will be installed but the daemon will remain stopped.
61
+
62
+ Make sure to manually stop and restart the daemon if you change the field configuration or model set. It will not reload the configuration file automatically.
63
+
64
+ == Running queries
65
+
66
+ Query the daemon as so:
67
+
68
+ @search = Ultrasphinx::Search.new(@query)
69
+ @search.run
70
+ @search.results
71
+
72
+ For more query options, including excerpt mode, see Ultrasphinx::Search.
73
+
74
+ == Spellcheck
75
+
76
+ See Ultrasphinx::Spell.
77
+
78
+ == Available Rake tasks
79
+
80
+ These rake tasks are made available to your Rails app:
81
+
82
+ <tt>ultrasphinx:configure</tt>:: Rebuild the configuration file for this particular environment.
83
+ <tt>ultrasphinx:index</tt>:: Reindex the database and send an update signal to the search daemon.
84
+ <tt>ultrasphinx:daemon:restart</tt>:: Restart the search daemon.
85
+ <tt>ultrasphinx:daemon:start</tt>:: Start the search daemon.
86
+ <tt>ultrasphinx:daemon:status</tt>:: Check if the search daemon is running.
87
+ <tt>ultrasphinx:daemon:stop</tt>:: Stop the search daemon.
88
+ <tt>ultrasphinx:spelling:build</tt>:: Rebuild the custom spelling dictionary.
89
+ <tt>ultrasphinx:bootstrap</tt>:: Bootstrap a full Sphinx environment by running configure, index, then daemon:start.
90
+
91
+ == Further resources
92
+
93
+ http://blog.evanweaver.com/pages/code#ultrasphinx
94
+ http://rubyforge.org/forum/forum.php?forum_id=14244
@@ -0,0 +1,21 @@
1
+
2
+ require 'rubygems'
3
+ require 'echoe'
4
+
5
+ Echoe.new("ultrasphinx", `cat CHANGELOG`[/^([\d\.]+)\. /, 1]) do |p|
6
+
7
+ p.name = "ultrasphinx"
8
+ p.rubyforge_name = "fauna"
9
+ p.description = p.summary = "Ruby on Rails configurator and client to the Sphinx fulltext search engine."
10
+ p.url = "http://blog.evanweaver.com/pages/code#ultrasphinx"
11
+ p.changes = `cat CHANGELOG`[/^([\d\.]+\. .*)/, 1]
12
+ p.need_tar = false
13
+ p.need_tar_gz = true
14
+
15
+ p.rdoc_pattern = /is_indexed.rb|search.rb|spell.rb|ultrasphinx.rb|README|CHANGELOG|LICENSE/
16
+ if File.exist?(template = "/Users/eweaver/p/allison/trunk/allison/allison.rb")
17
+ p.rdoc_template = template
18
+ end
19
+
20
+ end
21
+
@@ -0,0 +1,2 @@
1
+ add en_US-w_accents.multi
2
+ add custom.rws
@@ -0,0 +1,34 @@
1
+
2
+ # to put in RAILS_ROOT/config/ultrasphinx
3
+ # can be namespaced individually (development.base)
4
+
5
+ indexer
6
+ {
7
+ mem_limit = 256M
8
+ }
9
+
10
+ searchd
11
+ {
12
+ address = 0.0.0.0
13
+ port = 3312
14
+ log = /opt/local/var/db/sphinx/log/searchd.log
15
+ query_log = /opt/local/var/db/sphinx/log/query.log
16
+ read_timeout = 5
17
+ max_children = 30
18
+ pid_file = /opt/local/var/db/sphinx/log/searchd.pid
19
+ max_matches = 100000
20
+ }
21
+
22
+ ultrasphinx
23
+ {
24
+ # indexer options
25
+ path = /opt/local/var/db/sphinx/
26
+ docinfo = extern # just leave this alone
27
+ morphology = stem_en
28
+ stopwords = # /path/to/stopwords.txt
29
+ min_word_len = 1
30
+ charset_type = utf-8 # or sbcs (Single Byte Character Set)
31
+ # client options
32
+ server_host = localhost
33
+ server_port = 3312
34
+ }
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+
2
+ require 'ultrasphinx'
@@ -0,0 +1,20 @@
1
+
2
+ require "#{File.dirname(__FILE__)}/../vendor/sphinx/lib/client"
3
+
4
+ require 'ultrasphinx/core_extensions'
5
+ require 'ultrasphinx/ultrasphinx'
6
+ require 'ultrasphinx/autoload'
7
+ require 'ultrasphinx/fields'
8
+ require 'ultrasphinx/is_indexed'
9
+ require 'ultrasphinx/search'
10
+
11
+ Ultrasphinx.say(
12
+ begin
13
+ require 'raspell'
14
+ require 'ultrasphinx/spell'
15
+ "spelling support enabled"
16
+ rescue Object => e
17
+ "spelling support not available (module load raised \"#{e}\")"
18
+ end
19
+ )
20
+
@@ -0,0 +1,13 @@
1
+
2
+ require 'initializer'
3
+
4
+ class Rails::Initializer
5
+
6
+ def after_initialize_with_ultrasphinx_configuration
7
+ after_initialize_without_ultrasphinx_configuration
8
+ Ultrasphinx.load_constants
9
+ Ultrasphinx.verify_database_name
10
+ end
11
+
12
+ alias_method_chain :after_initialize, :ultrasphinx_configuration
13
+ end
@@ -0,0 +1,51 @@
1
+
2
+ require 'chronic'
3
+
4
+ class Array
5
+ def _flatten_once
6
+ self.inject([]) do |set, element|
7
+ set + Array(element)
8
+ end
9
+ end
10
+ end
11
+
12
+ class Object
13
+ def _metaclass
14
+ class << self
15
+ self
16
+ end
17
+ end
18
+ end
19
+
20
+ class String
21
+ def _to_numeric
22
+ zeroless = self.squeeze(" ").strip.sub(/^0+(\d)/, '\1')
23
+ zeroless.sub!(/(\...*?)0+$/, '\1')
24
+ if zeroless.to_i.to_s == zeroless
25
+ zeroless.to_i
26
+ elsif zeroless.to_f.to_s == zeroless
27
+ zeroless.to_f
28
+ elsif date = Chronic.parse(self)
29
+ date.to_i
30
+ else
31
+ self
32
+ end
33
+ end
34
+ end
35
+
36
+ class Hash
37
+ def _coerce_basic_types
38
+ Hash[*self.map do |key, value|
39
+ [key.to_sym,
40
+ if value.respond_to?(:to_i) && value.to_i.to_s == value
41
+ value.to_i
42
+ elsif value == ""
43
+ nil
44
+ elsif value.is_a? String
45
+ value.to_sym
46
+ else
47
+ value
48
+ end]
49
+ end._flatten_once]
50
+ end
51
+ end