Class: CouchRest::Model::Base
- Inherits:
-
Object
- Object
- CouchRest::Model::Base
- Extended by:
- Search::Escape
- Defined in:
- lib/couchrest_model_search.rb
Class Method Summary (collapse)
- + (Object) escaped_search(query, view_fn = "by_fulltext", options = {})
- + (Object) search(query, view_fn = "by_fulltext", options = {})
-
+ (Object) search_by(fn_name, fn)
example search functions.
Methods included from Search::Escape
escape_special_characters, lucene_special_characters
Class Method Details
+ (Object) escaped_search(query, view_fn = "by_fulltext", options = {})
111 112 113 |
# File 'lib/couchrest_model_search.rb', line 111 def escaped_search(query, view_fn="by_fulltext", ={}) self.search escape_special_characters(query), view_fn, end |
+ (Object) search(query, view_fn = "by_fulltext", options = {})
105 106 107 108 109 |
# File 'lib/couchrest_model_search.rb', line 105 def search(query, view_fn="by_fulltext", ={}) [:include_docs] = true ret = self.database.search(self.to_s, view_fn, query, ) ret['rows'].map {|r| self.new(r['doc'])} end |
+ (Object) search_by(fn_name, fn)
example search functions
class Aritlce
search_by :title,
:index => %(
function(doc) {
// ....
}
)
now you can make search like
Article.search "apple" # by default it uses "by_fulltext" search function
Article.search "apple", :by_title
128 129 130 131 132 |
# File 'lib/couchrest_model_search.rb', line 128 def self.search_by(fn_name, fn) design_doc["fulltext"] ||= {} design_doc["fulltext"]["by_#{fn_name}"] = fn.stringify_keys! req_design_doc_refresh end |