solrsan 0.5.8 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -0
- data/lib/solrsan/indexer.rb +27 -30
- data/lib/solrsan/search.rb +7 -6
- data/lib/solrsan/version.rb +1 -1
- data/test/unit/search_test.rb +13 -0
- metadata +8 -8
data/README.md
CHANGED
@@ -110,6 +110,9 @@ A simple search query:
|
|
110
110
|
More searching examples can be seen in test/unit/search_test.rb
|
111
111
|
|
112
112
|
## Changelog
|
113
|
+
0.5.9
|
114
|
+
Reverted ability to custom modify solr 'type' attribute field.
|
115
|
+
|
113
116
|
0.5.8
|
114
117
|
Allow any version of activesupport > 3.1 for gem dependency.
|
115
118
|
|
data/lib/solrsan/indexer.rb
CHANGED
@@ -2,44 +2,41 @@ module Solrsan
|
|
2
2
|
module Search
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
def indexed_fields
|
11
|
-
raise "Object has have a valid as_solr_document defined" if as_solr_document.nil?
|
5
|
+
def as_solr_document
|
6
|
+
self.attributes
|
7
|
+
end
|
12
8
|
|
13
|
-
|
9
|
+
def indexed_fields
|
10
|
+
raise "Object has have a valid as_solr_document defined" if as_solr_document.nil?
|
14
11
|
|
15
|
-
|
16
|
-
converted_fields = initial_document_fields.reduce({}) do |acc, tuple|
|
17
|
-
value = tuple[1]
|
18
|
-
value = value.to_time.utc.xmlschema if value.respond_to?(:utc) || value.is_a?(Date)
|
19
|
-
acc[tuple[0]] = value
|
20
|
-
acc
|
21
|
-
end
|
22
|
-
doc.merge(converted_fields)
|
23
|
-
end
|
12
|
+
doc = {:type => self.class.solr_type, :db_id => id_value, :id => solr_id_value}
|
24
13
|
|
25
|
-
|
26
|
-
|
14
|
+
initial_document_fields = as_solr_document.reject{|k,v| k == :id || k == :_id}
|
15
|
+
converted_fields = initial_document_fields.reduce({}) do |acc, tuple|
|
16
|
+
value = tuple[1]
|
17
|
+
value = value.to_time.utc.xmlschema if value.respond_to?(:utc) || value.is_a?(Date)
|
18
|
+
acc[tuple[0]] = value
|
19
|
+
acc
|
27
20
|
end
|
21
|
+
doc.merge(converted_fields)
|
22
|
+
end
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
def solr_index(opts={:add_attributes => {:commitWithin => 10}})
|
25
|
+
self.class.solr_index(self, opts)
|
26
|
+
end
|
32
27
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
item_id
|
37
|
-
end
|
28
|
+
def destroy_index_document
|
29
|
+
self.class.destroy_index_document(self)
|
30
|
+
end
|
38
31
|
|
39
|
-
|
40
|
-
|
41
|
-
|
32
|
+
def id_value
|
33
|
+
item_id = self.attributes[:_id] || self.attributes[:id] || self.id
|
34
|
+
raise "Object must have an id attribute defined before being indexed" if item_id.nil?
|
35
|
+
item_id
|
36
|
+
end
|
42
37
|
|
38
|
+
def solr_id_value
|
39
|
+
"#{self.class.solr_type}-#{id_value.to_s}"
|
43
40
|
end
|
44
41
|
|
45
42
|
module ClassMethods
|
data/lib/solrsan/search.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
-
|
3
1
|
module Solrsan
|
4
2
|
module Search
|
5
3
|
extend ActiveSupport::Concern
|
@@ -8,8 +6,9 @@ module Solrsan
|
|
8
6
|
HL_START_TAG = "<mark>"
|
9
7
|
HL_END_TAG = "</mark>"
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
def solr_type
|
10
|
+
self.to_s.underscore
|
11
|
+
end
|
13
12
|
|
14
13
|
def perform_solr_command
|
15
14
|
@rsolr ||= Solrsan::Config.instance.rsolr_object
|
@@ -44,7 +43,7 @@ module Solrsan
|
|
44
43
|
:'facet.mincount' => 1}.merge(search_params)
|
45
44
|
|
46
45
|
solr_params[:hl] = true unless search_params[:'hl.fl'].blank?
|
47
|
-
solr_params[:fq] = ["type:#{
|
46
|
+
solr_params[:fq] = ["type:#{solr_type}"] + parse_fq(search_params[:fq])
|
48
47
|
solr_params
|
49
48
|
end
|
50
49
|
|
@@ -180,7 +179,9 @@ if defined?(Rails) && Rails.env == "test"
|
|
180
179
|
module Search
|
181
180
|
extend ActiveSupport::Concern
|
182
181
|
module ClassMethods
|
183
|
-
|
182
|
+
def solr_type
|
183
|
+
"#{self.to_s.underscore}_test"
|
184
|
+
end
|
184
185
|
end
|
185
186
|
end
|
186
187
|
end
|
data/lib/solrsan/version.rb
CHANGED
data/test/unit/search_test.rb
CHANGED
@@ -13,6 +13,19 @@ class SearchTest < Test::Unit::TestCase
|
|
13
13
|
Document.destroy_all_index_documents!
|
14
14
|
end
|
15
15
|
|
16
|
+
def test_attributes
|
17
|
+
Document.solr_index(@document)
|
18
|
+
sleep 1
|
19
|
+
q = @document.attributes[:title]
|
20
|
+
|
21
|
+
response = Document.search(:q => q)
|
22
|
+
metadata = response[:metadata]
|
23
|
+
docs = response[:docs]
|
24
|
+
doc = docs.first
|
25
|
+
|
26
|
+
assert_equal "document_test", doc["type"]
|
27
|
+
end
|
28
|
+
|
16
29
|
def test_simple_query
|
17
30
|
Document.solr_index(@document)
|
18
31
|
sleep 1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solrsan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rsolr
|
16
|
-
requirement: &
|
16
|
+
requirement: &70361182665480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70361182665480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activemodel
|
27
|
-
requirement: &
|
27
|
+
requirement: &70361182664500 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>'
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.1.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70361182664500
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activesupport
|
38
|
-
requirement: &
|
38
|
+
requirement: &70361182662680 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>'
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 3.1.1
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70361182662680
|
47
47
|
description: solrsan is a lightweight wrapper for using Apache Solr within a Ruby
|
48
48
|
application including Rails and Sinatra.
|
49
49
|
email:
|