Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
2  lib/escargot.rb
@@ -42,7 +42,7 @@ def self.search_hits(query, options = {}, call_by_instance_method = false)
end
if query.kind_of?(Hash)
- query_dsl = query.delete(:query_dsl)
+ query_dsl = options.delete(:query_dsl)
query = {:query => query} if (query_dsl.nil? || query_dsl)
end
$elastic_search_client.search(query, options)
View
2  lib/tasks/escargot.rake
@@ -28,7 +28,7 @@ namespace :escargot do
end
task :load_all_models do
- models = ActiveRecord::Base.send(:subclasses)
+ models = defined?(ActiveRecord::Base) ? ActiveRecord::Base.send(:subclasses) : []
Dir["#{Rails.root}/app/models/*.rb", "#{Rails.root}/app/models/*/*.rb"].each do |file|
model = File.basename(file, ".*").classify
unless models.include?(model)
View
2  rails/init.rb
@@ -2,7 +2,7 @@
ActiveRecord::Base.class_eval do
include Escargot::ActiveRecordExtensions
-end
+end if defined?(ActiveRecord::Base)
ElasticSearch::Api::Hit.class_eval do
include Escargot::HitExtensions
View
11 test/search_test.rb
@@ -53,10 +53,17 @@ def test_search_without_query_dsl
# putting in the query Hash the option ":query_dsl => false", of course remember to put the term ":query => {your query}"
# to work correctly
- results = User.search(:sort =>[{ :country_code => {:reverse => true }}] , :query => {:term => {:name => "john"}}, :query_dsl => false,:track_scores =>true)
+ results = User.search({:sort =>[{ :country_code => {:reverse => true }}] , :query => {:term => {:name => "john"}}, :track_scores =>true}, :query_dsl => false)
assert_equal results.first.name, 'John the Skinny Too'
end
-
+
+ def test_search_without_query_dsl_with_pagination
+ results = User.search({:sort =>[{:country_code => {:reverse => true}}], :query => {:match_all => true}}, :query_dsl => false, :per_page => 5, :page => 1)
+ assert_equal results.count, 5
+
+ results = User.search({:sort =>[{:country_code => {:reverse => true}}], :query => {:match_all => true}}, :query_dsl => false, :per_page => 5, :page => 2)
+ assert_equal results.count, 1
+ end
def test_facets
assert_equal User.facets(:country_code)[:country_code]["ca"], 2

No commit comments for this range

Something went wrong with that request. Please try again.