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 +1 -1
- data/VERSION +1 -1
- data/couchrest_model_search.gemspec +1 -1
- data/lib/couchrest_model_search.rb +17 -2
- metadata +3 -3
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
|
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
|
+
0.0.2
|
@@ -52,7 +52,11 @@ end
|
|
52
52
|
|
53
53
|
class CouchRest::Database
|
54
54
|
def search(klass, view_fn, query, options={})
|
55
|
-
|
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
|
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:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dorren Chen
|