RUBY-564 Support for (hashed, text, 2dsphere) index types #170

Merged
merged 1 commit into from Mar 12, 2013

Conversation

Projects
None yet
3 participants
@estolfo
Contributor

estolfo commented Mar 7, 2013

In Mongo module: Added in constants for hashed, text, and 2dsphere index types. Added array constant for index types.

Added in conversion of bucket_size to bucketSize for use with geoHaystack indexes in the create_index and ensure_index methods on a collection.

Included hashed, text and 2dsphere in the list of valid index types when creating an index.

Wrote tests that ensure 2dsphere, text, geoHaystack, and hashed indexes can be created. NOTE: the test on a text index is commented out because the server must be started with 'setParameter textSearchEnabled=1'

Updated documentation for all affected methods, specifically references to index types as "directions".

@brandonblack

This comment has been minimized.

Show comment
Hide comment
@brandonblack

brandonblack Mar 8, 2013

Contributor

Great work @estolfo. Looks good to me, :shipit:

Contributor

brandonblack commented Mar 8, 2013

Great work @estolfo. Looks good to me, :shipit:

@TylerBrock

View changes

lib/mongo.rb
GEOHAYSTACK = 'geoHaystack'
+ TEXT = 'text'
+ HASHED = 'hashed'

This comment has been minimized.

@TylerBrock

TylerBrock Mar 11, 2013

Contributor

We could make these symbols.

@TylerBrock

TylerBrock Mar 11, 2013

Contributor

We could make these symbols.

This comment has been minimized.

@TylerBrock

TylerBrock Mar 11, 2013

Contributor

Lets make an array of all the possible index types for easier validation.

INDEX_TYPES = [ASCENDING, DESCENDING...]

@TylerBrock

TylerBrock Mar 11, 2013

Contributor

Lets make an array of all the possible index types for easier validation.

INDEX_TYPES = [ASCENDING, DESCENDING...]

@TylerBrock

View changes

lib/mongo/collection.rb
@@ -1017,11 +1022,14 @@ def parse_index_spec(spec)
end
elsif spec.is_a?(Array) && spec.all? {|field| field.is_a?(Array) }
spec.each do |f|
- if [Mongo::ASCENDING, Mongo::DESCENDING, Mongo::GEO2D, Mongo::GEOHAYSTACK].include?(f[1])
+ if [Mongo::ASCENDING, Mongo::DESCENDING, Mongo::GEO2D, Mongo::GEO2DSPHERE, Mongo::GEOHAYSTACK,
+ Mongo::TEXT, Mongo::HASHED].include?(f[1])
field_spec[f[0].to_s] = f[1]

This comment has been minimized.

@TylerBrock

TylerBrock Mar 11, 2013

Contributor

Mongo::INDEX_TYPES.include?(f[1]) given the above change to add the array is made.

@TylerBrock

TylerBrock Mar 11, 2013

Contributor

Mongo::INDEX_TYPES.include?(f[1]) given the above change to add the array is made.

@TylerBrock

View changes

lib/mongo/collection.rb
- "should be one of Mongo::ASCENDING (1), Mongo::DESCENDING (-1) or Mongo::GEO2D ('2d')."
+ "should be one of Mongo::ASCENDING (1), Mongo::DESCENDING (-1), Mongo::GEO2D ('2d'),
+ Mongo::GEOHAYSTACK ('geoHaystack') or Mongo::GEO2DSPHERE ('2dsphere'), Mongo::TEXT ('text') or
+ Mongo::HASHED ('hashed')."
end

This comment has been minimized.

@TylerBrock

TylerBrock Mar 11, 2013

Contributor

This should be a here doc or a string concatenation.

@TylerBrock

TylerBrock Mar 11, 2013

Contributor

This should be a here doc or a string concatenation.

- "should be one of Mongo::ASCENDING (1), Mongo::DESCENDING (-1) or Mongo::GEO2D ('2d')."
+ "should be one of Mongo::ASCENDING (#{Mongo::ASCENDING}), Mongo::DESCENDING (#{Mongo::DESCENDING}), " +
+ "Mongo::GEOHAYSTACK ('#{Mongo::GEOHAYSTACK}'), Mongo::GEO2DSPHERE ('#{Mongo::GEO2DSPHERE}'), " +
+ "Mongo::TEXT ('#{Mongo::TEXT}'), or Mongo::HASHED ('#{Mongo::HASHED}')"

This comment has been minimized.

@TylerBrock

TylerBrock Mar 12, 2013

Contributor

How about "should be one of #{INDEX_TYPES.inspect}"

@TylerBrock

TylerBrock Mar 12, 2013

Contributor

How about "should be one of #{INDEX_TYPES.inspect}"

This comment has been minimized.

@estolfo

estolfo Mar 12, 2013

Contributor

that works, but it'll only print out the server index type labels, which might not be very informative in the case of 1 and -1
What do you think?

@estolfo

estolfo Mar 12, 2013

Contributor

that works, but it'll only print out the server index type labels, which might not be very informative in the case of 1 and -1
What do you think?

This comment has been minimized.

@TylerBrock

TylerBrock Mar 12, 2013

Contributor

Users don't need to know what the values of the types are to use this feature. ASCENDING, DESCENDING, etc are 1000x more informative than 1 and -1 in my opinion.

@TylerBrock

TylerBrock Mar 12, 2013

Contributor

Users don't need to know what the values of the types are to use this feature. ASCENDING, DESCENDING, etc are 1000x more informative than 1 and -1 in my opinion.

This comment has been minimized.

@estolfo

estolfo Mar 12, 2013

Contributor

That's what I'm saying - if you print #{INDEX_TYPES.inspect}, it'll print [1, -1, "2d", "2dsphere", "geoHaystack", "text", "hashed"]
which I don't think is great.

@estolfo

estolfo Mar 12, 2013

Contributor

That's what I'm saying - if you print #{INDEX_TYPES.inspect}, it'll print [1, -1, "2d", "2dsphere", "geoHaystack", "text", "hashed"]
which I don't think is great.

This comment has been minimized.

@TylerBrock

TylerBrock Mar 12, 2013

Contributor

OK, LGTM.

@TylerBrock

TylerBrock Mar 12, 2013

Contributor

OK, LGTM.

estolfo added a commit that referenced this pull request Mar 12, 2013

Merge pull request #170 from estolfo/index_tests
RUBY-564 Support for (hashed, text, 2dsphere) index types

@estolfo estolfo merged commit 6b80321 into mongodb:master Mar 12, 2013

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment