Module: Srchio::Concern::ClassMethods

Defined in:
lib/srchio/concern.rb

Instance Method Summary collapse

Instance Method Details

#configure_srch(opts = {}) ⇒ Object

configure_srch: Configure the client for this model, mapping fields and setting the searcher id to use for all API call.

options:

  • searcher_id: the id for the searcher to use. This should probably be set in an environment variable, so you don’t accidentally use development data in your production searcher, for example.

  • title: The method to use as the title when saving a document.

  • body: The method to use as the body when saving a document.

  • url: The method to use for the URL when saving a document.

  • tags: The method to use for tags when saving a document.

  • created: The method to use for setting the timestamp on a document.

  • remote_id: The method to use for setting the id on a document (probably should be :id.



58
59
60
61
62
63
64
65
66
# File 'lib/srchio/concern.rb', line 58

def configure_srch(opts={})
	raise "SearcherIdRequired" if opts[:searcher_id].nil?
	raise "TitleRequired" if opts[:title].nil?
	raise "BodyRequired" if opts[:body].nil?
	raise "UrlRequired" if opts[:url].nil?
	raise "RemoteIdRequired" if opts[:remote_id].nil?
	
	@@srch_config = opts
end

#srch(opts = {}) ⇒ Object

srch: Search your content!

options:

  • query: Query all the fields.

  • page: The page of results to return, defaults to 1.

  • per_page: The number of results to return per page. Defaults to 25, max of 100.

  • body: Search just the body for something.

  • title: Search just the title for something.

  • tags: Find documents by their tags.

  • remote_id: Find a single document by the remote_id.



96
97
98
# File 'lib/srchio/concern.rb', line 96

def srch(opts={})
	srch_client.search(opts)
end

#srch_add(opts = {}) ⇒ Object

srch_add: Add a document to your searcher.

options:

  • title: required

  • body: required

  • url: required

  • remote_id: recommended The id in your system for the object being added.

  • tags: An array or comma-separated list of tags.

  • created: The creation timestamp for your document.



134
135
136
# File 'lib/srchio/concern.rb', line 134

def srch_add(opts={})
	srch_client.add_document(opts)
end

#srch_clientObject

srch_client: The client used to do all the API calls. The concern provides method wrappers for everything, so you probably don’t need to call this directly.



79
80
81
# File 'lib/srchio/concern.rb', line 79

def srch_client
	@@client ||= Srchio::Client.new(:searcher_id => srch_config[:searcher_id])
end

#srch_configObject



68
69
70
# File 'lib/srchio/concern.rb', line 68

def srch_config
	@@srch_config
end

#srch_config=(opts) ⇒ Object



72
73
74
# File 'lib/srchio/concern.rb', line 72

def srch_config=(opts)
	@@srch_config = opts
end

#srch_destroy(opts = {}) ⇒ Object

srch_destroy: Destroy a document.

options: (one of them is required)

  • remote_id: The id in your system for the document.

  • index_id: The id for the document in our system.



118
119
120
# File 'lib/srchio/concern.rb', line 118

def srch_destroy(opts={})
	srch_client.destroy_document(opts)
end

#tag_cloud(opts = {}) ⇒ Object

tag_cloud: Return the tags for your searcher.

options:

  • n: The number of tags to return. Defaults to 1,000.



106
107
108
# File 'lib/srchio/concern.rb', line 106

def tag_cloud(opts={})
  srch_client.tag_cloud(opts)
end