muck-solr 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -67,33 +67,9 @@ begin
67
67
  s.files = FileList["[A-Z]*", "{bin,generators,config,lib,solr}/**/*"] +
68
68
  FileList["test/**/*"].reject {|f| f.include?("test/log")}.reject {|f| f.include?("test/tmp")}
69
69
  end
70
+ Jeweler::RubyforgeTasks.new do |rubyforge|
71
+ rubyforge.doc_task = "rdoc"
72
+ end
70
73
  rescue LoadError
71
74
  puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
72
75
  end
73
-
74
- # rubyforge tasks
75
- begin
76
- require 'rake/contrib/sshpublisher'
77
- namespace :rubyforge do
78
-
79
- desc "Release gem and RDoc documentation to RubyForge"
80
- task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
81
-
82
- namespace :release do
83
- desc "Publish RDoc to RubyForge."
84
- task :docs => [:rdoc] do
85
- config = YAML.load(
86
- File.read(File.expand_path('~/.rubyforge/user-config.yml'))
87
- )
88
-
89
- host = "#{config['username']}@rubyforge.org"
90
- remote_dir = "/var/www/gforge-projects/muck-solr/"
91
- local_dir = 'rdoc'
92
-
93
- Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
94
- end
95
- end
96
- end
97
- rescue LoadError
98
- puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
99
- end
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 4
3
- :patch: 1
3
+ :patch: 2
4
4
  :major: 0
@@ -187,6 +187,11 @@ module ActsAsSolr #:nodoc:
187
187
  data.total_hits
188
188
  end
189
189
 
190
+ def more_like_this(uri, options={})
191
+ data = parse_mlt(uri, options)
192
+ return parse_results(data, options)
193
+ end
194
+
190
195
  # It's used to rebuild the Solr index for a specific model.
191
196
  # Book.rebuild_solr_index
192
197
  #
@@ -52,17 +52,17 @@ module ActsAsSolr #:nodoc:
52
52
 
53
53
  # Sends an add command to Solr
54
54
  def solr_add(add_xml)
55
- ActsAsSolr::Post.execute(Solr::Request::AddDocument.new(add_xml))
55
+ ActsAsSolr::Post.execute(Solr::Request::AddDocument.new(add_xml), specified_core)
56
56
  end
57
57
 
58
58
  # Sends the delete command to Solr
59
59
  def solr_delete(solr_ids)
60
- ActsAsSolr::Post.execute(Solr::Request::Delete.new(:id => solr_ids))
60
+ ActsAsSolr::Post.execute(Solr::Request::Delete.new(:id => solr_ids), specified_core)
61
61
  end
62
62
 
63
63
  # Sends the commit command to Solr
64
64
  def solr_commit
65
- ActsAsSolr::Post.execute(Solr::Request::Commit.new)
65
+ ActsAsSolr::Post.execute(Solr::Request::Commit.new, specified_core)
66
66
  end
67
67
 
68
68
  # Optimizes the Solr index. Solr says:
@@ -84,6 +84,19 @@ module ActsAsSolr #:nodoc:
84
84
  eval "object.#{object.class.primary_key}"
85
85
  end
86
86
 
87
+ private
88
+
89
+ def specified_core
90
+ if solr_configuration[:multi_core]
91
+ begin
92
+ return self.locale.to_s
93
+ rescue NoMethodError
94
+ return solr_configuration[:default_core]
95
+ end
96
+ end
97
+ nil
98
+ end
99
+
87
100
  end
88
101
 
89
102
  end
@@ -85,6 +85,32 @@ module ActsAsSolr #:nodoc:
85
85
  end
86
86
  end
87
87
 
88
+ def parse_mlt(uri, options={}, models=nil)
89
+ valid_options = [:offset, :limit, :facets, :models, :results_format, :order, :scores, :operator, :include, :lazy, :joins, :select, :core]
90
+ query_options = {}
91
+
92
+ return nil if (uri.nil? || uri.strip == '')
93
+
94
+ raise "Invalid parameters: #{(options.keys - valid_options).join(',')}" unless (options.keys - valid_options).empty?
95
+ begin
96
+
97
+ if models.nil?
98
+ # TODO: use a filter query for type, allowing Solr to cache it individually
99
+ models = "AND #{solr_type_condition}"
100
+ field_list = solr_configuration[:primary_key_field]
101
+ else
102
+ field_list = "id"
103
+ end
104
+
105
+ query_options['stream.url'] = uri
106
+ query_options[:rows] = options[:limit]
107
+
108
+ ActsAsSolr::Post.execute(Solr::Request::Mlt.new(query_options), options[:core])
109
+ rescue
110
+ raise "There was a problem executing your search\n#{query_options.inspect}\n: #{$!} in #{$!.backtrace.first}"
111
+ end
112
+ end
113
+
88
114
  def solr_type_condition
89
115
  subclasses.inject("(#{solr_configuration[:type_field]}:#{self.name}") do |condition, subclass|
90
116
  condition << " OR #{solr_configuration[:type_field]}:#{subclass.name}"
@@ -27,7 +27,7 @@ namespace :solr do
27
27
  end
28
28
  end
29
29
  sleep(5)
30
- File.open("#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid", "w"){ |f| f << pid} if windows
30
+ File.open("#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid", "w"){ |f| f << pid} unless windows
31
31
  puts "#{ENV['RAILS_ENV']} Solr started successfully on #{SOLR_PORT}, pid: #{pid}."
32
32
  end
33
33
  end
@@ -0,0 +1,71 @@
1
+ # The ASF licenses this file to You under the Apache License, Version 2.0
2
+ # (the "License"); you may not use this file except in compliance with
3
+ # the License. You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ class Solr::Request::Mlt < Solr::Request::Select
14
+
15
+ VALID_PARAMS = [:query, :sort, :default_field, :operator, :start, :rows, :shards, :date_facets,
16
+ :filter_queries, :field_list, :debug_query, :explain_other, :facets, :highlighting, :mlt, 'stream.url']
17
+
18
+ def initialize(params)
19
+ super('mlt', params)
20
+
21
+ raise "Invalid parameters: #{(params.keys - VALID_PARAMS).join(',')}" unless
22
+ (params.keys - VALID_PARAMS).empty?
23
+
24
+ raise "'stream.url' parameter required" unless params['stream.url']
25
+
26
+ @params = params.dup
27
+
28
+ @params[:field_list] ||= ["pk_i","score"]
29
+ end
30
+
31
+ def to_hash
32
+ hash = {}
33
+
34
+ # standard request param processing
35
+ sort = @params[:sort].collect do |sort|
36
+ key = sort.keys[0]
37
+ "#{key.to_s} #{sort[key] == :descending ? 'desc' : 'asc'}"
38
+ end.join(',') if @params[:sort]
39
+ #hash[:q] = sort ? "#{@params[:query]};#{sort}" : @params[:query]
40
+ hash["q.op"] = @params[:operator]
41
+ hash[:df] = @params[:default_field]
42
+
43
+ # common parameter processing
44
+ hash[:start] = @params[:start] || '0'
45
+ hash[:rows] = @params[:rows] || '10'
46
+ hash[:fq] = @params[:filter_queries]
47
+ hash[:fl] = @params[:field_list].join(',')
48
+ hash[:debugQuery] = @params[:debug_query]
49
+ hash[:explainOther] = @params[:explain_other]
50
+
51
+ hash[:qt] = 'mlt'
52
+ hash[:wt] = 'ruby'
53
+ hash['stream.url'] = @params[:query]
54
+
55
+ # hash[:mlt] = true
56
+ if @params[:mlt]
57
+ hash["mlt.count"] = @params[:mlt][:count]
58
+ hash["mlt.fl"] = @params[:mlt][:field_list].join(',')
59
+ hash["mlt.mintf"] = @params[:mlt][:min_term_freq]
60
+ hash["mlt.mindf"] = @params[:mlt][:min_doc_freq]
61
+ hash["mlt.minwl"] = @params[:mlt][:min_word_length]
62
+ hash["mlt.maxwl"] = @params[:mlt][:max_word_length]
63
+ hash["mlt.maxqt"] = @params[:mlt][:max_query_terms]
64
+ hash["mlt.maxntp"] = @params[:mlt][:max_tokens_parsed]
65
+ hash["mlt.boost"] = @params[:mlt][:boost]
66
+ end
67
+
68
+ hash.merge(super.to_hash)
69
+ end
70
+
71
+ end
data/lib/solr/request.rb CHANGED
@@ -19,6 +19,7 @@ require File.expand_path("#{File.dirname(__FILE__)}/request/commit")
19
19
  require File.expand_path("#{File.dirname(__FILE__)}/request/delete")
20
20
  require File.expand_path("#{File.dirname(__FILE__)}/request/ping")
21
21
  require File.expand_path("#{File.dirname(__FILE__)}/request/select")
22
+ require File.expand_path("#{File.dirname(__FILE__)}/request/mlt")
22
23
  require File.expand_path("#{File.dirname(__FILE__)}/request/standard")
23
24
  require File.expand_path("#{File.dirname(__FILE__)}/request/spellcheck")
24
25
  require File.expand_path("#{File.dirname(__FILE__)}/request/dismax")
@@ -0,0 +1,17 @@
1
+ # The ASF licenses this file to You under the Apache License, Version 2.0
2
+ # (the "License"); you may not use this file except in compliance with
3
+ # the License. You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ class Solr::Response::Mlt < Solr::Response::Standard
14
+ def initialize(ruby_code)
15
+ super
16
+ end
17
+ end
data/lib/solr/response.rb CHANGED
@@ -24,4 +24,5 @@ require File.expand_path("#{File.dirname(__FILE__)}/response/commit")
24
24
  require File.expand_path("#{File.dirname(__FILE__)}/response/delete")
25
25
  require File.expand_path("#{File.dirname(__FILE__)}/response/index_info")
26
26
  require File.expand_path("#{File.dirname(__FILE__)}/response/optimize")
27
- require File.expand_path("#{File.dirname(__FILE__)}/response/select")
27
+ require File.expand_path("#{File.dirname(__FILE__)}/response/select")
28
+ require File.expand_path("#{File.dirname(__FILE__)}/response/mlt")
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muck-solr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Meyer, Joel Duffin, Justin Ball
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-16 00:00:00 -06:00
12
+ date: 2009-08-12 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -67,6 +67,7 @@ files:
67
67
  - lib/solr/request/delete.rb
68
68
  - lib/solr/request/dismax.rb
69
69
  - lib/solr/request/index_info.rb
70
+ - lib/solr/request/mlt.rb
70
71
  - lib/solr/request/modify_document.rb
71
72
  - lib/solr/request/optimize.rb
72
73
  - lib/solr/request/ping.rb
@@ -81,6 +82,7 @@ files:
81
82
  - lib/solr/response/delete.rb
82
83
  - lib/solr/response/dismax.rb
83
84
  - lib/solr/response/index_info.rb
85
+ - lib/solr/response/mlt.rb
84
86
  - lib/solr/response/modify_document.rb
85
87
  - lib/solr/response/optimize.rb
86
88
  - lib/solr/response/ping.rb