customized-mongomapper-search 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGE_LOG +5 -0
- data/README.rdoc +7 -2
- data/Rakefile +2 -2
- data/customized-mongomapper-search.gemspec +3 -3
- data/lib/search/indexable.rb +18 -31
- metadata +5 -5
data/CHANGE_LOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
1.0.2
|
2
|
+
------
|
3
|
+
- Added a class method "idx_force_commit" that specifies whether index and delete operations should be force committed. ******* All index and delete operations now default to not being force committed. *******
|
4
|
+
- Cleaned up code
|
5
|
+
|
1
6
|
1.0.1
|
2
7
|
------
|
3
8
|
- Changed the output format of attributes of class type Time so that it complies with Solr's date field type. The output format is now %Y-%m-%dT%H:%M:%SZ. e.g. 2001-06-11T00:00:00Z
|
data/README.rdoc
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
= tsxn-mongomapper-search
|
2
2
|
|
3
|
-
Easily integrate Mongo Mapper with with Solr search.
|
3
|
+
Easily integrate Mongo Mapper with with Solr search. Please view the CHANGELOG before updating the gem.
|
4
4
|
|
5
5
|
== Credits
|
6
6
|
|
7
7
|
Earlier versions < 1.0.0 were based off the mongomapper-search gem written by Fernando Meyer that can be found at http://github.com/fmeyer/mongomapper-search.
|
8
8
|
|
9
9
|
== Usage
|
10
|
-
== Version 1.0.
|
10
|
+
== Version 1.0.2
|
11
11
|
|
12
12
|
To make a MongoMapper::Document indexable add the following line to include the functionality:
|
13
13
|
|
@@ -16,6 +16,10 @@ To make a MongoMapper::Document indexable add the following line to include the
|
|
16
16
|
The Solr URL must be specified using the :solr_url method. e.g.
|
17
17
|
|
18
18
|
solr_url "http://localhost/solr/some.core"
|
19
|
+
|
20
|
+
To specify that the index and delete operations into Solr should be force committed the :idx_force_commit method must be passed a value of true. It currently defaults to a value of false. e.g.
|
21
|
+
|
22
|
+
idx_force_commit true
|
19
23
|
|
20
24
|
To specify which attributes that need to be indexable pass hashes with the attributes and the corresponding indexed names to the :idx_attr method. e.g.
|
21
25
|
|
@@ -52,6 +56,7 @@ Define a Document model and specify the indexable fields and associations.
|
|
52
56
|
solr_url "http://search-api.search.com/solr/employee.core"
|
53
57
|
idx_attr :_id => "emp_id", :name => "emp_name"
|
54
58
|
idx_assoc :projects => "emp_project"
|
59
|
+
idx_force_commit true
|
55
60
|
|
56
61
|
key :name
|
57
62
|
many :projects
|
data/Rakefile
CHANGED
@@ -2,8 +2,8 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('customized-mongomapper-search', '1.0.
|
6
|
-
p.description = "Easily
|
5
|
+
Echoe.new('customized-mongomapper-search', '1.0.2') do |p|
|
6
|
+
p.description = "Easily integrate Mongo Mapper with with Solr search. Please view the CHANGELOG file found on the GitHub project homepage before upgrading."
|
7
7
|
p.url = "http://github.com/tsxn26/customized-mongomapper-search"
|
8
8
|
p.author = ["Thomas Nguyen"]
|
9
9
|
p.email = "tsxn26@gmail.com"
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{customized-mongomapper-search}
|
5
|
-
s.version = "1.0.
|
5
|
+
s.version = "1.0.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Thomas Nguyen"]
|
9
9
|
s.date = %q{2010-06-11}
|
10
|
-
s.description = %q{Easily
|
10
|
+
s.description = %q{Easily integrate Mongo Mapper with with Solr search. Please view the CHANGELOG file found on the GitHub project homepage before upgrading.}
|
11
11
|
s.email = %q{tsxn26@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["README.rdoc", "lib/customized-mongomapper-search.rb", "lib/search/indexable.rb", "lib/search/searchable.rb"]
|
13
13
|
s.files = ["CHANGE_LOG", "README.rdoc", "Rakefile", "lib/customized-mongomapper-search.rb", "lib/search/indexable.rb", "lib/search/searchable.rb", "Manifest", "customized-mongomapper-search.gemspec"]
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{customized-mongomapper-search}
|
18
18
|
s.rubygems_version = %q{1.3.7}
|
19
|
-
s.summary = %q{Easily
|
19
|
+
s.summary = %q{Easily integrate Mongo Mapper with with Solr search. Please view the CHANGELOG file found on the GitHub project homepage before upgrading.}
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
22
22
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
data/lib/search/indexable.rb
CHANGED
@@ -29,65 +29,54 @@ module Search
|
|
29
29
|
@idx_assocs = {}
|
30
30
|
args.each { |x| @idx_assocs.merge!(x) }
|
31
31
|
end
|
32
|
+
|
33
|
+
def idx_force_commit(commit = false)
|
34
|
+
@idx_force_commit ||= commit
|
35
|
+
end
|
32
36
|
|
33
|
-
def solr_url(
|
34
|
-
|
35
|
-
@solr_url = arg
|
36
|
-
end
|
37
|
-
@solr_url
|
37
|
+
def solr_url(url = nil)
|
38
|
+
@solr_url ||= url
|
38
39
|
end
|
39
40
|
|
40
41
|
def idx_attrs
|
41
|
-
|
42
|
-
@idx_attrs = {}
|
43
|
-
end
|
44
|
-
@idx_attrs
|
42
|
+
@idx_attrs ||= {}
|
45
43
|
end
|
46
44
|
|
47
45
|
def idx_assocs
|
48
|
-
|
49
|
-
@idx_assocs = {}
|
50
|
-
end
|
51
|
-
@idx_assocs
|
46
|
+
@idx_assocs ||= {}
|
52
47
|
end
|
53
48
|
end
|
54
49
|
|
55
50
|
module InstanceMethods
|
56
|
-
def index_to_solr
|
57
|
-
if
|
51
|
+
def index_to_solr
|
52
|
+
if self.class.solr_url # There's no point in attempting to index if the solr url isn't specified
|
58
53
|
fields = get_indexable_fields
|
59
|
-
if
|
54
|
+
if !fields.empty? # There's no point in indexing nothing
|
60
55
|
solr_conn = RSolr.connect(:url => self.class.solr_url)
|
61
56
|
solr_conn.add(fields)
|
62
|
-
if
|
63
|
-
solr_conn.commit
|
64
|
-
end
|
57
|
+
solr_conn.commit if self.class.idx_force_commit
|
65
58
|
end
|
66
59
|
end
|
67
60
|
end
|
68
61
|
|
69
|
-
def delete_from_solr
|
70
|
-
if
|
62
|
+
def delete_from_solr
|
63
|
+
if self.class.solr_url
|
71
64
|
solr_conn = RSolr.connect(:url => self.class.solr_url)
|
72
65
|
solr_conn.delete_by_id(self._id)
|
73
|
-
if
|
74
|
-
solr_conn.commit
|
75
|
-
end
|
66
|
+
solr_conn.commit if self.class.idx_force_commit
|
76
67
|
end
|
77
68
|
end
|
78
69
|
|
79
70
|
protected
|
80
71
|
def get_indexable_fields
|
81
72
|
fields = get_indexable_attributes
|
82
|
-
if self.respond_to?(:associations)
|
83
|
-
fields.merge!(get_indexable_associations)
|
84
|
-
end
|
73
|
+
fields.merge!(get_indexable_associations) if self.respond_to?(:associations)
|
85
74
|
fields
|
86
75
|
end
|
87
76
|
|
88
77
|
def get_indexable_attributes
|
89
78
|
fields = {}
|
90
|
-
if self.class.idx_attrs
|
79
|
+
if self.class.idx_attrs
|
91
80
|
self.class.idx_attrs.each_pair do |x,y|
|
92
81
|
fields[y] = self.attributes[x]
|
93
82
|
fields[y] = fields[y].strftime("%Y-%m-%dT%H:%M:%SZ") if fields[y].is_a?(Time)
|
@@ -111,9 +100,7 @@ module Search
|
|
111
100
|
if x.respond_to?("get_indexable_fields")
|
112
101
|
x_fields = x.get_indexable_fields
|
113
102
|
x_fields.each_pair do |field_name, field_value|
|
114
|
-
if fields[namespace + field_name.to_s]
|
115
|
-
fields[namespace + field_name.to_s] = []
|
116
|
-
end
|
103
|
+
fields[namespace + field_name.to_s] = [] if !fields[namespace + field_name.to_s]
|
117
104
|
fields[namespace + field_name.to_s].push(field_value)
|
118
105
|
end
|
119
106
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: customized-mongomapper-search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Thomas Nguyen
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: 2.3.11
|
67
67
|
type: :runtime
|
68
68
|
version_requirements: *id003
|
69
|
-
description: Easily
|
69
|
+
description: Easily integrate Mongo Mapper with with Solr search. Please view the CHANGELOG file found on the GitHub project homepage before upgrading.
|
70
70
|
email: tsxn26@gmail.com
|
71
71
|
executables: []
|
72
72
|
|
@@ -125,6 +125,6 @@ rubyforge_project: customized-mongomapper-search
|
|
125
125
|
rubygems_version: 1.3.7
|
126
126
|
signing_key:
|
127
127
|
specification_version: 3
|
128
|
-
summary: Easily
|
128
|
+
summary: Easily integrate Mongo Mapper with with Solr search. Please view the CHANGELOG file found on the GitHub project homepage before upgrading.
|
129
129
|
test_files: []
|
130
130
|
|