websolr-rails 1.4.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -10
- data/LICENSE +17 -16
- data/README.rdoc +16 -62
- data/Rakefile +2 -60
- data/VERSION +1 -1
- data/lib/websolr-rails.rb +54 -1
- data/lib/websolr.rb +2 -1
- metadata +12 -215
- data/CHANGELOG +0 -8
- data/TESTING_THE_PLUGIN +0 -25
- data/bin/websolr +0 -10
- data/config/solr.yml +0 -15
- data/config/solr_environment.rb +0 -22
- data/generate_rdoc.sh +0 -13
- data/lib/acts_as_solr.rb +0 -65
- data/lib/acts_methods.rb +0 -281
- data/lib/class_methods.rb +0 -243
- data/lib/common_methods.rb +0 -89
- data/lib/deprecation.rb +0 -61
- data/lib/instance_methods.rb +0 -181
- data/lib/lazy_document.rb +0 -18
- data/lib/parser_methods.rb +0 -230
- data/lib/search_results.rb +0 -72
- data/lib/solr.rb +0 -21
- data/lib/solr/connection.rb +0 -190
- data/lib/solr/document.rb +0 -78
- data/lib/solr/exception.rb +0 -13
- data/lib/solr/field.rb +0 -39
- data/lib/solr/importer.rb +0 -19
- data/lib/solr/importer/array_mapper.rb +0 -26
- data/lib/solr/importer/delimited_file_source.rb +0 -38
- data/lib/solr/importer/hpricot_mapper.rb +0 -27
- data/lib/solr/importer/mapper.rb +0 -51
- data/lib/solr/importer/solr_source.rb +0 -43
- data/lib/solr/importer/xpath_mapper.rb +0 -35
- data/lib/solr/indexer.rb +0 -52
- data/lib/solr/request.rb +0 -26
- data/lib/solr/request/add_document.rb +0 -63
- data/lib/solr/request/base.rb +0 -36
- data/lib/solr/request/commit.rb +0 -31
- data/lib/solr/request/delete.rb +0 -50
- data/lib/solr/request/dismax.rb +0 -46
- data/lib/solr/request/index_info.rb +0 -22
- data/lib/solr/request/modify_document.rb +0 -51
- data/lib/solr/request/optimize.rb +0 -21
- data/lib/solr/request/ping.rb +0 -36
- data/lib/solr/request/select.rb +0 -56
- data/lib/solr/request/spellcheck.rb +0 -30
- data/lib/solr/request/standard.rb +0 -402
- data/lib/solr/request/update.rb +0 -23
- data/lib/solr/response.rb +0 -27
- data/lib/solr/response/add_document.rb +0 -17
- data/lib/solr/response/base.rb +0 -42
- data/lib/solr/response/commit.rb +0 -17
- data/lib/solr/response/delete.rb +0 -13
- data/lib/solr/response/dismax.rb +0 -8
- data/lib/solr/response/index_info.rb +0 -26
- data/lib/solr/response/modify_document.rb +0 -17
- data/lib/solr/response/optimize.rb +0 -14
- data/lib/solr/response/ping.rb +0 -28
- data/lib/solr/response/ruby.rb +0 -42
- data/lib/solr/response/select.rb +0 -17
- data/lib/solr/response/spellcheck.rb +0 -20
- data/lib/solr/response/standard.rb +0 -64
- data/lib/solr/response/xml.rb +0 -42
- data/lib/solr/solrtasks.rb +0 -27
- data/lib/solr/util.rb +0 -32
- data/lib/solr/xml.rb +0 -44
- data/lib/solr_fixtures.rb +0 -13
- data/lib/tasks/database.rake +0 -18
- data/lib/tasks/solr.rake +0 -94
- data/lib/tasks/test.rake +0 -7
- data/lib/websolr_controller.rb +0 -233
- data/lib/websolr_option_parser.rb +0 -61
- data/lib/websolr_rails.rb +0 -1
- data/lib/websolr_rails/tasks.rb +0 -4
- data/lib/will_paginate_support.rb +0 -12
- data/solr/CHANGES.txt +0 -1207
- data/solr/LICENSE.txt +0 -712
- data/solr/NOTICE.txt +0 -90
- data/solr/etc/jetty.xml +0 -205
- data/solr/etc/webdefault.xml +0 -379
- data/solr/lib/easymock.jar +0 -0
- data/solr/lib/jetty-6.1.3.jar +0 -0
- data/solr/lib/jetty-util-6.1.3.jar +0 -0
- data/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
- data/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
- data/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
- data/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
- data/solr/lib/servlet-api-2.4.jar +0 -0
- data/solr/lib/servlet-api-2.5-6.1.3.jar +0 -0
- data/solr/lib/xpp3-1.1.3.4.O.jar +0 -0
- data/solr/logs/.empty-dir-for-git +0 -0
- data/solr/solr/README.txt +0 -52
- data/solr/solr/bin/abc +0 -176
- data/solr/solr/bin/abo +0 -176
- data/solr/solr/bin/backup +0 -108
- data/solr/solr/bin/backupcleaner +0 -142
- data/solr/solr/bin/commit +0 -128
- data/solr/solr/bin/optimize +0 -129
- data/solr/solr/bin/readercycle +0 -129
- data/solr/solr/bin/rsyncd-disable +0 -77
- data/solr/solr/bin/rsyncd-enable +0 -76
- data/solr/solr/bin/rsyncd-start +0 -145
- data/solr/solr/bin/rsyncd-stop +0 -105
- data/solr/solr/bin/scripts-util +0 -83
- data/solr/solr/bin/snapcleaner +0 -148
- data/solr/solr/bin/snapinstaller +0 -168
- data/solr/solr/bin/snappuller +0 -248
- data/solr/solr/bin/snappuller-disable +0 -77
- data/solr/solr/bin/snappuller-enable +0 -77
- data/solr/solr/bin/snapshooter +0 -109
- data/solr/solr/conf/admin-extra.html +0 -31
- data/solr/solr/conf/protwords.txt +0 -21
- data/solr/solr/conf/schema.xml +0 -126
- data/solr/solr/conf/scripts.conf +0 -24
- data/solr/solr/conf/solrconfig.xml +0 -458
- data/solr/solr/conf/stopwords.txt +0 -57
- data/solr/solr/conf/synonyms.txt +0 -31
- data/solr/solr/conf/xslt/example.xsl +0 -132
- data/solr/solr/conf/xslt/example_atom.xsl +0 -63
- data/solr/solr/conf/xslt/example_rss.xsl +0 -62
- data/solr/start.jar +0 -0
- data/solr/tmp/.empty-dir-for-git +0 -0
- data/solr/webapps/solr.war +0 -0
- data/test/config/solr.yml +0 -2
- data/test/db/connections/mysql/connection.rb +0 -10
- data/test/db/connections/sqlite/connection.rb +0 -8
- data/test/db/migrate/001_create_books.rb +0 -15
- data/test/db/migrate/002_create_movies.rb +0 -12
- data/test/db/migrate/003_create_categories.rb +0 -11
- data/test/db/migrate/004_create_electronics.rb +0 -16
- data/test/db/migrate/005_create_authors.rb +0 -12
- data/test/db/migrate/006_create_postings.rb +0 -9
- data/test/db/migrate/007_create_posts.rb +0 -13
- data/test/db/migrate/008_create_gadgets.rb +0 -11
- data/test/fixtures/authors.yml +0 -9
- data/test/fixtures/books.yml +0 -13
- data/test/fixtures/categories.yml +0 -7
- data/test/fixtures/db_definitions/mysql.sql +0 -41
- data/test/fixtures/electronics.yml +0 -49
- data/test/fixtures/movies.yml +0 -9
- data/test/fixtures/postings.yml +0 -10
- data/test/functional/acts_as_solr_test.rb +0 -413
- data/test/functional/association_indexing_test.rb +0 -37
- data/test/functional/faceted_search_test.rb +0 -163
- data/test/functional/multi_solr_search_test.rb +0 -51
- data/test/models/author.rb +0 -10
- data/test/models/book.rb +0 -10
- data/test/models/category.rb +0 -8
- data/test/models/electronic.rb +0 -21
- data/test/models/gadget.rb +0 -9
- data/test/models/movie.rb +0 -17
- data/test/models/novel.rb +0 -2
- data/test/models/post.rb +0 -3
- data/test/models/posting.rb +0 -11
- data/test/test_helper.rb +0 -51
- data/test/unit/acts_methods_shoulda.rb +0 -70
- data/test/unit/class_methods_shoulda.rb +0 -88
- data/test/unit/common_methods_shoulda.rb +0 -112
- data/test/unit/instance_methods_shoulda.rb +0 -326
- data/test/unit/lazy_document_shoulda.rb +0 -35
- data/test/unit/parser_instance.rb +0 -19
- data/test/unit/parser_methods_shoulda.rb +0 -278
- data/test/unit/solr_instance.rb +0 -46
- data/test/unit/test_helper.rb +0 -14
- data/websolr-rails.gemspec +0 -243
data/CHANGELOG
DELETED
data/TESTING_THE_PLUGIN
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
acts_as_solr comes with a quick and fast unit test suite, and with a longer-running
|
2
|
-
functional test suite, the latter testing the actual integration with Solr.
|
3
|
-
|
4
|
-
The unit test suite is written using Shoulda, so make sure you have a recent version
|
5
|
-
installed.
|
6
|
-
|
7
|
-
Running `rake test` or just `rake` will run both test suites. Use `rake test:unit` to
|
8
|
-
just run the unit test suite.
|
9
|
-
|
10
|
-
== How to run functional tests for this plugin:
|
11
|
-
To run the acts_as_solr's plugin tests run the following steps:
|
12
|
-
|
13
|
-
- create a MySQL database called "actsassolr_test" (if you want to use MySQL)
|
14
|
-
|
15
|
-
- create a new Rails project, if needed (the plugin can only be tested from within a Rails project); move/checkout acts_as_solr into its vendor/plugins/, as usual
|
16
|
-
|
17
|
-
- copy vendor/plugins/acts_as_solr/config/solr.yml to config/ (the Rails config folder)
|
18
|
-
|
19
|
-
- rake solr:start RAILS_ENV=test
|
20
|
-
|
21
|
-
- rake test:functional (Accepts the following arguments: DB=sqlite|mysql and MYSQL_USER=user)
|
22
|
-
|
23
|
-
== Troubleshooting:
|
24
|
-
If for some reason the tests don't run and you get MySQL errors, make sure you edit the MYSQL_USER entry under
|
25
|
-
config/environment.rb. It's recommended to create or use a MySQL user with no password.
|
data/bin/websolr
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.dirname(__FILE__) + "/../lib/websolr_option_parser"
|
3
|
-
require File.dirname(__FILE__) + "/../lib/websolr_controller"
|
4
|
-
|
5
|
-
PWD = File.expand_path(".")
|
6
|
-
|
7
|
-
parser = WebsolrOptionParser.new
|
8
|
-
parser.parse!
|
9
|
-
controller = WebsolrController.new(parser)
|
10
|
-
controller.start
|
data/config/solr.yml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# Config file for the acts_as_solr plugin.
|
2
|
-
#
|
3
|
-
# If you change the host or port number here, make sure you update
|
4
|
-
# them in your Solr config file
|
5
|
-
|
6
|
-
development:
|
7
|
-
url: http://127.0.0.1:8982/solr
|
8
|
-
|
9
|
-
production:
|
10
|
-
url: http://127.0.0.1:8983/solr
|
11
|
-
jvm_options: -server -d64 -Xmx1024M -Xms64M
|
12
|
-
|
13
|
-
test:
|
14
|
-
url: http://127.0.0.1:8981/solr
|
15
|
-
|
data/config/solr_environment.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# ENV['RAILS_ENV'] = (ENV['RAILS_ENV'] || 'development').dup
|
2
|
-
# # RAILS_ROOT isn't defined yet, so figure it out.
|
3
|
-
# rails_root_dir = "."
|
4
|
-
# SOLR_PATH = "#{File.dirname(File.expand_path(__FILE__))}/../solr" unless defined? SOLR_PATH
|
5
|
-
#
|
6
|
-
# SOLR_LOGS_PATH = "#{rails_root_dir}/log" unless defined? SOLR_LOGS_PATH
|
7
|
-
# SOLR_PIDS_PATH = "#{rails_root_dir}/tmp/pids" unless defined? SOLR_PIDS_PATH
|
8
|
-
# SOLR_DATA_PATH = "#{rails_root_dir}/solr/#{ENV['RAILS_ENV']}" unless defined? SOLR_DATA_PATH
|
9
|
-
#
|
10
|
-
# unless defined? SOLR_PORT
|
11
|
-
# config = YAML::load_file(rails_root_dir+'/config/solr.yml')
|
12
|
-
#
|
13
|
-
# SOLR_PORT = ENV['PORT'] || URI.parse(config[ENV['RAILS_ENV']]['url']).port
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# SOLR_JVM_OPTIONS = config[ENV['RAILS_ENV']]['jvm_options'] unless defined? SOLR_JVM_OPTIONS
|
17
|
-
#
|
18
|
-
# if ENV['RAILS_ENV'] == 'test'
|
19
|
-
# DB = (ENV['DB'] ? ENV['DB'] : 'mysql') unless defined?(DB)
|
20
|
-
# MYSQL_USER = (ENV['MYSQL_USER'].nil? ? 'root' : ENV['MYSQL_USER']) unless defined? MYSQL_USER
|
21
|
-
# require File.join(File.dirname(File.expand_path(__FILE__)), '..', 'test', 'db', 'connections', DB, 'connection.rb')
|
22
|
-
# end
|
data/generate_rdoc.sh
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
rm -rf /tmp/websolr-rails*
|
3
|
-
git clone git@github.com:onemorecloud/websolr-rails.git /tmp/websolr-rails
|
4
|
-
rdoc --op /tmp/websolr-rails-rdoc --main README.rdoc README.rdoc lib
|
5
|
-
cd /tmp/websolr-rails
|
6
|
-
git checkout origin/gh-pages
|
7
|
-
git checkout -b gh-pages
|
8
|
-
rm -rf /tmp/websolr-rails/*
|
9
|
-
mv /tmp/websolr-rails-rdoc/* .
|
10
|
-
git add .
|
11
|
-
git add -u
|
12
|
-
git commit -m "updating rdoc"
|
13
|
-
git push origin gh-pages
|
data/lib/acts_as_solr.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# Copyright (c) 2006 Erik Hatcher, Thiago Jackiw
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
|
21
|
-
require 'active_record'
|
22
|
-
require 'rexml/document'
|
23
|
-
require 'net/http'
|
24
|
-
require 'yaml'
|
25
|
-
|
26
|
-
require File.dirname(__FILE__) + '/solr'
|
27
|
-
require File.dirname(__FILE__) + '/acts_methods'
|
28
|
-
require File.dirname(__FILE__) + '/class_methods'
|
29
|
-
require File.dirname(__FILE__) + '/instance_methods'
|
30
|
-
require File.dirname(__FILE__) + '/common_methods'
|
31
|
-
require File.dirname(__FILE__) + '/deprecation'
|
32
|
-
require File.dirname(__FILE__) + '/search_results'
|
33
|
-
require File.dirname(__FILE__) + '/lazy_document'
|
34
|
-
require File.dirname(__FILE__) + '/will_paginate_support'
|
35
|
-
|
36
|
-
module ActsAsSolr
|
37
|
-
class ConnectionError < RuntimeError; end
|
38
|
-
|
39
|
-
class Post
|
40
|
-
def self.execute(request)
|
41
|
-
begin
|
42
|
-
# if File.exists?(RAILS_ROOT+'/config/solr.yml')
|
43
|
-
# config = YAML::load_file(RAILS_ROOT+'/config/solr.yml')
|
44
|
-
# url = config[RAILS_ENV]['url']
|
45
|
-
# # for backwards compatibility
|
46
|
-
# url ||= "http://#{config[RAILS_ENV]['host']}:#{config[RAILS_ENV]['port']}/#{config[RAILS_ENV]['servlet_path']}"
|
47
|
-
# else
|
48
|
-
# url = 'http://localhost:8982/solr'
|
49
|
-
# end
|
50
|
-
unless url = ENV["WEBSOLR_URL"]
|
51
|
-
raise "WEBSOLR_URL was not defined. Have you run websolr configure?"
|
52
|
-
end
|
53
|
-
connection = Solr::Connection.new(url)
|
54
|
-
return connection.send(request)
|
55
|
-
rescue
|
56
|
-
raise ActsAsSolr::ConnectionError, "Couldn't connect to the Solr server at #{url}. #{$!}"
|
57
|
-
false
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
# reopen ActiveRecord and include the acts_as_solr method
|
65
|
-
ActiveRecord::Base.extend ActsAsSolr::ActsMethods
|
data/lib/acts_methods.rb
DELETED
@@ -1,281 +0,0 @@
|
|
1
|
-
module ActsAsSolr #:nodoc:
|
2
|
-
|
3
|
-
module ActsMethods
|
4
|
-
|
5
|
-
# declares a class as solr-searchable
|
6
|
-
#
|
7
|
-
# ==== options:
|
8
|
-
# fields:: This option can be used to specify only the fields you'd
|
9
|
-
# like to index. If not given, all the attributes from the
|
10
|
-
# class will be indexed. You can also use this option to
|
11
|
-
# include methods that should be indexed as fields
|
12
|
-
#
|
13
|
-
# class Movie < ActiveRecord::Base
|
14
|
-
# acts_as_solr :fields => [:name, :description, :current_time]
|
15
|
-
# def current_time
|
16
|
-
# Time.now.to_s
|
17
|
-
# end
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# Each field passed can also be a hash with the value being a field type
|
21
|
-
#
|
22
|
-
# class Electronic < ActiveRecord::Base
|
23
|
-
# acts_as_solr :fields => [{:price => :range_float}]
|
24
|
-
# def current_time
|
25
|
-
# Time.now
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# The field types accepted are:
|
30
|
-
#
|
31
|
-
# :float:: Index the field value as a float (ie.: 12.87)
|
32
|
-
# :integer:: Index the field value as an integer (ie.: 31)
|
33
|
-
# :boolean:: Index the field value as a boolean (ie.: true/false)
|
34
|
-
# :date:: Index the field value as a date (ie.: Wed Nov 15 23:13:03 PST 2006)
|
35
|
-
# :string:: Index the field value as a text string, not applying the same indexing
|
36
|
-
# filters as a regular text field
|
37
|
-
# :range_integer:: Index the field value for integer range queries (ie.:[5 TO 20])
|
38
|
-
# :range_float:: Index the field value for float range queries (ie.:[14.56 TO 19.99])
|
39
|
-
#
|
40
|
-
# Setting the field type preserves its original type when indexed
|
41
|
-
#
|
42
|
-
# The field may also be passed with a hash value containing options
|
43
|
-
#
|
44
|
-
# class Author < ActiveRecord::Base
|
45
|
-
# acts_as_solr :fields => [{:full_name => {:type => :text, :as => :name}}]
|
46
|
-
# def full_name
|
47
|
-
# self.first_name + ' ' + self.last_name
|
48
|
-
# end
|
49
|
-
# end
|
50
|
-
#
|
51
|
-
# The options accepted are:
|
52
|
-
#
|
53
|
-
# :type:: Index the field using the specified type
|
54
|
-
# :as:: Index the field using the specified field name
|
55
|
-
#
|
56
|
-
# additional_fields:: This option takes fields to be include in the index
|
57
|
-
# in addition to those derived from the database. You
|
58
|
-
# can also use this option to include custom fields
|
59
|
-
# derived from methods you define. This option will be
|
60
|
-
# ignored if the :fields option is given. It also accepts
|
61
|
-
# the same field types as the option above
|
62
|
-
#
|
63
|
-
# class Movie < ActiveRecord::Base
|
64
|
-
# acts_as_solr :additional_fields => [:current_time]
|
65
|
-
# def current_time
|
66
|
-
# Time.now.to_s
|
67
|
-
# end
|
68
|
-
# end
|
69
|
-
#
|
70
|
-
# exclude_fields:: This option taks an array of fields that should be ignored from indexing:
|
71
|
-
#
|
72
|
-
# class User < ActiveRecord::Base
|
73
|
-
# acts_as_solr :exclude_fields => [:password, :login, :credit_card_number]
|
74
|
-
# end
|
75
|
-
#
|
76
|
-
# include:: This option can be used for association indexing, which
|
77
|
-
# means you can include any :has_one, :has_many, :belongs_to
|
78
|
-
# and :has_and_belongs_to_many association to be indexed:
|
79
|
-
#
|
80
|
-
# class Category < ActiveRecord::Base
|
81
|
-
# has_many :books
|
82
|
-
# acts_as_solr :include => [:books]
|
83
|
-
# end
|
84
|
-
#
|
85
|
-
# Each association may also be specified as a hash with an option hash as a value
|
86
|
-
#
|
87
|
-
# class Book < ActiveRecord::Base
|
88
|
-
# belongs_to :author
|
89
|
-
# has_many :distribution_companies
|
90
|
-
# has_many :copyright_dates
|
91
|
-
# has_many :media_types
|
92
|
-
# acts_as_solr(
|
93
|
-
# :fields => [:name, :description],
|
94
|
-
# :include => [
|
95
|
-
# {:author => {:using => :fullname, :as => :name}},
|
96
|
-
# {:media_types => {:using => lambda{|media| type_lookup(media.id)}}}
|
97
|
-
# {:distribution_companies => {:as => :distributor, :multivalued => true}},
|
98
|
-
# {:copyright_dates => {:as => :copyright, :type => :date}}
|
99
|
-
# ]
|
100
|
-
# ]
|
101
|
-
#
|
102
|
-
# The options accepted are:
|
103
|
-
#
|
104
|
-
# :type:: Index the associated objects using the specified type
|
105
|
-
# :as:: Index the associated objects using the specified field name
|
106
|
-
# :using:: Index the associated objects using the value returned by the specified method or proc. If a method
|
107
|
-
# symbol is supplied, it will be sent to each object to look up the value to index; if a proc is
|
108
|
-
# supplied, it will be called once for each object with the object as the only argument
|
109
|
-
# :multivalued:: Index the associated objects using one field for each object rather than joining them
|
110
|
-
# all into a single field
|
111
|
-
#
|
112
|
-
# facets:: This option can be used to specify the fields you'd like to
|
113
|
-
# index as facet fields
|
114
|
-
#
|
115
|
-
# class Electronic < ActiveRecord::Base
|
116
|
-
# acts_as_solr :facets => [:category, :manufacturer]
|
117
|
-
# end
|
118
|
-
#
|
119
|
-
# boost:: You can pass a boost (float) value that will be used to boost the document and/or a field. To specify a more
|
120
|
-
# boost for the document, you can either pass a block or a symbol. The block will be called with the record
|
121
|
-
# as an argument, a symbol will result in the according method being called:
|
122
|
-
#
|
123
|
-
# class Electronic < ActiveRecord::Base
|
124
|
-
# acts_as_solr :fields => [{:price => {:boost => 5.0}}], :boost => 10.0
|
125
|
-
# end
|
126
|
-
#
|
127
|
-
# class Electronic < ActiveRecord::Base
|
128
|
-
# acts_as_solr :fields => [{:price => {:boost => 5.0}}], :boost => proc {|record| record.id + 120*37}
|
129
|
-
# end
|
130
|
-
#
|
131
|
-
# class Electronic < ActiveRecord::Base
|
132
|
-
# acts_as_solr :fields => [{:price => {:boost => :price_rating}}], :boost => 10.0
|
133
|
-
# end
|
134
|
-
#
|
135
|
-
# if:: Only indexes the record if the condition evaluated is true. The argument has to be
|
136
|
-
# either a symbol, string (to be eval'ed), proc/method, or class implementing a static
|
137
|
-
# validation method. It behaves the same way as ActiveRecord's :if option.
|
138
|
-
#
|
139
|
-
# class Electronic < ActiveRecord::Base
|
140
|
-
# acts_as_solr :if => proc{|record| record.is_active?}
|
141
|
-
# end
|
142
|
-
#
|
143
|
-
# offline:: Assumes that your using an outside mechanism to explicitly trigger indexing records, e.g. you only
|
144
|
-
# want to update your index through some asynchronous mechanism. Will accept either a boolean or a block
|
145
|
-
# that will be evaluated before actually contacting the index for saving or destroying a document. Defaults
|
146
|
-
# to false. It doesn't refer to the mechanism of an offline index in general, but just to get a centralized point
|
147
|
-
# where you can control indexing. Note: This is only enabled for saving records. acts_as_solr doesn't always like
|
148
|
-
# it, if you have a different number of results coming from the database and the index. This might be rectified in
|
149
|
-
# another patch to support lazy loading.
|
150
|
-
#
|
151
|
-
# class Electronic < ActiveRecord::Base
|
152
|
-
# acts_as_solr :offline => proc {|record| record.automatic_indexing_disabled?}
|
153
|
-
# end
|
154
|
-
#
|
155
|
-
# auto_commit:: The commit command will be sent to Solr only if its value is set to true:
|
156
|
-
#
|
157
|
-
# class Author < ActiveRecord::Base
|
158
|
-
# acts_as_solr :auto_commit => false
|
159
|
-
# end
|
160
|
-
#
|
161
|
-
def acts_as_solr(options={}, solr_options={})
|
162
|
-
|
163
|
-
extend ClassMethods
|
164
|
-
include InstanceMethods
|
165
|
-
include CommonMethods
|
166
|
-
include ParserMethods
|
167
|
-
|
168
|
-
cattr_accessor :configuration
|
169
|
-
cattr_accessor :solr_configuration
|
170
|
-
|
171
|
-
self.configuration = {
|
172
|
-
:fields => nil,
|
173
|
-
:additional_fields => nil,
|
174
|
-
:exclude_fields => [],
|
175
|
-
:auto_commit => true,
|
176
|
-
:include => nil,
|
177
|
-
:facets => nil,
|
178
|
-
:boost => nil,
|
179
|
-
:if => "true",
|
180
|
-
:offline => false
|
181
|
-
}
|
182
|
-
self.solr_configuration = {
|
183
|
-
:type_field => "type_s",
|
184
|
-
:primary_key_field => "pk_i",
|
185
|
-
:default_boost => 1.0
|
186
|
-
}
|
187
|
-
|
188
|
-
configuration.update(options) if options.is_a?(Hash)
|
189
|
-
solr_configuration.update(solr_options) if solr_options.is_a?(Hash)
|
190
|
-
Deprecation.validate_index(configuration)
|
191
|
-
|
192
|
-
configuration[:solr_fields] = {}
|
193
|
-
configuration[:solr_includes] = {}
|
194
|
-
|
195
|
-
after_save :solr_save
|
196
|
-
after_destroy :solr_destroy
|
197
|
-
|
198
|
-
if configuration[:fields].respond_to?(:each)
|
199
|
-
process_fields(configuration[:fields])
|
200
|
-
else
|
201
|
-
process_fields(self.new.attributes.keys.map { |k| k.to_sym })
|
202
|
-
process_fields(configuration[:additional_fields])
|
203
|
-
end
|
204
|
-
|
205
|
-
if configuration[:include].respond_to?(:each)
|
206
|
-
process_includes(configuration[:include])
|
207
|
-
end
|
208
|
-
|
209
|
-
alias_method_chain :method_missing, :solr_magic
|
210
|
-
end
|
211
|
-
|
212
|
-
private
|
213
|
-
def get_field_value(field)
|
214
|
-
field_name, options = determine_field_name_and_options(field)
|
215
|
-
configuration[:solr_fields][field_name] = options
|
216
|
-
|
217
|
-
define_method("#{field_name}_for_solr".to_sym) do
|
218
|
-
begin
|
219
|
-
value = self[field_name] || self.instance_variable_get("@#{field_name.to_s}".to_sym) || self.send(field_name.to_sym)
|
220
|
-
case options[:type]
|
221
|
-
# format dates properly; return nil for nil dates
|
222
|
-
when :date
|
223
|
-
value ? (value.respond_to?(:utc) ? value.utc : value).strftime("%Y-%m-%dT%H:%M:%SZ") : nil
|
224
|
-
else value
|
225
|
-
end
|
226
|
-
rescue
|
227
|
-
puts $!
|
228
|
-
logger.debug "There was a problem getting the value for the field '#{field_name}': #{$!}"
|
229
|
-
value = ''
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
def process_fields(raw_field)
|
235
|
-
if raw_field.respond_to?(:each)
|
236
|
-
raw_field.each do |field|
|
237
|
-
next if configuration[:exclude_fields].include?(field)
|
238
|
-
get_field_value(field)
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
def process_includes(includes)
|
244
|
-
if includes.respond_to?(:each)
|
245
|
-
includes.each do |assoc|
|
246
|
-
field_name, options = determine_field_name_and_options(assoc)
|
247
|
-
configuration[:solr_includes][field_name] = options
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
def determine_field_name_and_options(field)
|
253
|
-
if field.is_a?(Hash)
|
254
|
-
name = field.keys.first
|
255
|
-
options = field.values.first
|
256
|
-
if options.is_a?(Hash)
|
257
|
-
[name, {:type => type_for_field(field)}.merge(options)]
|
258
|
-
else
|
259
|
-
[name, {:type => options}]
|
260
|
-
end
|
261
|
-
else
|
262
|
-
[field, {:type => type_for_field(field)}]
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
def type_for_field(field)
|
267
|
-
if configuration[:facets] && configuration[:facets].include?(field)
|
268
|
-
:facet
|
269
|
-
elsif column = columns_hash[field.to_s]
|
270
|
-
case column.type
|
271
|
-
when :string then :text
|
272
|
-
when :datetime then :date
|
273
|
-
when :time then :date
|
274
|
-
else column.type
|
275
|
-
end
|
276
|
-
else
|
277
|
-
:text
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|
281
|
-
end
|