customized-mongomapper-search 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ Rakefile
3
+ lib/customized-mongomapper-search.rb
4
+ lib/search.rb
5
+ Manifest
data/README.rdoc ADDED
@@ -0,0 +1,26 @@
1
+ = tsxn-mongomapper-search
2
+
3
+ Easily integreate mongo mapper with enterprise search like solr. MODIFIED/CUSTOMIZED by tsxn26 to use a specified Solr URL in the model.
4
+
5
+ == Credits
6
+
7
+ The original gem was written by Fernando Meyer and can be found at http://github.com/fmeyer/mongomapper-search.
8
+
9
+ == Usage
10
+
11
+ Within the model that includes MongoMapper::Document add the following:
12
+
13
+ class << self; attr_accessor :SOLR_URL end
14
+ @SOLR_URL = "{SOLR URL}"
15
+
16
+ Example:
17
+
18
+ class Foo
19
+ include MongoMapper::Document
20
+ include Search::SolrDocument
21
+
22
+ class << self; attr_accessor :SOLR_URL end
23
+ @SOLR_URL = "http://localhost:8080/solr/foo.core"
24
+
25
+ key :name, String, :fulltext => true
26
+ end
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('customized-mongomapper-search', '0.1.0') do |p|
6
+ p.description = "Easily integreate mongo mapper with enterprise search like solr. CUSTOMIZED to use a specified Solr URL in the model. Original gem was written by Fernando Meyer and can be found at http://github.com/fmeyer/mongomapper-search."
7
+ p.url = "http://github.com/tsxn26/tsxn-mongomapper-search"
8
+ p.author = ["Fernando Meyer", "Thomas Nguyen"]
9
+ p.email = "tsxn26@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.runtime_dependencies = ["oauth-rsolr >=0.12.1", "mongo_mapper", "will_paginate >=2.3.11"]
12
+ p.development_dependencies = []
13
+ end
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{customized-mongomapper-search}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Fernando Meyer, Thomas Nguyen"]
9
+ s.date = %q{2010-04-13}
10
+ s.description = %q{Easily integreate mongo mapper with enterprise search like solr. CUSTOMIZED to use a specified Solr URL in the model. Original gem was written by Fernando Meyer and can be found at http://github.com/fmeyer/mongomapper-search.}
11
+ s.email = %q{tsxn26@gmail.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/customized-mongomapper-search.rb", "lib/search.rb"]
13
+ s.files = ["README.rdoc", "Rakefile", "lib/customized-mongomapper-search.rb", "lib/search.rb", "Manifest", "customized-mongomapper-search.gemspec"]
14
+ s.homepage = %q{http://github.com/tsxn26/tsxn-mongomapper-search}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Customized-mongomapper-search", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{customized-mongomapper-search}
18
+ s.rubygems_version = %q{1.3.6}
19
+ s.summary = %q{Easily integreate mongo mapper with enterprise search like solr. CUSTOMIZED to use a specified Solr URL in the model. Original gem was written by Fernando Meyer and can be found at http://github.com/fmeyer/mongomapper-search.}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ s.add_runtime_dependency(%q<oauth-rsolr>, [">= 0.12.1"])
27
+ s.add_runtime_dependency(%q<mongo_mapper>, [">= 0"])
28
+ s.add_runtime_dependency(%q<will_paginate>, [">= 2.3.11"])
29
+ else
30
+ s.add_dependency(%q<oauth-rsolr>, [">= 0.12.1"])
31
+ s.add_dependency(%q<mongo_mapper>, [">= 0"])
32
+ s.add_dependency(%q<will_paginate>, [">= 2.3.11"])
33
+ end
34
+ else
35
+ s.add_dependency(%q<oauth-rsolr>, [">= 0.12.1"])
36
+ s.add_dependency(%q<mongo_mapper>, [">= 0"])
37
+ s.add_dependency(%q<will_paginate>, [">= 2.3.11"])
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'mongo_mapper'
4
+ require 'rsolr'
5
+ require 'will_paginate/collection'
6
+
7
+ module Search
8
+ mattr_accessor :connection
9
+ end
10
+
11
+ require 'search'
data/lib/search.rb ADDED
@@ -0,0 +1,62 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Search::SolrDocument
4
+ module ClassMethods
5
+ def init_connection
6
+ @Solr ||= RSolr.connect(:url => instance_variable_get(:@SOLR_URL))
7
+ end
8
+
9
+ def show_url
10
+ @test ||= instance_variable_get(:@SOLR_URL)
11
+ end
12
+
13
+ def search(query, page = 1, opts = {})
14
+ init_connection()
15
+ WillPaginate::Collection.create(page, 20) do |pager|
16
+ result,count = search_engine_query(query, opts)
17
+ pager.replace(result)
18
+ pager.total_entries = count
19
+ end
20
+ end
21
+
22
+ protected
23
+ def search_engine_query(query, opts = {})
24
+ opts.reverse_merge!(:limit => 20, :offset => 0)
25
+ resp = @Solr.select(:q => query, :rows => opts[:limit], :start => opts[:offset], :qt => :dismax, :fl => '*,score')['response']
26
+ return resp['docs'].map{|doc| find(doc['id'])}, resp['numFound']
27
+ end
28
+ end
29
+
30
+ module InstanceMethods
31
+ def to_index
32
+ attrs = {'id' => self._id}
33
+ self.keys.each_pair do |name, key|
34
+ attrs.merge!(name => self[name]) if key.options[:fulltext] && self[name] != nil
35
+ end
36
+ attrs
37
+ end
38
+
39
+ def init_connection
40
+ @Solr ||= RSolr.connect(:url => self.class.SOLR_URL)
41
+ end
42
+
43
+ protected
44
+ def save_on_search_engine
45
+ init_connection
46
+ @Solr.add(to_index)
47
+ @Solr.commit
48
+ end
49
+
50
+ def delete_from_search_engine
51
+ init_connection
52
+ @Solr.delete_by_id(self._id)
53
+ end
54
+ end
55
+
56
+ def self.included(receiver)
57
+ receiver.extend ClassMethods
58
+ receiver.send :include, InstanceMethods
59
+ receiver.after_save :save_on_search_engine
60
+ receiver.before_destroy :delete_from_search_engine
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: customized-mongomapper-search
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Fernando Meyer, Thomas Nguyen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-13 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: oauth-rsolr
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 12
30
+ - 1
31
+ version: 0.12.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: mongo_mapper
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: will_paginate
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 2
55
+ - 3
56
+ - 11
57
+ version: 2.3.11
58
+ type: :runtime
59
+ version_requirements: *id003
60
+ description: Easily integreate mongo mapper with enterprise search like solr. CUSTOMIZED to use a specified Solr URL in the model. Original gem was written by Fernando Meyer and can be found at http://github.com/fmeyer/mongomapper-search.
61
+ email: tsxn26@gmail.com
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ extra_rdoc_files:
67
+ - README.rdoc
68
+ - lib/customized-mongomapper-search.rb
69
+ - lib/search.rb
70
+ files:
71
+ - README.rdoc
72
+ - Rakefile
73
+ - lib/customized-mongomapper-search.rb
74
+ - lib/search.rb
75
+ - Manifest
76
+ - customized-mongomapper-search.gemspec
77
+ has_rdoc: true
78
+ homepage: http://github.com/tsxn26/tsxn-mongomapper-search
79
+ licenses: []
80
+
81
+ post_install_message:
82
+ rdoc_options:
83
+ - --line-numbers
84
+ - --inline-source
85
+ - --title
86
+ - Customized-mongomapper-search
87
+ - --main
88
+ - README.rdoc
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 1
104
+ - 2
105
+ version: "1.2"
106
+ requirements: []
107
+
108
+ rubyforge_project: customized-mongomapper-search
109
+ rubygems_version: 1.3.6
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Easily integreate mongo mapper with enterprise search like solr. CUSTOMIZED to use a specified Solr URL in the model. Original gem was written by Fernando Meyer and can be found at http://github.com/fmeyer/mongomapper-search.
113
+ test_files: []
114
+