Class: Khoj::Function
Instance Attribute Summary collapse
-
#_index ⇒ Object
readonly
Returns the value of attribute _index.
-
#index ⇒ Object
Returns the value of attribute index.
Instance Method Summary collapse
- #add(funtion_name, options = {}) ⇒ Object
-
#initialize(index) ⇒ Function
constructor
A new instance of Function.
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
#_index ⇒ Object (readonly)
Returns the value of attribute _index.
6 7 8 |
# File 'lib/khoj/function.rb', line 6 def _index @_index end |
#index ⇒ Object
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, ={}) type = [:type] if funtion_name == 'geo_location' geo_mapping = { "#{type}" => { "properties" => { "location" => { "type" => "geo_point" } } } } = {:body => geo_mapping.to_json, :format => 'json'} response = @conn.post("/#{_index}/#{type}/_mapping", ) 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 |