Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.