escargot 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -13,7 +13,7 @@ and (if you want to use the **optional** distributed indexing mode) Redis.
13
13
  Usage
14
14
  =======
15
15
 
16
- First, [download and start ElasticSearch](http://www.elasticsearch.com/docs/elasticsearch/setup/installation/) (it's really simple). With the default setup of
16
+ First, [download](http://www.elasticsearch.org/download/) and [start ElasticSearch](http://www.elasticsearch.org/guide/reference/setup/installation.html) (it's really simple). With the default setup of
17
17
  of ElasticSearch (listening to localhost and port 9200) no configuration of the plugin is
18
18
  necessary.
19
19
 
@@ -132,14 +132,14 @@ Pagination
132
132
 
133
133
  Query DSL
134
134
  ----------------
135
- Instead of a string, you can pass a query in ElasticSearch's [Query DSL](http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/)
135
+ Instead of a string, you can pass a query in ElasticSearch's [Query DSL](http://www.elasticsearch.org/guide/reference/query-dsl/)
136
136
  giving you access to the full range of search features.
137
137
 
138
- Bird.search(:match_all => true}
138
+ Bird.search(:match_all => { })
139
139
 
140
140
  Bird.search(:fuzzy => {:name => 'oriale'})
141
141
 
142
- Bird.search(:custom_score => {:query => {:match_all => true}, :script => "random()"})
142
+ Bird.search(:custom_score => {:query => {:match_all => { } }, :script => "random()"})
143
143
 
144
144
  Bird.search(:dis_max => {
145
145
  :tie_breaker => 0.7,
@@ -162,7 +162,27 @@ giving you access to the full range of search features.
162
162
  }
163
163
  }
164
164
  )
165
-
165
+
166
+
167
+ Query DSL with API Search
168
+ ----------------
169
+ Any query Hash in Escargot a is a Query DSL by default, so anything you put in the first param is wrapper with
170
+ the term "query", but sometimes you need puts some params out Query DSL, using options of [API Search](http://www.elasticsearch.org/guide/reference/api/search/), you can do this
171
+ using the option *:query_dsl => false* in the query Hash, of course remember to put the term *:query => {your query}* to work correctly
172
+
173
+ User.search (
174
+ :track_scores =>true,
175
+ :sort =>[ {
176
+ :name => {:reverse => true }
177
+ }
178
+ ],
179
+ :query => {
180
+ :term => {:name => "john"}
181
+ },
182
+ :query_dsl => false
183
+ )
184
+
185
+
166
186
  Facets
167
187
  ----------------
168
188
 
@@ -234,7 +254,7 @@ If you want the search to be insensitive to accents and other diacritics:
234
254
  end
235
255
 
236
256
  The full list of available options for index creation is documented at
237
- [http://www.elasticsearch.com/docs/elasticsearch/index_modules/](http://www.elasticsearch.com/docs/elasticsearch/index_modules/)
257
+ [http://www.elasticsearch.org/guide/reference/index-modules/](http://www.elasticsearch.org/guide/reference/index-modules/)
238
258
 
239
259
  Mapping options
240
260
  ----------------
@@ -259,7 +279,7 @@ Some examples:
259
279
  end
260
280
 
261
281
 
262
- See the [ElasticSearch Documentation](http://www.elasticsearch.com/docs/elasticsearch/mapping/) for mappings.
282
+ See the [ElasticSearch Documentation](http://www.elasticsearch.org/guide/reference/mapping/) for mappings.
263
283
 
264
284
  Distributed indexing
265
285
  =======
data/lib/escargot.rb CHANGED
@@ -42,7 +42,8 @@ module Escargot
42
42
  end
43
43
 
44
44
  if query.kind_of?(Hash)
45
- query = {:query => query}
45
+ query_dsl = query.delete(:query_dsl)
46
+ query = {:query => query} if (query_dsl.nil? || query_dsl)
46
47
  end
47
48
  $elastic_search_client.search(query, options)
48
49
  end
@@ -68,7 +68,7 @@ module Escargot
68
68
  fields_list = [fields_list] unless fields_list.kind_of?(Array)
69
69
 
70
70
  if !options[:query]
71
- options[:query] = {:match_all => true}
71
+ options[:query] = {:match_all => { } }
72
72
  elsif options[:query].kind_of?(String)
73
73
  options[:query] = {:query_string => {:query => options[:query]}}
74
74
  end
@@ -1,3 +1,3 @@
1
1
  module Escargot
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -17,7 +17,11 @@ class NrtEnqueue < Test::Unit::TestCase
17
17
  User.create(:name => 'Peter the Young')
18
18
  User.create(:name => 'Peter the Old')
19
19
  User.create(:name => 'Bob the Skinny')
20
- User.create(:name => 'Jamie the Flying Machine')
20
+ User.create(:name => 'Jamie the Flying Machine')
21
+
22
+ # the Resque tasks have not run yet, so there should be nothing in the index
23
+ # but now run the Resque tasks and check that the index is good for each test
24
+ Resque.run!
21
25
  end
22
26
 
23
27
  def teardown
@@ -26,9 +30,6 @@ class NrtEnqueue < Test::Unit::TestCase
26
30
  end
27
31
 
28
32
  def test_document_creation
29
- # the Resque tasks have not run yet, so there should be nothing in the index
30
- # but now run the Resque tasks and check that the index is good
31
- Resque.run!
32
33
  User.refresh_index
33
34
 
34
35
  assert_equal 5, User.search("*").total_entries
@@ -38,10 +39,8 @@ class NrtEnqueue < Test::Unit::TestCase
38
39
  end
39
40
 
40
41
  def test_document_updates
41
- # now run the Resque tasks and check that the index is good
42
- Resque.run!
43
42
  User.refresh_index
44
-
43
+
45
44
  assert_equal 5, User.search("*").total_entries
46
45
 
47
46
  # make a change in a document
@@ -62,8 +61,6 @@ class NrtEnqueue < Test::Unit::TestCase
62
61
  end
63
62
 
64
63
  def test_document_deletes
65
- # now run the Resque tasks and check that the index is good
66
- Resque.run!
67
64
  User.refresh_index
68
65
 
69
66
  assert_equal User.search("*").total_entries, 5
data/test/search_test.rb CHANGED
@@ -46,6 +46,17 @@ class BasicSearchTest < Test::Unit::TestCase
46
46
  assert_equal results.total_entries, 2
47
47
  assert_equal User.search_count(:term => {:name => "john"}), 2
48
48
  end
49
+
50
+ def test_search_without_query_dsl
51
+ # By default in Escargot any query Hash is a Query DSL, so anything you put in the first param is wrapper with
52
+ # this "query = {:query => {query}}", but sometimes if you need puts some params OUT Query DSL you can do this
53
+ # putting in the query Hash the option ":query_dsl => false", of course remember to put the term ":query => {your query}"
54
+ # to work correctly
55
+
56
+ results = User.search(:sort =>[{ :country_code => {:reverse => true }}] , :query => {:term => {:name => "john"}}, :query_dsl => false,:track_scores =>true)
57
+ assert_equal results.first.name, 'John the Skinny Too'
58
+ end
59
+
49
60
 
50
61
  def test_facets
51
62
  assert_equal User.facets(:country_code)[:country_code]["ca"], 2
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escargot
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Angel Faus
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-03 00:00:00 -03:00
18
+ date: 2011-04-05 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency