slingshot-rb 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -11,7 +11,7 @@ RESTful database communicating by JSON over HTTP, based on [Lucene](http://lucen
11
11
  written in Java. It manages to very simple and very powerful at the same time.
12
12
  You should seriously consider it to power search in your Ruby applications:
13
13
  it will deliver all the features you want — and many more you may have not
14
- imagined yet (native geo search? histogram facets?)
14
+ imagined yet (native geo search? histogram facets for dates?)
15
15
 
16
16
  _Slingshot_ currently allows basic operation with the index and searching. More is planned.
17
17
 
@@ -21,9 +21,9 @@ Installation
21
21
 
22
22
  First, you need a running _ElasticSearch_ server. Thankfully, it's easy. Let's define easy:
23
23
 
24
- $ curl -L -o elasticsearch-0.14.4.tar.gz http://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.14.4.tar.gz
25
- $ tar -zxvf elasticsearch-0.14.4.tar.gz
26
- $ ./elasticsearch-0.14.4/bin/elasticsearch -f
24
+ $ curl -k -L -o elasticsearch-0.15.0.tar.gz http://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.15.0.tar.gz
25
+ $ tar -zxvf elasticsearch-0.15.0.tar.gz
26
+ $ ./elasticsearch-0.15.0/bin/elasticsearch -f
27
27
 
28
28
  OK, easy. Now, install the gem via Rubygems:
29
29
 
@@ -40,9 +40,10 @@ Usage
40
40
  -----
41
41
 
42
42
  Currently, you can use _Slingshot_ via the DSL (eg. by extending your class with it).
43
- Plans for full ActiveModel integration (and other convenience layers) are in progress.
43
+ Plans for full ActiveModel integration (and other convenience layers) are in progress
44
+ (see the [`activemodel`](https://github.com/karmi/slingshot/compare/activemodel) branch).
44
45
 
45
- To kick the tiers, require the gem in an IRB session or a Ruby script
46
+ To kick the tires, require the gem in an IRB session or a Ruby script
46
47
  (note that you can run the full example from [`examples/dsl.rb`](https://github.com/karmi/slingshot/blob/master/examples/dsl.rb)):
47
48
 
48
49
  require 'rubygems'
@@ -112,7 +113,9 @@ We can display the full query JSON:
112
113
  puts s.to_json
113
114
  # {"facets":{"current-tags":{"terms":{"field":"tags"}},"global-tags":{"global":true,"terms":{"field":"tags"}}},"sort":[{"title":"desc"}],"query":{"terms":{"tags":["ruby"]}}}
114
115
 
115
- See, a Ruby DSL for this thing is kinda handy? We can query _ElasticSearch_ manually with `curl`, simply:
116
+ See, a Ruby DSL for this thing is kinda handy?
117
+
118
+ You can display the corresponding `curl` command easily:
116
119
 
117
120
  puts s.to_curl
118
121
  # curl -X POST "http://localhost:9200/articles/_search?pretty=true" -d '{"facets":{"current-tags":{"terms":{"field":"tags"}},"global-tags":{"global":true,"terms":{"field":"tags"}}},"sort":[{"title":"desc"}],"query":{"terms":{"tags":["ruby"]}}}'
@@ -128,7 +131,7 @@ Currently, _Slingshot_ supports only a limited subset of vast _ElasticSearch_ [S
128
131
  * [Querying](https://github.com/karmi/slingshot/blob/master/examples/dsl.rb) the index with the `query_string`, `term` and `terms` types of queries
129
132
  * Sorting the results by `fields`
130
133
  * Retrieving a _terms_ type of [facets](http://www.elasticsearch.org/guide/reference/api/search/facets/index.html) -- other types are high priority
131
- * Returning just specific fields from documents
134
+ * Returning just specific `fields` from documents
132
135
  * Paging with `from` and `size` query options
133
136
 
134
137
  See the [`examples/dsl.rb`](blob/master/examples/dsl.rb).
@@ -145,12 +148,13 @@ Todo & Plans
145
148
 
146
149
  In order of importance:
147
150
 
148
- * Seamless _ActiveModel_ compatibility for easy usage in _Rails_ applications (this also means nearly full _ActiveRecord_ compatibility)
151
+ * Seamless _ActiveModel_ compatibility for easy usage in _Rails_ applications (this also means nearly full _ActiveRecord_ compatibility). See the [`activemodel`](https://github.com/karmi/slingshot/compare/activemodel) branch
149
152
  * Seamless [will_paginate](https://github.com/mislav/will_paginate) compatibility for easy pagination
153
+ * [Mapping](http://www.elasticsearch.org/guide/reference/mapping/) definition for models
154
+ * Proper RDoc annotations for the source code
155
+ * Dual interface: allow to simply pass queries/options for _ElasticSearch_ as a Hash in any method
150
156
  * [Histogram](http://www.elasticsearch.org/guide/reference/api/search/facets/histogram-facet.html) facets
151
157
  * Seamless support for [auto-updating _river_ index](http://www.elasticsearch.org/guide/reference/river/couchdb.html) for _CouchDB_ `_changes` feed
152
- * [Mapping](http://www.elasticsearch.org/guide/reference/mapping/) management
153
- * Proper RDoc annotations for the source code
154
158
  * Infrastructure for query filters
155
159
  * [Range](http://www.elasticsearch.org/guide/reference/query-dsl/range-filter.html) filters and queries
156
160
  * [Geo Filters](http://www.elasticsearch.org/blog/2010/08/16/geo_location_and_search.html) for queries
@@ -160,7 +164,7 @@ In order of importance:
160
164
  * [Analyze](http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze.html) API support
161
165
  * [Highligting](http://www.elasticsearch.org/guide/reference/api/search/highlighting.html) support
162
166
  * [Bulk](http://www.elasticsearch.org/guide/reference/api/bulk.html) API
163
- * Embedded webserver to display cluster statistics and allow easy searches
167
+ * Embedded webserver to display statistics and to allow easy searches
164
168
 
165
169
 
166
170
  Other Clients
@@ -13,12 +13,17 @@ module Slingshot
13
13
  false
14
14
  end
15
15
 
16
- def create
17
- Configuration.client.post "#{Configuration.url}/#{@name}", ''
16
+ def create(options={})
17
+ # http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html
18
+ Configuration.client.post "#{Configuration.url}/#{@name}", Yajl::Encoder.encode(options)
18
19
  rescue
19
20
  false
20
21
  end
21
22
 
23
+ def mapping
24
+ JSON.parse( Configuration.client.get("#{Configuration.url}/#{@name}/_mapping") )[@name]
25
+ end
26
+
22
27
  def store(*args)
23
28
  # TODO: Infer type from the document (hash property, method)
24
29
 
@@ -1,3 +1,3 @@
1
1
  module Slingshot
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ module Slingshot
4
+
5
+ class IndexMappingTest < Test::Unit::TestCase
6
+ include Test::Integration
7
+
8
+ context "Default mapping" do
9
+ teardown { Slingshot.index('mapped-index').delete }
10
+
11
+ should "create and return the default mapping" do
12
+
13
+ index = Slingshot.index 'mapped-index' do
14
+ create
15
+ store :article, :title => 'One'
16
+ refresh
17
+ end
18
+ sleep 1
19
+
20
+ assert_equal 'string', index.mapping['article']['properties']['title']['type'], index.mapping.inspect
21
+ assert_nil index.mapping['article']['properties']['title']['boost'], index.mapping.inspect
22
+ end
23
+ end
24
+
25
+ context "Creating index with mapping" do
26
+ teardown { Slingshot.index('mapped-index').delete; sleep 1 }
27
+
28
+ should "create the specified mapping" do
29
+
30
+ index = Slingshot.index 'mapped-index' do
31
+ create :mappings => { :article => { :properties => { :title => { :type => 'string', :boost => 2.0, :store => 'yes' } } } }
32
+ end
33
+ sleep 1
34
+
35
+ # p index.mapping
36
+ assert_equal 2.0, index.mapping['article']['properties']['title']['boost'], index.mapping.inspect
37
+ assert_equal 'yes', index.mapping['article']['properties']['title']['store'], index.mapping.inspect
38
+
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -37,6 +37,44 @@ module Slingshot
37
37
  assert_nothing_raised { assert @index.refresh }
38
38
  end
39
39
 
40
+ context "mapping" do
41
+
42
+ should "create index with mapping" do
43
+ Configuration.client.expects(:post).returns('{"ok":true,"acknowledged":true}')
44
+
45
+ assert @index.create :settings => { :number_of_shards => 1 },
46
+ :mappings => { :article => {
47
+ :properties => {
48
+ :title => { :boost => 2.0,
49
+ :type => 'string',
50
+ :store => 'yes',
51
+ :analyzer => 'snowball' }
52
+ }
53
+ }
54
+ }
55
+ end
56
+
57
+ should "return the mapping" do
58
+ json =<<-JSON
59
+ {
60
+ "dummy" : {
61
+ "article" : {
62
+ "properties" : {
63
+ "title" : { "type" : "string", "boost" : 2.0 },
64
+ "category" : { "type" : "string", "analyzed" : "no" }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ JSON
70
+ Configuration.client.stubs(:get).returns(json)
71
+
72
+ assert_equal 'string', @index.mapping['article']['properties']['title']['type']
73
+ assert_equal 2.0, @index.mapping['article']['properties']['title']['boost']
74
+ end
75
+
76
+ end
77
+
40
78
  context "when storing" do
41
79
 
42
80
  should "properly set type from args" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slingshot-rb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Karel Minarik
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-09 00:00:00 +01:00
18
+ date: 2011-03-02 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -174,6 +174,7 @@ files:
174
174
  - test/fixtures/articles/4.json
175
175
  - test/fixtures/articles/5.json
176
176
  - test/integration/facets_test.rb
177
+ - test/integration/index_mapping_test.rb
177
178
  - test/integration/index_store_test.rb
178
179
  - test/integration/query_string_test.rb
179
180
  - test/integration/results_test.rb
@@ -233,6 +234,7 @@ test_files:
233
234
  - test/fixtures/articles/4.json
234
235
  - test/fixtures/articles/5.json
235
236
  - test/integration/facets_test.rb
237
+ - test/integration/index_mapping_test.rb
236
238
  - test/integration/index_store_test.rb
237
239
  - test/integration/query_string_test.rb
238
240
  - test/integration/results_test.rb