oss_rb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +97 -0
- data/LICENSE.txt +21 -0
- data/README.md +31 -0
- data/Rakefile +25 -0
- data/docs/retours_api.txt +11 -0
- data/docs/retours_schema_api.txt +21 -0
- data/examples/index.rb +18 -0
- data/lib/oss_rb.rb +156 -0
- data/lib/oss_rb/version.rb +3 -0
- data/oss_rb.gemspec +25 -0
- data/spec/api/api_v1_spec.rb +126 -0
- data/spec/spec_helper.rb +9 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3b717d6502f67f75077aaaac92a194f00e0fe617
|
4
|
+
data.tar.gz: 12c35c15e835a2a2a4673baa9cef0bbd552ebb04
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f06c34432c9f7f89c157edb279c627597c3d57952ec455ab260e709b8c273de6fa8634d9ab0318d1b7f30ce5c46cf92aab114fe08ebda9363aae8022a28f11e
|
7
|
+
data.tar.gz: 20b734f21cd01f4e7a7b0e9e37642093a036fb299ef2fe85b00aba208d4b4cce34c663a351cffa375eb554efd93b9d3ade35ba57ddcb709fa593fce7a2d93f97
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
|
15
|
+
# Mac
|
16
|
+
.DS_Store
|
17
|
+
|
18
|
+
# Eclipse project
|
19
|
+
.buildpath
|
20
|
+
.project
|
21
|
+
|
22
|
+
# YARD artifacts
|
23
|
+
.yardoc
|
24
|
+
_yardoc
|
25
|
+
doc/
|
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in oss_rb.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem "rake"
|
8
|
+
gem "rspec"
|
9
|
+
gem "guard"
|
10
|
+
gem "guard-bundler"
|
11
|
+
gem "guard-rack"
|
12
|
+
gem 'pry'
|
13
|
+
gem 'net-http-spy'
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem "rspec"
|
18
|
+
gem "rack-test"
|
19
|
+
gem "rspec-core"
|
20
|
+
gem "rspec-expectations"
|
21
|
+
gem "rspec-mocks"
|
22
|
+
gem 'net-http-spy'
|
23
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
oss_rb (0.0.1)
|
5
|
+
activesupport
|
6
|
+
rest-client
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (4.0.0)
|
12
|
+
i18n (~> 0.6, >= 0.6.4)
|
13
|
+
minitest (~> 4.2)
|
14
|
+
multi_json (~> 1.3)
|
15
|
+
thread_safe (~> 0.1)
|
16
|
+
tzinfo (~> 0.3.37)
|
17
|
+
atomic (1.1.10)
|
18
|
+
coderay (1.0.9)
|
19
|
+
diff-lcs (1.2.4)
|
20
|
+
ffi (1.3.1)
|
21
|
+
formatador (0.2.4)
|
22
|
+
guard (1.8.1)
|
23
|
+
formatador (>= 0.2.4)
|
24
|
+
listen (>= 1.0.0)
|
25
|
+
lumberjack (>= 1.0.2)
|
26
|
+
pry (>= 0.9.10)
|
27
|
+
thor (>= 0.14.6)
|
28
|
+
guard-bundler (1.0.0)
|
29
|
+
bundler (~> 1.0)
|
30
|
+
guard (~> 1.1)
|
31
|
+
guard-rack (1.3.1)
|
32
|
+
ffi (~> 1.3.1)
|
33
|
+
guard (~> 1.1)
|
34
|
+
libnotify (~> 0.1.3)
|
35
|
+
rb-inotify (>= 0.5.1)
|
36
|
+
spoon (~> 0.0.1)
|
37
|
+
i18n (0.6.4)
|
38
|
+
libnotify (0.1.4)
|
39
|
+
ffi (>= 0.6.2)
|
40
|
+
listen (1.2.2)
|
41
|
+
rb-fsevent (>= 0.9.3)
|
42
|
+
rb-inotify (>= 0.9)
|
43
|
+
rb-kqueue (>= 0.2)
|
44
|
+
lumberjack (1.0.4)
|
45
|
+
method_source (0.8.1)
|
46
|
+
mime-types (1.23)
|
47
|
+
minitest (4.7.5)
|
48
|
+
multi_json (1.7.7)
|
49
|
+
net-http-spy (0.2.1)
|
50
|
+
pry (0.9.12.2)
|
51
|
+
coderay (~> 1.0.5)
|
52
|
+
method_source (~> 0.8)
|
53
|
+
slop (~> 3.4)
|
54
|
+
rack (1.5.2)
|
55
|
+
rack-test (0.6.2)
|
56
|
+
rack (>= 1.0)
|
57
|
+
rake (10.1.0)
|
58
|
+
rb-fsevent (0.9.3)
|
59
|
+
rb-inotify (0.9.0)
|
60
|
+
ffi (>= 0.5.0)
|
61
|
+
rb-kqueue (0.2.0)
|
62
|
+
ffi (>= 0.5.0)
|
63
|
+
rest-client (1.6.7)
|
64
|
+
mime-types (>= 1.16)
|
65
|
+
rspec (2.14.1)
|
66
|
+
rspec-core (~> 2.14.0)
|
67
|
+
rspec-expectations (~> 2.14.0)
|
68
|
+
rspec-mocks (~> 2.14.0)
|
69
|
+
rspec-core (2.14.2)
|
70
|
+
rspec-expectations (2.14.0)
|
71
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
72
|
+
rspec-mocks (2.14.1)
|
73
|
+
slop (3.4.5)
|
74
|
+
spoon (0.0.4)
|
75
|
+
ffi
|
76
|
+
thor (0.18.1)
|
77
|
+
thread_safe (0.1.2)
|
78
|
+
atomic
|
79
|
+
tzinfo (0.3.37)
|
80
|
+
|
81
|
+
PLATFORMS
|
82
|
+
ruby
|
83
|
+
|
84
|
+
DEPENDENCIES
|
85
|
+
bundler (~> 1.3)
|
86
|
+
guard
|
87
|
+
guard-bundler
|
88
|
+
guard-rack
|
89
|
+
net-http-spy
|
90
|
+
oss_rb!
|
91
|
+
pry
|
92
|
+
rack-test
|
93
|
+
rake
|
94
|
+
rspec
|
95
|
+
rspec-core
|
96
|
+
rspec-expectations
|
97
|
+
rspec-mocks
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) 2013 Ori Pekelman <ori@pekelman.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# oss_rb
|
2
|
+
|
3
|
+
|
4
|
+
A very initial Ruby Client for OpenSearchServer http://www.open-search-server.com
|
5
|
+
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'oss_rb'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install oss_rb
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "bundler"
|
2
|
+
begin
|
3
|
+
Bundler.setup(:default, :development)
|
4
|
+
rescue Bundler::BundlerError => e
|
5
|
+
$stderr.puts e.message
|
6
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
7
|
+
exit e.status_code
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
|
15
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
16
|
+
# do not run integration tests, doesn't work on TravisCI
|
17
|
+
spec.pattern = FileList['spec/*/*_spec.rb']
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "vendorize oss_rb lib"
|
21
|
+
task :vendorize do
|
22
|
+
sh "gem unpack oss_rb -v 0.0.1 --target vendor/private_gems"
|
23
|
+
end
|
24
|
+
|
25
|
+
task :default => :spec
|
@@ -0,0 +1,11 @@
|
|
1
|
+
curl -X PUT "http://localhost:8080/indexname.json" -d
|
2
|
+
{ \n
|
3
|
+
docs: [ \n
|
4
|
+
id:1, \n
|
5
|
+
title: "Open Search Server", \n
|
6
|
+
url: "http://www.open-search-server.com", \n
|
7
|
+
users : ["emmanuel_keller","philcube"] \n
|
8
|
+
] \n
|
9
|
+
}
|
10
|
+
|
11
|
+
curl "http://localhost:8080/indexname?q=ma%20requête"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Creating an index?:
|
2
|
+
POST http://localhost:8080/schema/index1
|
3
|
+
id,doc
|
4
|
+
|
5
|
+
Maybe if I post a document on a non existing index I should create the Index, if not:
|
6
|
+
|
7
|
+
404 Not Found
|
8
|
+
{
|
9
|
+
message:" The database index1 does not exist yet. You can create it by POST http://localhost:8080/schema/index1"
|
10
|
+
}
|
11
|
+
|
12
|
+
http://localhost:8080/schema?cmd=createindex&index.name=index1&index.template=WEB_CRAWLER
|
13
|
+
|
14
|
+
List all the available index:
|
15
|
+
http://localhost:8080/schema?cmd=indexlist
|
16
|
+
|
17
|
+
Deleting an index :
|
18
|
+
http://localhost:8080/schema?cmd=deleteindex&index.name=index1&index.delete.name=index1
|
19
|
+
|
20
|
+
Setting/Creating a schema field:
|
21
|
+
http://localhost:8080/oss1.3/schema?cmd=setField&field.name=titleNew&field.analyzer=StandardAnalyzer&use=index1&field.stored=YES&field.indexed=YES&term.termVector=NO
|
data/examples/index.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative '../lib/oss_rb'
|
2
|
+
require 'securerandom'
|
3
|
+
index = Oss::Index.new("test_oss_rb")
|
4
|
+
index.delete!
|
5
|
+
indexes = index.create('EMPTY_INDEX')
|
6
|
+
puts index.list
|
7
|
+
|
8
|
+
(1..15).each do |i|
|
9
|
+
id = SecureRandom.uuid
|
10
|
+
doc = Oss::Document.new
|
11
|
+
doc.add_field("user", "jane#{i}")
|
12
|
+
doc.add_field("user", "john#{i}")
|
13
|
+
doc.add_field("url", "http://myserver.com/#{id}")
|
14
|
+
index.add_document(doc)
|
15
|
+
end
|
16
|
+
|
17
|
+
index.index!
|
18
|
+
puts index.search("http*")
|
data/lib/oss_rb.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'active_support/all'
|
3
|
+
|
4
|
+
module Oss
|
5
|
+
class Index
|
6
|
+
attr_accessor :documents, :name
|
7
|
+
def initialize(name, host = 'http://localhost:8080', login = nil, key = nil)
|
8
|
+
@name = name
|
9
|
+
@documents = Array.new
|
10
|
+
@host = host
|
11
|
+
@credentials = {:login=>login,:key=>key}
|
12
|
+
end
|
13
|
+
|
14
|
+
# Return the index list
|
15
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Index-list
|
16
|
+
def list
|
17
|
+
JSON.parse(api_get("services/rest/index"))["indexList"]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create a new index with the given template name
|
21
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Index-create
|
22
|
+
def create(template = 'WEB_CRAWLER')
|
23
|
+
api_post "services/rest/index/#{@name}/template/#{template}"
|
24
|
+
end
|
25
|
+
|
26
|
+
# Delete the index
|
27
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Index-delete
|
28
|
+
def delete!
|
29
|
+
api_delete "services/rest/index/#{@name}"
|
30
|
+
end
|
31
|
+
|
32
|
+
# Create or update the field defined by the given hash
|
33
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Field-create-update
|
34
|
+
def set_field(field_params)
|
35
|
+
api_put_json "services/rest/index/#{@name}/field", field_params
|
36
|
+
end
|
37
|
+
|
38
|
+
# Set the default field and the unique field
|
39
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Field-set-default-unique
|
40
|
+
def set_field_default_unique(default, unique)
|
41
|
+
params = { 'unique' => unique, 'default' => default }
|
42
|
+
api_put "services/rest/index/#{@name}/field", '', params
|
43
|
+
end
|
44
|
+
|
45
|
+
# Delete the field matching the give name
|
46
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Field-delete
|
47
|
+
def delete_field(field_name = nil)
|
48
|
+
api_delete "services/rest/index/#{@name}/field/#{field_name}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Delete the document matching the given field and values
|
52
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Document-delete
|
53
|
+
def delete_document_by_value(field_name, *values)
|
54
|
+
api_delete "services/rest/index/#{@name}/document/#{field_name}/#{values.join('/')}"
|
55
|
+
end
|
56
|
+
|
57
|
+
# Delete the document matching the given query
|
58
|
+
def delete_document_by_query(query)
|
59
|
+
params = { 'query' => query }
|
60
|
+
api_delete "services/rest/index/#{@name}/document", params
|
61
|
+
end
|
62
|
+
|
63
|
+
# Put document in the index
|
64
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Document-put-JSON
|
65
|
+
def index!
|
66
|
+
api_put_json "services/rest/index/#{@name}/document", @documents
|
67
|
+
@documents = []
|
68
|
+
end
|
69
|
+
|
70
|
+
# Execute a search (using pattern)
|
71
|
+
def search_pattern( body = nil)
|
72
|
+
JSON.parse(api_post_json("services/rest/index/#{@name}/search/pattern", body))
|
73
|
+
end
|
74
|
+
|
75
|
+
# Execute a search (using field)
|
76
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Search-field
|
77
|
+
def search_field(body = nil)
|
78
|
+
JSON.parse(api_post_json("services/rest/index/#{@name}/search/field", body))
|
79
|
+
end
|
80
|
+
|
81
|
+
# Execute a search based on an existing template
|
82
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Search-pattern
|
83
|
+
def search_template_pattern(template, body = nil)
|
84
|
+
JSON.parse(api_post_json("services/rest/index/#{@name}/search/pattern/#{template}", body))
|
85
|
+
end
|
86
|
+
|
87
|
+
# Execute a search based on an existing template
|
88
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Search-template-field
|
89
|
+
def search_template_field(template, body = nil)
|
90
|
+
JSON.parse(api_post_json("services/rest/index/#{@name}/search/field/#{template}", body))
|
91
|
+
end
|
92
|
+
|
93
|
+
# Create/update a search template (pattern search)
|
94
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Search-template-pattern-set
|
95
|
+
def search_store_template_pattern(template, body = nil)
|
96
|
+
api_put_json "services/rest/index/#{@name}/search/pattern/#{template}", body
|
97
|
+
end
|
98
|
+
|
99
|
+
# Create/update a search template (field search)
|
100
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Search-template-field-set
|
101
|
+
def search_store_template_field(template, body = nil)
|
102
|
+
api_put_json"services/rest/index/#{@name}/search/field/#{template}", body
|
103
|
+
end
|
104
|
+
|
105
|
+
# Delete a search template matching the given name
|
106
|
+
# http://github.com/jaeksoft/opensearchserver/wiki/Search-template-delete
|
107
|
+
def search_template_delete(template)
|
108
|
+
api_delete "services/rest/index/#{@name}/search/template/#{template}"
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def api_get (method, params={})
|
114
|
+
RestClient.get("#{@host}/#{method}", {:accept => :json, :params => params})
|
115
|
+
end
|
116
|
+
|
117
|
+
def api_post (method, body="", params={})
|
118
|
+
RestClient.post("#{@host}/#{method}", body, {:params => params.merge(@credentials)})
|
119
|
+
end
|
120
|
+
|
121
|
+
def api_post_json (method, body="", params={})
|
122
|
+
RestClient.post("#{@host}/#{method}", body.to_json, {:accept => :json, :content_type => :json, :params => params.merge(@credentials)})
|
123
|
+
end
|
124
|
+
|
125
|
+
def api_put (method, body="", params={})
|
126
|
+
RestClient.put("#{@host}/#{method}", body, {:params => params.merge(@credentials)})
|
127
|
+
end
|
128
|
+
|
129
|
+
def api_put_json (method, body="", params={})
|
130
|
+
RestClient.put("#{@host}/#{method}", body.to_json, {:accept => :json, :content_type => :json, :params => params.merge(@credentials)})
|
131
|
+
end
|
132
|
+
|
133
|
+
def api_delete (method, params={})
|
134
|
+
RestClient.delete("#{@host}/#{method}", {:params => params.merge(@credentials)})
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
class Field
|
140
|
+
attr_accessor :name, :value, :boost
|
141
|
+
def initialize(name, value, boost=1.0)
|
142
|
+
@name = name
|
143
|
+
@value = value
|
144
|
+
@boost =boost
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
class Document < Field
|
149
|
+
attr_accessor :lang, :fields
|
150
|
+
def initialize(lang ='ENGLISH')
|
151
|
+
@lang = lang
|
152
|
+
@fields = Array.new
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
data/oss_rb.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'oss_rb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "oss_rb"
|
8
|
+
spec.version = Oss::VERSION
|
9
|
+
spec.authors = ["Ori Pekelman", "Emmanuel Keller"]
|
10
|
+
spec.email = ["ori@pekelman.com", "ekeller@open-search-server.com"]
|
11
|
+
spec.description = %q{OpenSearchServer Ruby Client}
|
12
|
+
spec.summary = %q{OpenSearchServer Ruby Client}
|
13
|
+
spec.homepage = "http://www.open-search-server.com/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency 'activesupport'
|
24
|
+
spec.add_dependency 'rest-client'
|
25
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
|
3
|
+
describe Oss::Index do
|
4
|
+
before(:all) do
|
5
|
+
@index_name = "test_oss_rb"
|
6
|
+
@index = Oss::Index.new(@index_name, ENV['OSS_RB_URL'], ENV['OSS_RB_LOGIN'], ENV['OSS_RB_KEY'])
|
7
|
+
@index.delete!
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#OssIndex(name)' do
|
11
|
+
it "should not work with no index name" do
|
12
|
+
expect { Oss::Index.new() }.to raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#Non existing methods' do
|
17
|
+
it "should not work" do
|
18
|
+
expect {@index.send(:api_get,"plop")}.to raise_error
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#OssIndex' do
|
23
|
+
it "fetches the OssIndex client object" do
|
24
|
+
@index.should be_an_instance_of(Oss::Index)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#delete index' do
|
29
|
+
it "delete index" do
|
30
|
+
index = Oss::Index.new("DELETE_ME", ENV['OSS_RB_URL'], ENV['OSS_RB_LOGIN'], ENV['OSS_RB_KEY'])
|
31
|
+
index.create('EMPTY_INDEX')
|
32
|
+
index.list.should include "DELETE_ME"
|
33
|
+
index.delete!
|
34
|
+
index.list.should_not include "DELETE_ME"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#create index' do
|
39
|
+
it "create index" do
|
40
|
+
@index.create('WEB_CRAWLER') unless @index.list.include? @index_name
|
41
|
+
@index.list.should include @index_name
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#set fields' do
|
46
|
+
it 'set fields' do
|
47
|
+
params = {
|
48
|
+
'name' => 'id',
|
49
|
+
'stored' => 'YES',
|
50
|
+
'indexed' => 'YES'
|
51
|
+
}
|
52
|
+
@index.set_field(params)
|
53
|
+
params = {
|
54
|
+
'name' => 'user',
|
55
|
+
'analyzer' => 'StandardAnalyzer',
|
56
|
+
'stored' => 'YES',
|
57
|
+
'indexed' => 'YES'
|
58
|
+
}
|
59
|
+
@index.set_field(params)
|
60
|
+
@index.set_field_default_unique('user', 'id')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#index docs' do
|
65
|
+
it "create index, set fields, index docs" do
|
66
|
+
@index.set_field( {
|
67
|
+
'name' => 'user',
|
68
|
+
'analyzer' => 'StandardAnalyzer',
|
69
|
+
'stored' => 'YES',
|
70
|
+
'indexed' => 'YES'
|
71
|
+
})
|
72
|
+
@index.set_field( {
|
73
|
+
'name' => 'id',
|
74
|
+
'stored' => 'YES',
|
75
|
+
'indexed' => 'YES'
|
76
|
+
})
|
77
|
+
@index.set_field_default_unique('user', 'id')
|
78
|
+
|
79
|
+
(1..15).each do |i|
|
80
|
+
doc = Oss::Document.new()
|
81
|
+
doc.fields << Oss::Field.new('id', "#{i}")
|
82
|
+
doc.fields << Oss::Field.new('user', "john#{i}")
|
83
|
+
@index.documents << doc
|
84
|
+
end
|
85
|
+
|
86
|
+
@index.index!
|
87
|
+
params = {
|
88
|
+
'query' => 'user:j*',
|
89
|
+
'start' => 0,
|
90
|
+
'rows' => 10,
|
91
|
+
"returnedFields" => ['id', 'user']
|
92
|
+
}
|
93
|
+
result= @index.search_pattern(params);
|
94
|
+
result['numFound'].should == 15
|
95
|
+
result['documents'].length.should == 10
|
96
|
+
|
97
|
+
@index.search_store_template_pattern('patternsearch', params);
|
98
|
+
result = @index.search_template_pattern('patternsearch', params);
|
99
|
+
result['numFound'].should == 15
|
100
|
+
result['documents'].length.should == 10
|
101
|
+
|
102
|
+
@index.search_template_delete('search');
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#delete fields' do
|
107
|
+
it 'set fields, delete fields' do
|
108
|
+
@index.delete_field('host')
|
109
|
+
@index.delete_field('subhost')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#delete document by value' do
|
114
|
+
it 'index docs, delete document by value' do
|
115
|
+
@index.delete_document_by_value('id', 1, 2, 3)
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#delete document by query' do
|
119
|
+
it 'index docs, delete document by query' do
|
120
|
+
@index.delete_document_by_query('user:john4')
|
121
|
+
@index.delete_document_by_query('user:john5')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oss_rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ori Pekelman
|
8
|
+
- Emmanuel Keller
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: activesupport
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rest-client
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: OpenSearchServer Ruby Client
|
71
|
+
email:
|
72
|
+
- ori@pekelman.com
|
73
|
+
- ekeller@open-search-server.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- docs/retours_api.txt
|
85
|
+
- docs/retours_schema_api.txt
|
86
|
+
- examples/index.rb
|
87
|
+
- lib/oss_rb.rb
|
88
|
+
- lib/oss_rb/version.rb
|
89
|
+
- oss_rb.gemspec
|
90
|
+
- spec/api/api_v1_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
homepage: http://www.open-search-server.com/
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.0.4
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: OpenSearchServer Ruby Client
|
116
|
+
test_files:
|
117
|
+
- spec/api/api_v1_spec.rb
|
118
|
+
- spec/spec_helper.rb
|