acts_as_solr 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Rakefile +12 -0
- data/VERSION +1 -1
- data/acts_as_solr.gemspec +6 -5
- data/lib/acts_methods.rb +6 -0
- data/lib/class_methods.rb +1 -0
- data/lib/instance_methods.rb +8 -0
- data/lib/parser_methods.rb +11 -7
- data/lib/solr/request/standard.rb +2 -1
- data/solr/solr/conf/schema.xml +18 -15
- metadata +3 -3
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
|
7
|
+
Dir["#{File.dirname(__FILE__)}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
|
8
|
+
|
9
|
+
desc "Default Task"
|
10
|
+
task :default => [:test]
|
11
|
+
|
12
|
+
desc "Runs the unit tests"
|
13
|
+
task :test => "test:unit"
|
14
|
+
|
15
|
+
|
4
16
|
begin
|
5
17
|
require 'jeweler'
|
6
18
|
Jeweler::Tasks.new do |gem|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.1
|
data/acts_as_solr.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{acts_as_solr}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.1.1"
|
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-
|
12
|
+
s.date = %q{2009-12-09}
|
13
13
|
s.description = %q{Acts As Solr}
|
14
14
|
s.email = %q{kyle@onemorecloud.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -184,7 +184,7 @@ Gem::Specification.new do |s|
|
|
184
184
|
s.homepage = %q{http://github.com/onemorecloud/acts_as_solr}
|
185
185
|
s.rdoc_options = ["--charset=UTF-8"]
|
186
186
|
s.require_paths = ["lib"]
|
187
|
-
s.rubygems_version = %q{1.3.
|
187
|
+
s.rubygems_version = %q{1.3.5}
|
188
188
|
s.summary = %q{Solr integration for rails}
|
189
189
|
s.test_files = [
|
190
190
|
"test/db/connections/mysql/connection.rb",
|
@@ -235,3 +235,4 @@ Gem::Specification.new do |s|
|
|
235
235
|
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
236
236
|
end
|
237
237
|
end
|
238
|
+
|
data/lib/acts_methods.rb
CHANGED
@@ -210,6 +210,12 @@ module ActsAsSolr #:nodoc:
|
|
210
210
|
alias_method_chain :method_missing, :solr_magic
|
211
211
|
@already_solr_magic = true
|
212
212
|
end
|
213
|
+
rescue ActiveRecord::StatementInvalid
|
214
|
+
@acts_as_solr_needs_reload = true
|
215
|
+
end
|
216
|
+
|
217
|
+
def acts_as_solr_needs_reload?
|
218
|
+
@acts_as_solr_needs_reload
|
213
219
|
end
|
214
220
|
|
215
221
|
private
|
data/lib/class_methods.rb
CHANGED
data/lib/instance_methods.rb
CHANGED
@@ -24,6 +24,10 @@ module ActsAsSolr #:nodoc:
|
|
24
24
|
|
25
25
|
# saves to the Solr index
|
26
26
|
def solr_save
|
27
|
+
if self.class.respond_to?(:acts_as_solr_needs_reload?) && self.class.acts_as_solr_needs_reload?
|
28
|
+
self.class.acts_as_solr
|
29
|
+
end
|
30
|
+
|
27
31
|
return true if indexing_disabled?
|
28
32
|
if evaluate_condition(:if, self)
|
29
33
|
logger.debug "solr_save: #{self.class.name} : #{record_id(self)}"
|
@@ -33,6 +37,8 @@ module ActsAsSolr #:nodoc:
|
|
33
37
|
else
|
34
38
|
solr_destroy
|
35
39
|
end
|
40
|
+
rescue ConnectionError
|
41
|
+
false
|
36
42
|
end
|
37
43
|
|
38
44
|
def indexing_disabled?
|
@@ -46,6 +52,8 @@ module ActsAsSolr #:nodoc:
|
|
46
52
|
solr_delete solr_id
|
47
53
|
solr_commit if configuration[:auto_commit]
|
48
54
|
true
|
55
|
+
rescue ConnectionError
|
56
|
+
false
|
49
57
|
end
|
50
58
|
|
51
59
|
# convert instance to Solr document
|
data/lib/parser_methods.rb
CHANGED
@@ -4,6 +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
|
+
|
7
8
|
valid_options = [:offset, :limit, :facets, :models, :results_format, :order, :scores, :operator, :include, :lazy, :highlight]
|
8
9
|
query_options = {}
|
9
10
|
|
@@ -87,11 +88,14 @@ module ActsAsSolr #:nodoc:
|
|
87
88
|
order = options[:order].split(/\s*,\s*/).collect{|e| e.gsub(/\s+/,'_t ').gsub(/\bscore_t\b/, 'score') }.join(',') if options[:order]
|
88
89
|
query_options[:query] = replace_types([query])[0] # TODO adjust replace_types to work with String or Array
|
89
90
|
|
90
|
-
if options[:order]
|
91
|
-
|
92
|
-
|
91
|
+
if options[:order].is_a?(String)
|
92
|
+
string = replace_types([order], false)[0]
|
93
|
+
field, direction = string.split(/\s+/)
|
94
|
+
direction = direction.to_s =~ /asc/i ? :ascending : :descending
|
95
|
+
query_options[:sort] = [{field => direction}]
|
96
|
+
elsif options[:order]
|
97
|
+
query_options[:sort] = options[:order]
|
93
98
|
end
|
94
|
-
|
95
99
|
ActsAsSolr::Post.execute(Solr::Request::Standard.new(query_options))
|
96
100
|
rescue
|
97
101
|
raise "There was a problem executing your search: #{$!} in #{$!.backtrace.first}"
|
@@ -164,13 +168,13 @@ module ActsAsSolr #:nodoc:
|
|
164
168
|
|
165
169
|
# Reorders the instances keeping the order returned from Solr
|
166
170
|
def reorder(things, ids)
|
167
|
-
ordered_things = Array.new(things.size)
|
168
|
-
raise "Out of sync! Found #{ids.size} items in index, but only #{things.size} were found in database!" unless things.size == ids.size
|
171
|
+
ordered_things = Array.new([things.size, ids.size].max)
|
172
|
+
# raise "Out of sync! Found #{ids.size} items in index, but only #{things.size} were found in database!" unless things.size == ids.size
|
169
173
|
things.each do |thing|
|
170
174
|
position = ids.index(thing.id)
|
171
175
|
ordered_things[position] = thing
|
172
176
|
end
|
173
|
-
ordered_things
|
177
|
+
ordered_things.compact
|
174
178
|
end
|
175
179
|
|
176
180
|
# Replaces the field types based on the types (if any) specified
|
@@ -50,7 +50,8 @@ class Solr::Request::Standard < Solr::Request::Select
|
|
50
50
|
key = sort.keys[0]
|
51
51
|
"#{key.to_s} #{sort[key] == :descending ? 'desc' : 'asc'}"
|
52
52
|
end.join(',') if @params[:sort]
|
53
|
-
hash[:q] =
|
53
|
+
hash[:q] = @params[:query]
|
54
|
+
hash[:sort] = sort if sort
|
54
55
|
hash["q.op"] = @params[:operator]
|
55
56
|
hash[:df] = @params[:default_field]
|
56
57
|
|
data/solr/solr/conf/schema.xml
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8" ?>
|
2
|
+
<!--META:NAME acts_as_solr for Ruby on Rails-->
|
2
3
|
<!--
|
3
4
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
4
5
|
contributor license agreements. See the NOTICE file distributed with
|
@@ -50,7 +51,8 @@
|
|
50
51
|
|
51
52
|
<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
|
52
53
|
<analyzer type="index">
|
53
|
-
<tokenizer class="solr.
|
54
|
+
<tokenizer class="solr.ChineseTokenizerFactory"/>
|
55
|
+
<filter class="solr.ChineseFilterFactory" />
|
54
56
|
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
|
55
57
|
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0"/>
|
56
58
|
<filter class="solr.LowerCaseFilterFactory"/>
|
@@ -58,7 +60,8 @@
|
|
58
60
|
<filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
|
59
61
|
</analyzer>
|
60
62
|
<analyzer type="query">
|
61
|
-
<tokenizer class="solr.
|
63
|
+
<tokenizer class="solr.ChineseTokenizerFactory"/>
|
64
|
+
<filter class="solr.ChineseFilterFactory" />
|
62
65
|
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
|
63
66
|
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
|
64
67
|
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0"/>
|
@@ -100,19 +103,19 @@
|
|
100
103
|
<field name="id" type="string" indexed="true" stored="true" required="true" />
|
101
104
|
<field name="pk_i" type="integer" indexed="true" stored="true"/>
|
102
105
|
<field name="pk_s" type="string" indexed="true" stored="true"/>
|
103
|
-
<field name="text" type="text" indexed="true" stored="
|
104
|
-
|
105
|
-
<dynamicField name="*_i" type="integer" indexed="true" stored="
|
106
|
-
<dynamicField name="*_t" type="text" indexed="true" stored="
|
107
|
-
<dynamicField name="*_f" type="float" indexed="true" stored="
|
108
|
-
<dynamicField name="*_b" type="boolean" indexed="true" stored="
|
109
|
-
<dynamicField name="*_d" type="date" indexed="true" stored="
|
110
|
-
<dynamicField name="*_s" type="string" indexed="true" stored="
|
111
|
-
<dynamicField name="*_ri" type="sint" indexed="true" stored="
|
112
|
-
<dynamicField name="*_rf" type="sfloat" indexed="true" stored="
|
113
|
-
<dynamicField name="*_facet" type="string" indexed="true" stored="
|
114
|
-
<dynamicField name="*_s_mv" type="string" indexed="true" stored="
|
115
|
-
<dynamicField name="*_zh_text" type="text_zh" indexed="true" stored="
|
106
|
+
<field name="text" type="text" indexed="true" stored="true" multiValued="true"/>
|
107
|
+
|
108
|
+
<dynamicField name="*_i" type="integer" indexed="true" stored="true"/>
|
109
|
+
<dynamicField name="*_t" type="text" indexed="true" stored="true"/>
|
110
|
+
<dynamicField name="*_f" type="float" indexed="true" stored="true"/>
|
111
|
+
<dynamicField name="*_b" type="boolean" indexed="true" stored="true"/>
|
112
|
+
<dynamicField name="*_d" type="date" indexed="true" stored="true"/>
|
113
|
+
<dynamicField name="*_s" type="string" indexed="true" stored="true"/>
|
114
|
+
<dynamicField name="*_ri" type="sint" indexed="true" stored="true"/>
|
115
|
+
<dynamicField name="*_rf" type="sfloat" indexed="true" stored="true"/>
|
116
|
+
<dynamicField name="*_facet" type="string" indexed="true" stored="true"/>
|
117
|
+
<dynamicField name="*_s_mv" type="string" indexed="true" stored="true" multiValued="true"/>
|
118
|
+
<dynamicField name="*_zh_text" type="text_zh" indexed="true" stored="true" multiValued="true"/>
|
116
119
|
<dynamicField name="*_display" type="text" indexed="false" stored="true" multiValued="true"/>
|
117
120
|
</fields>
|
118
121
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_solr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
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-
|
12
|
+
date: 2009-12-09 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
219
|
requirements: []
|
220
220
|
|
221
221
|
rubyforge_project:
|
222
|
-
rubygems_version: 1.3.
|
222
|
+
rubygems_version: 1.3.5
|
223
223
|
signing_key:
|
224
224
|
specification_version: 3
|
225
225
|
summary: Solr integration for rails
|