onemorecloud-websolr-rails 1.1.1 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/config/solr_environment.rb +22 -22
- data/generate_rdoc.sh +11 -11
- data/lib/acts_as_solr.rb +11 -7
- data/lib/acts_methods.rb +2 -0
- data/lib/instance_methods.rb +14 -0
- data/lib/parser_methods.rb +32 -3
- data/lib/search_results.rb +4 -0
- data/lib/solr/response/standard.rb +4 -0
- data/lib/tasks/solr.rake +50 -50
- data/lib/websolr_rails/tasks.rb +1 -1
- data/lib/will_paginate_support.rb +12 -0
- data/websolr-rails.gemspec +3 -2
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.3
|
data/config/solr_environment.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
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
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
#!/bin/sh
|
2
|
-
|
3
|
-
|
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
|
-
|
9
|
-
mv /tmp/websolr-rails-rdoc/* .
|
10
|
-
git add .
|
11
|
-
git add -u
|
12
|
-
git commit -m "updating rdoc"
|
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
13
|
git push origin gh-pages
|
data/lib/acts_as_solr.rb
CHANGED
@@ -31,18 +31,22 @@ require File.dirname(__FILE__) + '/common_methods'
|
|
31
31
|
require File.dirname(__FILE__) + '/deprecation'
|
32
32
|
require File.dirname(__FILE__) + '/search_results'
|
33
33
|
require File.dirname(__FILE__) + '/lazy_document'
|
34
|
+
require File.dirname(__FILE__) + '/will_paginate_support'
|
34
35
|
module ActsAsSolr
|
35
36
|
|
36
37
|
class Post
|
37
38
|
def self.execute(request)
|
38
39
|
begin
|
39
|
-
if File.exists?(RAILS_ROOT+'/config/solr.yml')
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
else
|
45
|
-
|
40
|
+
# if File.exists?(RAILS_ROOT+'/config/solr.yml')
|
41
|
+
# config = YAML::load_file(RAILS_ROOT+'/config/solr.yml')
|
42
|
+
# url = config[RAILS_ENV]['url']
|
43
|
+
# # for backwards compatibility
|
44
|
+
# url ||= "http://#{config[RAILS_ENV]['host']}:#{config[RAILS_ENV]['port']}/#{config[RAILS_ENV]['servlet_path']}"
|
45
|
+
# else
|
46
|
+
# url = 'http://localhost:8982/solr'
|
47
|
+
# end
|
48
|
+
unless url = ENV["WEBSOLR_URL"]
|
49
|
+
raise "WEBSOLR_URL was not defined. Have you run websolr configure?"
|
46
50
|
end
|
47
51
|
connection = Solr::Connection.new(url)
|
48
52
|
return connection.send(request)
|
data/lib/acts_methods.rb
CHANGED
data/lib/instance_methods.rb
CHANGED
@@ -6,6 +6,20 @@ module ActsAsSolr #:nodoc:
|
|
6
6
|
def solr_id
|
7
7
|
"#{self.class.name}:#{record_id(self)}"
|
8
8
|
end
|
9
|
+
|
10
|
+
def init_solr(data)
|
11
|
+
@solr_data = data
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing_with_solr_magic(method, *a, &b)
|
15
|
+
if method.to_s =~ /^highlighted_(.*)$/ && a.length == 0
|
16
|
+
original_field = $1
|
17
|
+
@solr_data && @solr_data[:highlights] && @solr_data[:highlights][id] &&
|
18
|
+
@solr_data[:highlights][id][original_field].join(" ") || send(original_field)
|
19
|
+
else
|
20
|
+
method_missing_without_solr_magic(method, *a, &b)
|
21
|
+
end
|
22
|
+
end
|
9
23
|
|
10
24
|
# saves to the Solr index
|
11
25
|
def solr_save
|
data/lib/parser_methods.rb
CHANGED
@@ -4,7 +4,7 @@ module ActsAsSolr #:nodoc:
|
|
4
4
|
|
5
5
|
# Method used by mostly all the ClassMethods when doing a search
|
6
6
|
def parse_query(query=nil, options={}, models=nil)
|
7
|
-
valid_options = [:offset, :limit, :facets, :models, :results_format, :order, :scores, :operator, :include, :lazy]
|
7
|
+
valid_options = [:offset, :limit, :facets, :models, :results_format, :order, :scores, :operator, :include, :lazy, :highlight]
|
8
8
|
query_options = {}
|
9
9
|
|
10
10
|
return nil if (query.nil? || query.strip == '')
|
@@ -15,6 +15,20 @@ module ActsAsSolr #:nodoc:
|
|
15
15
|
query_options[:start] = options[:offset]
|
16
16
|
query_options[:rows] = options[:limit]
|
17
17
|
query_options[:operator] = options[:operator]
|
18
|
+
|
19
|
+
if options[:highlight] == true
|
20
|
+
options[:highlight] = {:fields => "*"}
|
21
|
+
end
|
22
|
+
|
23
|
+
if options[:highlight]
|
24
|
+
query_options[:highlighting] = {}
|
25
|
+
query_options[:highlighting][:field_list] = []
|
26
|
+
query_options[:highlighting][:field_list] << options[:highlight][:fields].collect {|k| "#{k}_t"} if options[:highlight][:fields]
|
27
|
+
query_options[:highlighting][:require_field_match] = options[:highlight][:require_field_match] if options[:highlight][:require_field_match]
|
28
|
+
query_options[:highlighting][:max_snippets] = options[:highlight][:max_snippets] if options[:highlight][:max_snippets]
|
29
|
+
query_options[:highlighting][:prefix] = options[:highlight][:prefix] if options[:highlight][:prefix]
|
30
|
+
query_options[:highlighting][:suffix] = options[:highlight][:suffix] if options[:highlight][:suffix]
|
31
|
+
end
|
18
32
|
|
19
33
|
# first steps on the facet parameter processing
|
20
34
|
if options[:facets]
|
@@ -29,7 +43,6 @@ module ActsAsSolr #:nodoc:
|
|
29
43
|
query_options[:filter_queries] = replace_types([*options[:facets][:browse]].collect{|k| "#{k.sub!(/ *: */,"_facet:")}"}) if options[:facets][:browse]
|
30
44
|
query_options[:facets][:queries] = replace_types(options[:facets][:query].collect{|k| "#{k.sub!(/ *: */,"_t:")}"}) if options[:facets][:query]
|
31
45
|
|
32
|
-
|
33
46
|
if options[:facets][:dates]
|
34
47
|
query_options[:date_facets] = {}
|
35
48
|
# if options[:facets][:dates][:fields] exists then :start, :end, and :gap must be there
|
@@ -112,9 +125,25 @@ module ActsAsSolr #:nodoc:
|
|
112
125
|
|
113
126
|
add_scores(result, solr_data) if configuration[:format] == :objects && options[:scores]
|
114
127
|
|
128
|
+
highlighted = {}
|
129
|
+
solr_data.highlighting.map do |x,y|
|
130
|
+
e={}
|
131
|
+
y1=y.map{|x1,y1| e[x1.gsub(/_[^_]*/,"")]=y1} unless y.nil?
|
132
|
+
highlighted[x.gsub(/[^:]*:/,"").to_i]=e
|
133
|
+
end unless solr_data.highlighting.nil?
|
134
|
+
|
115
135
|
results.update(:facets => solr_data.data['facet_counts']) if options[:facets]
|
116
136
|
results.update({:docs => result, :total => solr_data.total_hits, :max_score => solr_data.max_score, :query_time => solr_data.data['responseHeader']['QTime']})
|
117
|
-
|
137
|
+
results.update({:highlights=>highlighted})
|
138
|
+
|
139
|
+
|
140
|
+
sr = SearchResults.new(results)
|
141
|
+
|
142
|
+
sr.records.each do |model|
|
143
|
+
model.init_solr(results)
|
144
|
+
end
|
145
|
+
|
146
|
+
sr
|
118
147
|
end
|
119
148
|
|
120
149
|
|
data/lib/search_results.rb
CHANGED
@@ -51,6 +51,10 @@ class Solr::Response::Standard < Solr::Response::Ruby
|
|
51
51
|
@data['highlighting'][id.to_s][field.to_s] rescue nil
|
52
52
|
end
|
53
53
|
|
54
|
+
def highlighting
|
55
|
+
@data['highlighting']
|
56
|
+
end
|
57
|
+
|
54
58
|
# supports enumeration of hits
|
55
59
|
# TODO revisit - should this iterate through *all* hits by re-requesting more?
|
56
60
|
def each
|
data/lib/tasks/solr.rake
CHANGED
@@ -5,58 +5,58 @@ require 'active_record'
|
|
5
5
|
|
6
6
|
namespace :solr do
|
7
7
|
|
8
|
-
desc 'Starts Solr. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.'
|
9
|
-
task :start do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
8
|
+
# desc 'Starts Solr. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.'
|
9
|
+
# task :start do
|
10
|
+
# require "#{File.dirname(__FILE__)}/../../config/solr_environment.rb"
|
11
|
+
# begin
|
12
|
+
# n = Net::HTTP.new('127.0.0.1', SOLR_PORT)
|
13
|
+
# n.request_head('/').value
|
14
|
+
#
|
15
|
+
# rescue Net::HTTPServerException #responding
|
16
|
+
# puts "Port #{SOLR_PORT} in use" and return
|
17
|
+
#
|
18
|
+
# rescue Errno::ECONNREFUSED #not responding
|
19
|
+
# Dir.chdir(SOLR_PATH) do
|
20
|
+
# pid = fork do
|
21
|
+
# #STDERR.close
|
22
|
+
# exec "java #{SOLR_JVM_OPTIONS} -Dsolr.data.dir=#{SOLR_DATA_PATH} -Djetty.logs=#{SOLR_LOGS_PATH} -Djetty.port=#{SOLR_PORT} -jar start.jar"
|
23
|
+
# end
|
24
|
+
# sleep(5)
|
25
|
+
# File.open("#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid", "w"){ |f| f << pid}
|
26
|
+
# puts "#{ENV['RAILS_ENV']} Solr started successfully on #{SOLR_PORT}, pid: #{pid}."
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
# end
|
30
30
|
|
31
|
-
desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.'
|
32
|
-
task :stop do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
31
|
+
# desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.'
|
32
|
+
# task :stop do
|
33
|
+
# require "#{File.dirname(__FILE__)}/../../config/solr_environment.rb"
|
34
|
+
# fork do
|
35
|
+
# file_path = "#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid"
|
36
|
+
# if File.exists?(file_path)
|
37
|
+
# File.open(file_path, "r") do |f|
|
38
|
+
# pid = f.readline
|
39
|
+
# Process.kill('TERM', pid.to_i)
|
40
|
+
# end
|
41
|
+
# File.unlink(file_path)
|
42
|
+
# Rake::Task["solr:destroy_index"].invoke if ENV['RAILS_ENV'] == 'test'
|
43
|
+
# puts "Solr shutdown successfully."
|
44
|
+
# else
|
45
|
+
# puts "PID file not found at #{file_path}. Either Solr is not running or no PID file was written."
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
# end
|
49
49
|
|
50
|
-
desc 'Remove Solr index'
|
51
|
-
task :destroy_index do
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
50
|
+
# desc 'Remove Solr index'
|
51
|
+
# task :destroy_index do
|
52
|
+
# require "#{File.dirname(__FILE__)}/../../config/solr_environment.rb"
|
53
|
+
# raise "In production mode. I'm not going to delete the index, sorry." if ENV['RAILS_ENV'] == "production"
|
54
|
+
# if File.exists?("#{SOLR_DATA_PATH}")
|
55
|
+
# Dir["#{SOLR_DATA_PATH}/index/*"].each{|f| File.unlink(f)}
|
56
|
+
# Dir.rmdir("#{SOLR_DATA_PATH}/index")
|
57
|
+
# puts "Index files removed under " + ENV['RAILS_ENV'] + " environment"
|
58
|
+
# end
|
59
|
+
# end
|
60
60
|
|
61
61
|
# this task is by Henrik Nyh
|
62
62
|
# http://henrik.nyh.se/2007/06/rake-task-to-reindex-models-for-acts_as_solr
|
data/lib/websolr_rails/tasks.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
module ActsAsSolr
|
2
|
+
module ClassMethods
|
3
|
+
def paginate_by_solr(query, options = {})
|
4
|
+
options[:total_entries] ||= count_by_solr(query)
|
5
|
+
method_missing :paginate_by_solr, query, options
|
6
|
+
end
|
7
|
+
|
8
|
+
def find_all_by_solr(*args)
|
9
|
+
find_by_solr(*args).records
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/websolr-rails.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{websolr-rails}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.3.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kyle Maxwell"]
|
12
|
-
s.date = %q{2009-08-
|
12
|
+
s.date = %q{2009-08-26}
|
13
13
|
s.default_executable = %q{websolr}
|
14
14
|
s.description = %q{acts_as_solr compatible gem for websolr}
|
15
15
|
s.email = %q{kyle@kylemaxwell.com}
|
@@ -94,6 +94,7 @@ Gem::Specification.new do |s|
|
|
94
94
|
"lib/websolr_option_parser.rb",
|
95
95
|
"lib/websolr_rails.rb",
|
96
96
|
"lib/websolr_rails/tasks.rb",
|
97
|
+
"lib/will_paginate_support.rb",
|
97
98
|
"solr/CHANGES.txt",
|
98
99
|
"solr/LICENSE.txt",
|
99
100
|
"solr/NOTICE.txt",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onemorecloud-websolr-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Maxwell
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-26 00:00:00 -07:00
|
13
13
|
default_executable: websolr
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- lib/websolr_option_parser.rb
|
108
108
|
- lib/websolr_rails.rb
|
109
109
|
- lib/websolr_rails/tasks.rb
|
110
|
+
- lib/will_paginate_support.rb
|
110
111
|
- solr/CHANGES.txt
|
111
112
|
- solr/LICENSE.txt
|
112
113
|
- solr/NOTICE.txt
|