class Oss::Index

Attributes

documents[RW]
name[RW]

Public Class Methods

new(name, host = 'http://localhost:8080', login = nil, key = nil) click to toggle source
# File lib/oss_rb.rb, line 7
def initialize(name, host = 'http://localhost:8080', login = nil, key = nil)
  @name = name
  @urlname = URI.encode(name)
  @documents = Array.new
  @host = host
  @credentials = {:login=>login,:key=>key}
end

Public Instance Methods

create(template = 'WEB_CRAWLER') click to toggle source

Create a new index with the given template name github.com/jaeksoft/opensearchserver/wiki/Index-create

# File lib/oss_rb.rb, line 23
def create(template = 'WEB_CRAWLER')
  api_post "services/rest/index/#{@urlname}/template/#{template}"
end
delete!() click to toggle source

Delete the index github.com/jaeksoft/opensearchserver/wiki/Index-delete

# File lib/oss_rb.rb, line 29
def delete!
  api_delete "services/rest/index/#{@urlname}"
end
delete_document_by_query(query) click to toggle source

Delete the document matching the given query

# File lib/oss_rb.rb, line 59
def delete_document_by_query(query)
  params = { 'query' => query }
  api_delete "services/rest/index/#{@urlname}/document", params
end
delete_document_by_value(field_name, *values) click to toggle source

Delete the document matching the given field and values github.com/jaeksoft/opensearchserver/wiki/Document-delete

# File lib/oss_rb.rb, line 54
def delete_document_by_value(field_name, *values)
  api_delete "services/rest/index/#{@urlname}/document/#{URI.encode(field_name)}/#{values.join('/')}"
end
delete_field(field_name = nil) click to toggle source

Delete the field matching the give name github.com/jaeksoft/opensearchserver/wiki/Field-delete

# File lib/oss_rb.rb, line 48
def delete_field(field_name = nil)
  api_delete "services/rest/index/#{@urlname}/field/#{URI.encode(field_name)}"
end
index!() click to toggle source

Put document in the index github.com/jaeksoft/opensearchserver/wiki/Document-put-JSON

# File lib/oss_rb.rb, line 66
def index!
  api_put_json "services/rest/index/#{@urlname}/document", @documents
  @documents = []
end
list() click to toggle source

Return the index list github.com/jaeksoft/opensearchserver/wiki/Index-list

# File lib/oss_rb.rb, line 17
def list
  JSON.parse(api_get("services/rest/index"))["indexList"]
end
search_field(body = nil) click to toggle source

Execute a search (using field) github.com/jaeksoft/opensearchserver/wiki/Search-field

# File lib/oss_rb.rb, line 78
def search_field(body = nil)
  JSON.parse(api_post_json("services/rest/index/#{@urlname}/search/field", body))
end
search_pattern( body = nil) click to toggle source

Execute a search (using pattern)

# File lib/oss_rb.rb, line 72
def search_pattern( body = nil)
  JSON.parse(api_post_json("services/rest/index/#{@urlname}/search/pattern", body))
end
search_store_template_field(template, body = nil) click to toggle source

Create/update a search template (field search) github.com/jaeksoft/opensearchserver/wiki/Search-template-field-set

# File lib/oss_rb.rb, line 102
def search_store_template_field(template,  body = nil)
  api_put_json"services/rest/index/#{@urlname}/search/field/#{template}", body
end
search_store_template_pattern(template, body = nil) click to toggle source

Create/update a search template (pattern search) github.com/jaeksoft/opensearchserver/wiki/Search-template-pattern-set

# File lib/oss_rb.rb, line 96
def search_store_template_pattern(template,  body = nil)
  api_put_json "services/rest/index/#{@urlname}/search/pattern/#{template}", body
end
search_template_delete(template) click to toggle source

Delete a search template matching the given name github.com/jaeksoft/opensearchserver/wiki/Search-template-delete

# File lib/oss_rb.rb, line 108
def search_template_delete(template)
  api_delete "services/rest/index/#{@urlname}/search/template/#{template}"
end
search_template_field(template, body = nil) click to toggle source

Execute a search based on an existing template github.com/jaeksoft/opensearchserver/wiki/Search-template-field

# File lib/oss_rb.rb, line 90
def search_template_field(template,  body = nil)
  JSON.parse(api_post_json("services/rest/index/#{@urlname}/search/field/#{template}", body))
end
search_template_pattern(template, body = nil) click to toggle source

Execute a search based on an existing template github.com/jaeksoft/opensearchserver/wiki/Search-pattern

# File lib/oss_rb.rb, line 84
def search_template_pattern(template,  body = nil)
  JSON.parse(api_post_json("services/rest/index/#{@urlname}/search/pattern/#{template}", body))
end
set_field(field_params) click to toggle source

Create or update the field defined by the given hash github.com/jaeksoft/opensearchserver/wiki/Field-create-update

# File lib/oss_rb.rb, line 35
def set_field(field_params)
  api_put_json "services/rest/index/#{@urlname}/field/#{URI.encode(field_params['name'])}", field_params
end
set_field_default_unique(default, unique) click to toggle source

Set the default field and the unique field github.com/jaeksoft/opensearchserver/wiki/Field-set-default-unique

# File lib/oss_rb.rb, line 41
def set_field_default_unique(default, unique)
  params = { 'unique' => unique, 'default' => default }
  api_post "services/rest/index/#{@urlname}/field", '', params
end

Private Instance Methods

api_delete(method, params={}) click to toggle source
# File lib/oss_rb.rb, line 134
def api_delete (method, params={})
  RestClient.delete("#{@host}/#{method}", {:params => params.merge(@credentials)})
end
api_get(method, params={}) click to toggle source
# File lib/oss_rb.rb, line 114
def api_get (method, params={})
  RestClient.get("#{@host}/#{method}", {:accept => :json, :params => params.merge(@credentials)})
end
api_post(method, body="", params={}) click to toggle source
# File lib/oss_rb.rb, line 118
def api_post (method, body="", params={})
  RestClient.post("#{@host}/#{method}", body, {:params => params.merge(@credentials)})
end
api_post_json(method, body="", params={}) click to toggle source
# File lib/oss_rb.rb, line 122
def api_post_json (method, body="", params={})
  RestClient.post("#{@host}/#{method}", body.to_json, {:accept => :json, :content_type => :json, :params => params.merge(@credentials)})
end
api_put(method, body="", params={}) click to toggle source
# File lib/oss_rb.rb, line 126
def api_put (method, body="", params={})
  RestClient.put("#{@host}/#{method}", body, {:params => params.merge(@credentials)})
end
api_put_json(method, body="", params={}) click to toggle source
# File lib/oss_rb.rb, line 130
def api_put_json (method, body="", params={})
  RestClient.put("#{@host}/#{method}", body.to_json, {:accept => :json, :content_type => :json, :params => params.merge(@credentials)})
end