Class: Khoj::Function

Inherits:
Object
  • Object
show all
Includes:
Index
Defined in:
lib/khoj/function.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Index

#create_index, #delete_index, #index?, #index_stats

Constructor Details

#initialize(index) ⇒ Function

Returns a new instance of Function.



8
9
10
11
12
# File 'lib/khoj/function.rb', line 8

def initialize(index)
  @index = index
  @_index = "#{Configuration.api_key}-#{index}"
  @conn = Configuration.connection
end

Instance Attribute Details

#_indexObject (readonly)

Returns the value of attribute _index.



6
7
8
# File 'lib/khoj/function.rb', line 6

def _index
  @_index
end

#indexObject

Returns the value of attribute index.



5
6
7
# File 'lib/khoj/function.rb', line 5

def index
  @index
end

Instance Method Details

#add(funtion_name, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/khoj/function.rb', line 14

def add(funtion_name, options ={})
  type = options[:type]
  if funtion_name == 'geo_location' 
    geo_mapping =  { "#{type}" => { "properties" => { "location" => { "type" => "geo_point" } } } }
    req_options = {:body => geo_mapping.to_json, :format => 'json'}
    response = @conn.post("/#{_index}/#{type}/_mapping", req_options)
    case response.code
    when 200
      true
    when 201
      true
    else
      raise KhojException.new(response.parsed_response)
    end
  else
      raise KhojException.new('No function found with given name')
  end
end