customized-mongomapper-search 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGE_LOG ADDED
@@ -0,0 +1,13 @@
1
+ 0.1.4
2
+ ------
3
+ - Added a way to specify the Solr document id (uniqueKey) field that the MongoMapper document _id key maps to.
4
+ - Added handling for Solr document id/uniqueKey field that's set as multiValued so that the first value is chosen. There can only be one value for the id/uniqueKey field but it's still possible to set the field as multiValued. RSolr returns an array containing only one value for the id/uniqueKey field when the field is multiValued.
5
+
6
+ 0.1.3
7
+ ------
8
+ - Added an option named "solr_field_name" for MongoMapper document keys. The value of "solr_field_name" overrides the name of the key when indexing the document in Solr.
9
+
10
+
11
+ 0.1.2
12
+ ______
13
+ - Added the ability to define the value of the "qt" request parameter as an option in the options hash of the search method. The value of the "qt" request parameter defaults to "standard" if one is not specified in the options hash.
data/Manifest CHANGED
@@ -1,3 +1,4 @@
1
+ CHANGE_LOG
1
2
  README.rdoc
2
3
  Rakefile
3
4
  lib/customized-mongomapper-search.rb
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = tsxn-mongomapper-search
2
2
 
3
- Easily integreate mongo mapper with enterprise search like solr. MODIFIED/CUSTOMIZED by tsxn26 to use a specified Solr URL in the model.
3
+ Easily integrate mongo mapper with enterprise search like solr. MODIFIED/CUSTOMIZED to use a specified Solr URL in the model.
4
4
 
5
5
  == Credits
6
6
 
@@ -10,17 +10,28 @@ The original gem was written by Fernando Meyer and can be found at http://github
10
10
 
11
11
  Within the model that includes MongoMapper::Document add the following:
12
12
 
13
- class << self; attr_accessor :SOLR_URL end
14
- @SOLR_URL = "{SOLR URL}"
13
+ class << self; attr_accessor :SOLR_URL end
14
+ @SOLR_URL = "{SOLR URL}" # {SOLR URL} should be replaced with the actual solr url if that wasn't apparent
15
15
 
16
16
  Example:
17
17
 
18
- class Foo
19
- include MongoMapper::Document
20
- include Search::SolrDocument
18
+ class Foo
19
+ include MongoMapper::Document
20
+ include Search::SolrDocument
21
21
 
22
- class << self; attr_accessor :SOLR_URL end
23
- @SOLR_URL = "http://localhost:8080/solr/foo.core"
22
+ class << self; attr_accessor :SOLR_URL end
23
+ @SOLR_URL = "http://localhost:8080/solr/foo.core"
24
24
 
25
- key :name, String, :fulltext => true
26
- end
25
+ key :name, String, :fulltext => true
26
+ end
27
+
28
+ The name of the index document fields can be also be specified if the name of the keys aren't desired.
29
+
30
+ Example:
31
+
32
+ key :name, String, :fulltext => true, :solr_field_name => "object_name"
33
+
34
+ The name of the Solr document id/uniqueKey name can be specified that the MongoMapper document _id maps to. Within the model that includes MongoMapper::Document add the folowing:
35
+
36
+ class << self; attr_accessor :SOLR_DOC_ID_FIELD end
37
+ @SOLR_DOC_ID_FIELD = "preexisting_index_id"
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('customized-mongomapper-search', '0.1.3') do |p|
5
+ Echoe.new('customized-mongomapper-search', '0.1.4') do |p|
6
6
  p.description = "Easily integreate mongo mapper with enterprise search like solr. CUSTOMIZED to use a specified Solr URL in the model. Original mongomapper-search gem (version 0.1.0) was written by Fernando Meyer and can be found at http://github.com/fmeyer/mongomapper-search."
7
7
  p.url = "http://github.com/tsxn26/customized-mongomapper-search"
8
8
  p.author = ["Fernando Meyer", "Thomas Nguyen"]
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{customized-mongomapper-search}
5
- s.version = "0.1.3"
5
+ s.version = "0.1.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Fernando Meyer, Thomas Nguyen"]
9
- s.date = %q{2010-04-16}
9
+ s.date = %q{2010-04-29}
10
10
  s.description = %q{Easily integreate mongo mapper with enterprise search like solr. CUSTOMIZED to use a specified Solr URL in the model. Original mongomapper-search gem (version 0.1.0) was written by Fernando Meyer and can be found at http://github.com/fmeyer/mongomapper-search.}
11
11
  s.email = %q{tsxn26@gmail.com}
12
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"]
13
+ s.files = ["CHANGE_LOG", "README.rdoc", "Rakefile", "lib/customized-mongomapper-search.rb", "lib/search.rb", "Manifest", "customized-mongomapper-search.gemspec"]
14
14
  s.homepage = %q{http://github.com/tsxn26/customized-mongomapper-search}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Customized-mongomapper-search", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
data/lib/search.rb CHANGED
@@ -13,9 +13,12 @@ module Search::SolrDocument
13
13
  def search(query, page = 1, opts = {})
14
14
  init_connection()
15
15
  WillPaginate::Collection.create(page, 20) do |pager|
16
- result,count = search_engine_query(query, opts)
16
+ result = search_engine_query(query, opts)
17
+ if(result.class == Array)
18
+ result.compact!
19
+ end
17
20
  pager.replace(result)
18
- pager.total_entries = count
21
+ pager.total_entries = result.length
19
22
  end
20
23
  end
21
24
 
@@ -23,13 +26,31 @@ module Search::SolrDocument
23
26
  def search_engine_query(query, opts = {})
24
27
  opts.reverse_merge!(:limit => 20, :offset => 0)
25
28
  resp = @Solr.select(:q => query, :rows => opts[:limit], :start => opts[:offset], :qt => !opts[:qt].blank? ? opts[:qt] : "standard", :fl => '*,score')['response']
26
- return resp['docs'].map{|doc| find(doc['id'])}, resp['numFound']
29
+
30
+ if(instance_variable_defined?(:@SOLR_DOC_ID_FIELD) && !instance_variable_get(:@SOLR_DOC_ID_FIELD).blank?)
31
+ id_name = instance_variable_get(:@SOLR_DOC_ID_FIELD)
32
+ else
33
+ id_name = 'id'
34
+ end
35
+
36
+ return resp['docs'].map do |doc|
37
+ id = doc[id_name]
38
+ if id.class == Array
39
+ id = id[0]
40
+ end
41
+ find(id)
42
+ end
27
43
  end
28
44
  end
29
45
 
30
46
  module InstanceMethods
31
47
  def to_index
32
- attrs = {'id' => self._id}
48
+ if(self.class.instance_variable_defined?(:@SOLR_DOC_ID_FIELD) && !self.class.SOLR_DOC_ID_FIELD.blank?)
49
+ attrs = {self.class.SOLR_DOC_ID_FIELD => self._id}
50
+ else
51
+ attrs = {'id' => self._id}
52
+ end
53
+
33
54
  self.keys.each_pair do |name, key|
34
55
  field_name = key.options[:solr_field_name]
35
56
  field_name ||= name
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Fernando Meyer, Thomas Nguyen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-16 00:00:00 -07:00
17
+ date: 2010-04-29 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -70,6 +70,7 @@ extra_rdoc_files:
70
70
  - lib/customized-mongomapper-search.rb
71
71
  - lib/search.rb
72
72
  files:
73
+ - CHANGE_LOG
73
74
  - README.rdoc
74
75
  - Rakefile
75
76
  - lib/customized-mongomapper-search.rb