couchrest_model_search 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -13,7 +13,7 @@ This add search method calls to couchrest_model gem. Assuming you are using couc
13
13
  # by default, couchrest_model only update view_by functions.
14
14
  Article.update_search_doc
15
15
 
16
- @articles = Article..search 'by_content', "apple" # search by keyword apple
16
+ @articles = Article.search 'by_content', "apple" # search by keyword apple
17
17
 
18
18
  # you can also custom the search function.
19
19
  class CustomArticle < CouchRest::Model::Base
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{couchrest_model_search}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dorren Chen"]
@@ -52,7 +52,11 @@ end
52
52
 
53
53
  class CouchRest::Database
54
54
  def search(klass, view_fn, query, options={})
55
- CouchRest.get CouchRest.paramify_url("#{@root}/_fti/_design/#{klass}/#{view_fn}", options.merge(:q => query))
55
+ url = CouchRest.paramify_url("#{@root}/_fti/_design/#{klass}/#{view_fn}", options.merge(:q => query))
56
+ ActiveSupport::Notifications.instrument("search.lucene",
57
+ :query => url) do
58
+ CouchRest.get url
59
+ end
56
60
  end
57
61
  end
58
62
 
@@ -64,9 +68,20 @@ class CouchRest::Model::Base
64
68
  end
65
69
 
66
70
  def self.update_search_doc
67
- dbdoc = database.get '_design/#{self.to_s}'
71
+ dbdoc = database.get "_design/#{self.to_s}"
68
72
  dbdoc.update design_doc
69
73
  dbdoc.save
70
74
  end
71
75
  end
72
76
 
77
+
78
+ # see http://gist.github.com/566725 on how to use ActiveSupport logging
79
+ class CouchRestModelSearchLogger < ActiveSupport::LogSubscriber
80
+ def search(event)
81
+ name = '%s (%.1fms)' % ["Couchdb-lucene Query", event.duration]
82
+ url = event.payload[:query]
83
+ info " #{color(name, YELLOW, true)} [ #{url} ]"
84
+ end
85
+ end
86
+
87
+ CouchRestModelSearchLogger.attach_to :lucene
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchrest_model_search
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dorren Chen