class Oss::Index
Attributes
Public Class Methods
# 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 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 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 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 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 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
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
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
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
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
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
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
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
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
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
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 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
# File lib/oss_rb.rb, line 134 def api_delete (method, params={}) RestClient.delete("#{@host}/#{method}", {:params => params.merge(@credentials)}) end
# File lib/oss_rb.rb, line 114 def api_get (method, params={}) RestClient.get("#{@host}/#{method}", {:accept => :json, :params => params.merge(@credentials)}) end
# File lib/oss_rb.rb, line 118 def api_post (method, body="", params={}) RestClient.post("#{@host}/#{method}", body, {:params => params.merge(@credentials)}) end
# 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
# File lib/oss_rb.rb, line 126 def api_put (method, body="", params={}) RestClient.put("#{@host}/#{method}", body, {:params => params.merge(@credentials)}) end
# 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