Class: Oss::Index
- Inherits:
-
Object
- Object
- Oss::Index
- Defined in:
- lib/oss_rb.rb
Instance Attribute Summary collapse
-
#documents ⇒ Object
Returns the value of attribute documents.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#create(template = 'WEB_CRAWLER') ⇒ Object
Create a new index with the given template name github.com/jaeksoft/opensearchserver/wiki/Index-create.
-
#delete! ⇒ Object
Delete the index github.com/jaeksoft/opensearchserver/wiki/Index-delete.
-
#delete_document_by_query(query) ⇒ Object
Delete the document matching the given query.
-
#delete_document_by_value(field_name, *values) ⇒ Object
Delete the document matching the given field and values github.com/jaeksoft/opensearchserver/wiki/Document-delete.
-
#delete_field(field_name = nil) ⇒ Object
Delete the field matching the give name github.com/jaeksoft/opensearchserver/wiki/Field-delete.
-
#index! ⇒ Object
Put document in the index github.com/jaeksoft/opensearchserver/wiki/Document-put-JSON.
-
#initialize(name, host = 'http://localhost:8080', login = nil, key = nil) ⇒ Index
constructor
A new instance of Index.
-
#list ⇒ Object
Return the index list github.com/jaeksoft/opensearchserver/wiki/Index-list.
-
#search_field(body = nil) ⇒ Object
Execute a search (using field) github.com/jaeksoft/opensearchserver/wiki/Search-field.
-
#search_pattern(body = nil) ⇒ Object
Execute a search (using pattern).
-
#search_store_template_field(template, body = nil) ⇒ Object
Create/update a search template (field search) github.com/jaeksoft/opensearchserver/wiki/Search-template-field-set.
-
#search_store_template_pattern(template, body = nil) ⇒ Object
Create/update a search template (pattern search) github.com/jaeksoft/opensearchserver/wiki/Search-template-pattern-set.
-
#search_template_delete(template) ⇒ Object
Delete a search template matching the given name github.com/jaeksoft/opensearchserver/wiki/Search-template-delete.
-
#search_template_field(template, body = nil) ⇒ Object
Execute a search based on an existing template github.com/jaeksoft/opensearchserver/wiki/Search-template-field.
-
#search_template_pattern(template, body = nil) ⇒ Object
Execute a search based on an existing template github.com/jaeksoft/opensearchserver/wiki/Search-pattern.
-
#set_field(field_params) ⇒ Object
Create or update the field defined by the given hash github.com/jaeksoft/opensearchserver/wiki/Field-create-update.
-
#set_field_default_unique(default, unique) ⇒ Object
Set the default field and the unique field github.com/jaeksoft/opensearchserver/wiki/Field-set-default-unique.
Constructor Details
#initialize(name, host = 'http://localhost:8080', login = nil, key = nil) ⇒ Index
Returns a new instance of Index.
7 8 9 10 11 12 |
# File 'lib/oss_rb.rb', line 7 def initialize(name, host = 'http://localhost:8080', login = nil, key = nil) @name = name @documents = Array.new @host = host @credentials = {:login=>login,:key=>key} end |
Instance Attribute Details
#documents ⇒ Object
Returns the value of attribute documents.
6 7 8 |
# File 'lib/oss_rb.rb', line 6 def documents @documents end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/oss_rb.rb', line 6 def name @name end |
Instance Method Details
#create(template = 'WEB_CRAWLER') ⇒ Object
Create a new index with the given template name github.com/jaeksoft/opensearchserver/wiki/Index-create
22 23 24 |
# File 'lib/oss_rb.rb', line 22 def create(template = 'WEB_CRAWLER') api_post "services/rest/index/#{@name}/template/#{template}" end |
#delete! ⇒ Object
Delete the index github.com/jaeksoft/opensearchserver/wiki/Index-delete
28 29 30 |
# File 'lib/oss_rb.rb', line 28 def delete! api_delete "services/rest/index/#{@name}" end |
#delete_document_by_query(query) ⇒ Object
Delete the document matching the given query
58 59 60 61 |
# File 'lib/oss_rb.rb', line 58 def delete_document_by_query(query) params = { 'query' => query } api_delete "services/rest/index/#{@name}/document", params end |
#delete_document_by_value(field_name, *values) ⇒ Object
Delete the document matching the given field and values github.com/jaeksoft/opensearchserver/wiki/Document-delete
53 54 55 |
# File 'lib/oss_rb.rb', line 53 def delete_document_by_value(field_name, *values) api_delete "services/rest/index/#{@name}/document/#{field_name}/#{values.join('/')}" end |
#delete_field(field_name = nil) ⇒ Object
Delete the field matching the give name github.com/jaeksoft/opensearchserver/wiki/Field-delete
47 48 49 |
# File 'lib/oss_rb.rb', line 47 def delete_field(field_name = nil) api_delete "services/rest/index/#{@name}/field/#{field_name}" end |
#index! ⇒ Object
Put document in the index github.com/jaeksoft/opensearchserver/wiki/Document-put-JSON
65 66 67 68 |
# File 'lib/oss_rb.rb', line 65 def index! api_put_json "services/rest/index/#{@name}/document", @documents @documents = [] end |
#list ⇒ Object
Return the index list github.com/jaeksoft/opensearchserver/wiki/Index-list
16 17 18 |
# File 'lib/oss_rb.rb', line 16 def list JSON.parse(api_get("services/rest/index"))["indexList"] end |
#search_field(body = nil) ⇒ Object
Execute a search (using field) github.com/jaeksoft/opensearchserver/wiki/Search-field
77 78 79 |
# File 'lib/oss_rb.rb', line 77 def search_field(body = nil) JSON.parse(api_post_json("services/rest/index/#{@name}/search/field", body)) end |
#search_pattern(body = nil) ⇒ Object
Execute a search (using pattern)
71 72 73 |
# File 'lib/oss_rb.rb', line 71 def search_pattern( body = nil) JSON.parse(api_post_json("services/rest/index/#{@name}/search/pattern", body)) end |
#search_store_template_field(template, body = nil) ⇒ Object
Create/update a search template (field search) github.com/jaeksoft/opensearchserver/wiki/Search-template-field-set
101 102 103 |
# File 'lib/oss_rb.rb', line 101 def search_store_template_field(template, body = nil) api_put_json"services/rest/index/#{@name}/search/field/#{template}", body end |
#search_store_template_pattern(template, body = nil) ⇒ Object
Create/update a search template (pattern search) github.com/jaeksoft/opensearchserver/wiki/Search-template-pattern-set
95 96 97 |
# File 'lib/oss_rb.rb', line 95 def search_store_template_pattern(template, body = nil) api_put_json "services/rest/index/#{@name}/search/pattern/#{template}", body end |
#search_template_delete(template) ⇒ Object
Delete a search template matching the given name github.com/jaeksoft/opensearchserver/wiki/Search-template-delete
107 108 109 |
# File 'lib/oss_rb.rb', line 107 def search_template_delete(template) api_delete "services/rest/index/#{@name}/search/template/#{template}" end |
#search_template_field(template, body = nil) ⇒ Object
Execute a search based on an existing template github.com/jaeksoft/opensearchserver/wiki/Search-template-field
89 90 91 |
# File 'lib/oss_rb.rb', line 89 def search_template_field(template, body = nil) JSON.parse(api_post_json("services/rest/index/#{@name}/search/field/#{template}", body)) end |
#search_template_pattern(template, body = nil) ⇒ Object
Execute a search based on an existing template github.com/jaeksoft/opensearchserver/wiki/Search-pattern
83 84 85 |
# File 'lib/oss_rb.rb', line 83 def search_template_pattern(template, body = nil) JSON.parse(api_post_json("services/rest/index/#{@name}/search/pattern/#{template}", body)) end |
#set_field(field_params) ⇒ Object
Create or update the field defined by the given hash github.com/jaeksoft/opensearchserver/wiki/Field-create-update
34 35 36 |
# File 'lib/oss_rb.rb', line 34 def set_field(field_params) api_put_json "services/rest/index/#{@name}/field/#{URI.encode(field_params['name'])}", field_params end |
#set_field_default_unique(default, unique) ⇒ Object
Set the default field and the unique field github.com/jaeksoft/opensearchserver/wiki/Field-set-default-unique
40 41 42 43 |
# File 'lib/oss_rb.rb', line 40 def set_field_default_unique(default, unique) params = { 'unique' => unique, 'default' => default } api_post "services/rest/index/#{@name}/field", '', params end |