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 13 |
# 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 |
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
23 24 25 |
# File 'lib/oss_rb.rb', line 23 def create(template = 'WEB_CRAWLER') api_post "services/rest/index/#{@urlname}/template/#{template}" end |
#delete! ⇒ Object
Delete the index github.com/jaeksoft/opensearchserver/wiki/Index-delete
29 30 31 |
# File 'lib/oss_rb.rb', line 29 def delete! api_delete "services/rest/index/#{@urlname}" end |
#delete_document_by_query(query) ⇒ Object
Delete the document matching the given query
59 60 61 62 |
# 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) ⇒ Object
Delete the document matching the given field and values github.com/jaeksoft/opensearchserver/wiki/Document-delete
54 55 56 |
# 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) ⇒ Object
Delete the field matching the give name github.com/jaeksoft/opensearchserver/wiki/Field-delete
48 49 50 |
# 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! ⇒ Object
Put document in the index github.com/jaeksoft/opensearchserver/wiki/Document-put-JSON
66 67 68 69 |
# File 'lib/oss_rb.rb', line 66 def index! api_put_json "services/rest/index/#{@urlname}/document", @documents @documents = [] end |
#list ⇒ Object
Return the index list github.com/jaeksoft/opensearchserver/wiki/Index-list
17 18 19 |
# File 'lib/oss_rb.rb', line 17 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
78 79 80 |
# 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) ⇒ Object
Execute a search (using pattern)
72 73 74 |
# 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) ⇒ Object
Create/update a search template (field search) github.com/jaeksoft/opensearchserver/wiki/Search-template-field-set
102 103 104 |
# 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) ⇒ Object
Create/update a search template (pattern search) github.com/jaeksoft/opensearchserver/wiki/Search-template-pattern-set
96 97 98 |
# 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) ⇒ Object
Delete a search template matching the given name github.com/jaeksoft/opensearchserver/wiki/Search-template-delete
108 109 110 |
# 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) ⇒ Object
Execute a search based on an existing template github.com/jaeksoft/opensearchserver/wiki/Search-template-field
90 91 92 |
# 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) ⇒ Object
Execute a search based on an existing template github.com/jaeksoft/opensearchserver/wiki/Search-pattern
84 85 86 |
# 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) ⇒ Object
Create or update the field defined by the given hash github.com/jaeksoft/opensearchserver/wiki/Field-create-update
35 36 37 |
# 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) ⇒ Object
Set the default field and the unique field github.com/jaeksoft/opensearchserver/wiki/Field-set-default-unique
41 42 43 44 |
# 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 |