Class: CouchRest::Model::Base

Inherits:
Object
  • Object
show all
Extended by:
Search::Escape
Defined in:
lib/couchrest_model_search.rb

Class Method Summary collapse

Methods included from Search::Escape

escape_special_characters, lucene_special_characters

Class Method Details

.escaped_search(query, view_fn = "by_fulltext", options = {}) ⇒ Object



111
112
113
# File 'lib/couchrest_model_search.rb', line 111

def escaped_search(query, view_fn="by_fulltext", options={})
  self.search escape_special_characters(query), view_fn, options
end

.search(query, view_fn = "by_fulltext", options = {}) ⇒ Object



105
106
107
108
109
# File 'lib/couchrest_model_search.rb', line 105

def search(query, view_fn="by_fulltext", options={})
  options[:include_docs] = true
  ret = self.database.search(self.to_s, view_fn, query, options)
  ret['rows'].map {|r| self.new(r['doc'])}
end

.search_by(fn_name, fn) ⇒ Object

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