class Suggester::Client
Simple client to access a Suggester::Server
instance
Constants
- DEFAULT_HOST
server uses sinatra with default port 17500
- DEFAULT_PORT
Attributes
Public Class Methods
Create an instance of the client
# File lib/suggester/client.rb, line 22 def initialize(options = {}) @host = options[:host] || DEFAULT_HOST @port = options[:port] || DEFAULT_PORT @logger = options[:logger] end
Public Instance Methods
Find returns an array of data returned for records that start with query string provided
Parameters¶ ↑
-
type
- The name of the handler like “book” -
query
- The search term you are searching on -
options
- Hash of optionally parameters which are passed as query parameters. Includes the:limit
option.
Examples¶ ↑
# find exact matches client = Suggester::Client.new client.match("book", "A Tale") # returns all books that match "A Tale of Two Cities" client.match("book", "A Tale", :limit => 1) # return the first match for "A Tale of Two Cities"
# File lib/suggester/client.rb, line 64 def find(type, query, options = {}) fetch_response(build_url(type, "find", query, options)) end
Match returns an array of data returned that is an exact match for the query string provided
Parameters¶ ↑
-
type
- The name of the handler like “book” -
query
- The search term you are matching on -
options
- Hash of optionally parameters which are passed as query parameters. Includes the:limit
option.
Examples¶ ↑
# find exact matches client = Suggester::Client.new client.match("book", "A Tale of Two Cities") # returns all books that match "A Tale of Two Cities" client.match("book", "A Tale of Two Cities", :limit => 1) # return the first match for "A Tale of Two Cities"
# File lib/suggester/client.rb, line 44 def match(type, query, options = {}) fetch_response(build_url(type, "match", query, options)) end
Refresh tells the server to force a reload of its cached data
Parameters¶ ↑
-
type
- The name of the handler to refresh
# File lib/suggester/client.rb, line 73 def refresh(type) url = "http://#{@host}:#{@port}/#{type}/refresh.json" response = fetch_response(url) return response.is_a?(Hash) && response["return"] == "OK" end