Skip to content

Instantly share code, notes, and snippets.

@darrenterhune
Created October 29, 2010 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save darrenterhune/653125 to your computer and use it in GitHub Desktop.
Save darrenterhune/653125 to your computer and use it in GitHub Desktop.
Example bitfield calculations in ruby with thinking-sphinx
# For bitfield calculations...
#------------------------------------------------------------------------
# flag | sale | lease | charter | hide | vertical
#------------------------------------------------------------------------
# booleans | 1 | 1 | 1 | 1 | 1
#------------------------------------------------------------------------
# position | 1 | 2 | 3 | 4 | 5
#------------------------------------------------------------------------
# value | 1 | 2 | 4 | 8 | 16
#
# bitvalues (to calc: add the values where boolean = 1)
#------------------------------------------------------------------------
# sale,lease,charter,hide = 15
# sale,lease,charter = 7
# sale,charter = 5
#
# To search {:charter => true} in this example bitvalues would be: 4,5,6,7,12,13,14,15 so....
MyModel.search('whadup', :with => {:bitfield => [4,5,6,7,12,13,14,15]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment