oss_rb 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/README.md +88 -2
- data/lib/oss_rb/version.rb +1 -1
- data/lib/oss_rb.rb +2 -2
- data/oss_rb.gemspec +4 -2
- data/spec/api/api_v1_spec.rb +26 -7
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44e31bb9abb8bfdefd8df1b447a0916377be69f1
|
4
|
+
data.tar.gz: d006e029fa82add99b9fb828be1f412b45f9f6a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 274130699bfb6caec39bd1cf11ffa2eb30f8cbdcfa827ddb072a9779057f00b731585e3120b740f5f0a9c3b18f5a26e180799ff928e315eef8dacf0d1022dfe3
|
7
|
+
data.tar.gz: 63054303ba6c27f74d9bcc0557228155dd49866e2338d55be95416e750f85989191ba3cdff898b0404fdf71e7adb27ef5d60c2c9ee99ba0ac6696137cdf85883
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
oss_rb (0.0
|
4
|
+
oss_rb (0.1.0)
|
5
5
|
activesupport
|
6
6
|
rest-client
|
7
7
|
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
multi_json (~> 1.3)
|
15
15
|
thread_safe (~> 0.1)
|
16
16
|
tzinfo (~> 0.3.37)
|
17
|
-
atomic (1.1.
|
17
|
+
atomic (1.1.13)
|
18
18
|
coderay (1.0.9)
|
19
19
|
diff-lcs (1.2.4)
|
20
20
|
ffi (1.3.1)
|
@@ -34,7 +34,7 @@ GEM
|
|
34
34
|
libnotify (~> 0.1.3)
|
35
35
|
rb-inotify (>= 0.5.1)
|
36
36
|
spoon (~> 0.0.1)
|
37
|
-
i18n (0.6.
|
37
|
+
i18n (0.6.5)
|
38
38
|
libnotify (0.1.4)
|
39
39
|
ffi (>= 0.6.2)
|
40
40
|
listen (1.2.2)
|
@@ -43,9 +43,9 @@ GEM
|
|
43
43
|
rb-kqueue (>= 0.2)
|
44
44
|
lumberjack (1.0.4)
|
45
45
|
method_source (0.8.1)
|
46
|
-
mime-types (1.
|
46
|
+
mime-types (1.25)
|
47
47
|
minitest (4.7.5)
|
48
|
-
multi_json (1.7.
|
48
|
+
multi_json (1.7.9)
|
49
49
|
net-http-spy (0.2.1)
|
50
50
|
pry (0.9.12.2)
|
51
51
|
coderay (~> 1.0.5)
|
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# oss_rb
|
2
2
|
|
3
|
+
A Ruby Client for OpenSearchServer
|
3
4
|
|
4
|
-
|
5
|
+
## Requirement
|
5
6
|
|
7
|
+
A running OpenSearchServer instance (>= v1.5)
|
8
|
+
http://www.open-search-server.com
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
@@ -20,7 +23,90 @@ Or install it yourself as:
|
|
20
23
|
|
21
24
|
## Usage
|
22
25
|
|
23
|
-
|
26
|
+
Obtain a client instance
|
27
|
+
```ruby
|
28
|
+
index = Oss::Index.new('my_index', 'http://localhost:8080')
|
29
|
+
```
|
30
|
+
|
31
|
+
Create an index
|
32
|
+
```ruby
|
33
|
+
index.create 'EMPTY_INDEX'
|
34
|
+
```
|
35
|
+
|
36
|
+
Create some fields
|
37
|
+
```ruby
|
38
|
+
index.set_field({'name' => 'id', 'indexed' => 'YES'})
|
39
|
+
index.set_field(
|
40
|
+
{ 'name' => 'name',
|
41
|
+
'analyzer' => 'StandardAnalyzer',
|
42
|
+
'stored' => 'YES',
|
43
|
+
'indexed' => 'YES'
|
44
|
+
}
|
45
|
+
)
|
46
|
+
```
|
47
|
+
|
48
|
+
Set the default field, and the primary key
|
49
|
+
```ruby
|
50
|
+
index.set_field_default_unique('name', 'id')
|
51
|
+
```
|
52
|
+
|
53
|
+
Put a document in the index
|
54
|
+
```ruby
|
55
|
+
doc = Oss::Document.new
|
56
|
+
doc.fields << Oss::Field.new('id', "1")
|
57
|
+
doc.fields << Oss::Field.new('name', "john smith")
|
58
|
+
index.documents << doc
|
59
|
+
index.index!
|
60
|
+
```
|
61
|
+
|
62
|
+
Ok, time to make a search
|
63
|
+
```ruby
|
64
|
+
result = index.search_field(
|
65
|
+
{ 'query' => 'john',
|
66
|
+
'searchFields' => [ {'field' => 'name', 'phrase'=>true, 'boost' => 1.0} ],
|
67
|
+
'start' => 0,
|
68
|
+
'rows' => 10,
|
69
|
+
'returnedFields' => ['id', 'name']
|
70
|
+
}
|
71
|
+
)
|
72
|
+
```
|
73
|
+
|
74
|
+
It is possible to store a search template
|
75
|
+
```ruby
|
76
|
+
index.search_store_template_field('fieldsearch',
|
77
|
+
{ 'query' => 'john',
|
78
|
+
'searchFields' => [ {'field' => 'name', 'phrase'=>true, 'boost' => 1.0} ],
|
79
|
+
'start' => 0,
|
80
|
+
'rows' => 10,
|
81
|
+
'returnedFields' => ['id', 'name']
|
82
|
+
}
|
83
|
+
)
|
84
|
+
```
|
85
|
+
|
86
|
+
Use the stored search template to make a search
|
87
|
+
```ruby
|
88
|
+
result = index.search_template_field('fieldsearch', {'query' => 'john2'})
|
89
|
+
```
|
90
|
+
|
91
|
+
Deleting a search template
|
92
|
+
```ruby
|
93
|
+
index.search_template_delete('fieldsearch')
|
94
|
+
```
|
95
|
+
|
96
|
+
You may remove documents by value or by query
|
97
|
+
```ruby
|
98
|
+
index.delete_document_by_value('id', 1)
|
99
|
+
index.delete_document_by_query('name:john')
|
100
|
+
```
|
101
|
+
Or remove field
|
102
|
+
```ruby
|
103
|
+
index.delete_field('name')
|
104
|
+
```
|
105
|
+
|
106
|
+
And finally here is how to delete the index
|
107
|
+
```ruby
|
108
|
+
index.delete!
|
109
|
+
```
|
24
110
|
|
25
111
|
## Contributing
|
26
112
|
|
data/lib/oss_rb/version.rb
CHANGED
data/lib/oss_rb.rb
CHANGED
@@ -32,14 +32,14 @@ module Oss
|
|
32
32
|
# Create or update the field defined by the given hash
|
33
33
|
# http://github.com/jaeksoft/opensearchserver/wiki/Field-create-update
|
34
34
|
def set_field(field_params)
|
35
|
-
api_put_json "services/rest/index/#{@name}/field", field_params
|
35
|
+
api_put_json "services/rest/index/#{@name}/field/#{field_params['name']}", field_params
|
36
36
|
end
|
37
37
|
|
38
38
|
# Set the default field and the unique field
|
39
39
|
# http://github.com/jaeksoft/opensearchserver/wiki/Field-set-default-unique
|
40
40
|
def set_field_default_unique(default, unique)
|
41
41
|
params = { 'unique' => unique, 'default' => default }
|
42
|
-
|
42
|
+
api_post "services/rest/index/#{@name}/field", '', params
|
43
43
|
end
|
44
44
|
|
45
45
|
# Delete the field matching the give name
|
data/oss_rb.gemspec
CHANGED
@@ -9,10 +9,12 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Ori Pekelman", "Emmanuel Keller"]
|
10
10
|
spec.email = ["ori@pekelman.com", "ekeller@open-search-server.com"]
|
11
11
|
spec.description = %q{OpenSearchServer Ruby Client}
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.homepage = "
|
12
|
+
spec.summary = %q{A Ruby Client library for OpenSearchServer}
|
13
|
+
spec.homepage = "https://github.com/jaeksoft/oss_rb/"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
+
spec.metadata = { "Issues" => "https://github.com/jaeksoft/oss_rb/issues" }
|
17
|
+
|
16
18
|
spec.files = `git ls-files`.split($/)
|
17
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
data/spec/api/api_v1_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe Oss::Index do
|
|
4
4
|
before(:all) do
|
5
5
|
@index_name = "test_oss_rb"
|
6
6
|
@index = Oss::Index.new(@index_name, ENV['OSS_RB_URL'], ENV['OSS_RB_LOGIN'], ENV['OSS_RB_KEY'])
|
7
|
-
@index.delete!
|
7
|
+
@index.delete! if @index.list.include? @index_name
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '#OssIndex(name)' do
|
@@ -29,16 +29,16 @@ describe Oss::Index do
|
|
29
29
|
it "delete index" do
|
30
30
|
index = Oss::Index.new("DELETE_ME", ENV['OSS_RB_URL'], ENV['OSS_RB_LOGIN'], ENV['OSS_RB_KEY'])
|
31
31
|
index.create('EMPTY_INDEX')
|
32
|
-
index.list.should
|
32
|
+
index.list.should(include, "DELETE_ME")
|
33
33
|
index.delete!
|
34
|
-
index.list.should_not
|
34
|
+
index.list.should_not(include, "DELETE_ME")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
describe '#create index' do
|
39
39
|
it "create index" do
|
40
40
|
@index.create('WEB_CRAWLER') unless @index.list.include? @index_name
|
41
|
-
@index.list.should
|
41
|
+
@index.list.should(include, @index_name)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -77,7 +77,7 @@ describe Oss::Index do
|
|
77
77
|
@index.set_field_default_unique('user', 'id')
|
78
78
|
|
79
79
|
(1..15).each do |i|
|
80
|
-
doc = Oss::Document.new
|
80
|
+
doc = Oss::Document.new
|
81
81
|
doc.fields << Oss::Field.new('id', "#{i}")
|
82
82
|
doc.fields << Oss::Field.new('user', "john#{i}")
|
83
83
|
@index.documents << doc
|
@@ -95,11 +95,30 @@ describe Oss::Index do
|
|
95
95
|
result['documents'].length.should == 10
|
96
96
|
|
97
97
|
@index.search_store_template_pattern('patternsearch', params);
|
98
|
-
result = @index.search_template_pattern('patternsearch',
|
98
|
+
result = @index.search_template_pattern('patternsearch', {'query' => 'user:j*'});
|
99
99
|
result['numFound'].should == 15
|
100
100
|
result['documents'].length.should == 10
|
101
101
|
|
102
|
-
@index.search_template_delete('
|
102
|
+
@index.search_template_delete('patternsearch');
|
103
|
+
|
104
|
+
params = {
|
105
|
+
'query' => 'john1',
|
106
|
+
'searchFields' => [ {'field' => 'user', 'phrase'=>true, 'boost' => 1.0} ],
|
107
|
+
'start' => 0,
|
108
|
+
'rows' => 10,
|
109
|
+
"returnedFields" => ['id', 'user']
|
110
|
+
}
|
111
|
+
result= @index.search_field(params);
|
112
|
+
result['numFound'].should == 1
|
113
|
+
result['documents'].length.should == 1
|
114
|
+
|
115
|
+
@index.search_store_template_field('fieldsearch', params);
|
116
|
+
result = @index.search_template_field('fieldsearch', {'query' => 'john2'});
|
117
|
+
result['numFound'].should == 1
|
118
|
+
result['documents'].length.should == 1
|
119
|
+
|
120
|
+
@index.search_template_delete('fieldsearch');
|
121
|
+
|
103
122
|
end
|
104
123
|
end
|
105
124
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oss_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ori Pekelman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -89,10 +89,11 @@ files:
|
|
89
89
|
- oss_rb.gemspec
|
90
90
|
- spec/api/api_v1_spec.rb
|
91
91
|
- spec/spec_helper.rb
|
92
|
-
homepage:
|
92
|
+
homepage: https://github.com/jaeksoft/oss_rb/
|
93
93
|
licenses:
|
94
94
|
- MIT
|
95
|
-
metadata:
|
95
|
+
metadata:
|
96
|
+
Issues: https://github.com/jaeksoft/oss_rb/issues
|
96
97
|
post_install_message:
|
97
98
|
rdoc_options: []
|
98
99
|
require_paths:
|
@@ -109,10 +110,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
110
|
version: '0'
|
110
111
|
requirements: []
|
111
112
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.1.5
|
113
114
|
signing_key:
|
114
115
|
specification_version: 4
|
115
|
-
summary:
|
116
|
+
summary: A Ruby Client library for OpenSearchServer
|
116
117
|
test_files:
|
117
118
|
- spec/api/api_v1_spec.rb
|
118
119
|
- spec/spec_helper.rb
|