Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Search with version should set the version value in options #190

Closed
wants to merge 1 commit into from

3 participants

@gedwards

Adding 'version' to the DSL. Includes unit and integration tests. (thanks for Tire and Elasticsearch!)

@karmi karmi closed this in 2bf5585
@karmi
Owner

Greg, thanks, the delay with merging is embarrasing, sorry. Pushed.

(By the way, I think a better way would be an API like Tire.search 'an_index', version: true do ... end, but it does not matter at the moment. We have to sort out the issue with search params anyway, and transfer the version option there once it's done...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 lib/tire/search.rb
@@ -69,6 +69,10 @@ def fields(*fields)
self
end
+ def version(value)
+ @version = value
+ end
+
def perform
@response = Configuration.client.get(self.url, self.to_json)
if @response.failure?
@@ -97,6 +101,7 @@ def to_hash
request.update( { :size => @size } ) if @size
request.update( { :from => @from } ) if @from
request.update( { :fields => @fields } ) if @fields
+ request.update( { :version => @version } ) if @version
request
end
View
70 test/integration/query_return_version_test.rb
@@ -0,0 +1,70 @@
+require 'test_helper'
+
+module Tire
+
+ class DslVersionIntegrationTest < Test::Unit::TestCase
+ include Test::Integration
+
+ context "DSL Version" do
+
+ setup do
+ Tire.index 'articles-test-ids' do
+ delete
+ create
+
+ store :id => 1, :title => 'One'
+ store :id => 2, :title => 'Two'
+
+ refresh
+ end
+ end
+
+ teardown { Tire.index('articles-test-ids').delete }
+
+ should "returns actual version (non-nil) value for records when 'version' is true" do
+ s = Tire.search('articles-test-ids') do
+ version true
+ query { string 'One' }
+ end
+
+ assert_equal 1, s.results.count
+
+ document = s.results.first
+ assert_equal 'One', document.title
+ assert_equal 1, document._version.to_i
+
+ end
+
+ should "returns a nil version field when 'version' is false" do
+ s = Tire.search('articles-test-ids') do
+ version false
+ query { string 'One' }
+ end
+
+ assert_equal 1, s.results.count
+
+ document = s.results.first
+ assert_equal 'One', document.title
+ assert_equal nil, document._version
+
+ end
+
+ should "returns a nil version field when 'version' is not included" do
+ s = Tire.search('articles-test-ids') do
+ query { string 'One' }
+ end
+
+ assert_equal 1, s.results.count
+
+ document = s.results.first
+ assert_equal 'One', document.title
+ assert_equal nil, document._version
+
+ end
+
+ end
+
+ end
+
+end
+
View
12 test/unit/search_test.rb
@@ -262,6 +262,18 @@ def foo; 'bar'; end
end
+ context "with version" do
+
+ should "set the version value in options" do
+ s = Search::Search.new('index') do
+ version true
+ end
+ hash = MultiJson.decode( s.to_json )
+ assert_equal true, hash['version']
+ end
+
+ end
+
context "with from/size" do
should "set the values in request" do
Something went wrong with that request. Please try again.