Skip to content


Merging data can make things easier

Scotchel.com has options for users to select information about themselves (e.g. age, relationship status, etc.) Originally I kept two of those fields, gender and orientation, as separate entities. That was working fine until I wanted to start searching for certain types of people.

Let’s assume there’s a straight girl that wants to find guys that would be interested in her. Obviously her pool of candidates includes straight guys. However, it’s also entirely possible that it would include bisexual guys. After all, they’re interested in girls too.

It gets even more complicated with bisexual folks. If you’re a bisexual guy you may be interested in gay guys, bisexual guys, straight girls, and bisexual girls. If you have gender and orientation as separate fields in your database you’re suddenly searching on 8 different elements:

  • gender = “male” AND orientation = “gay” OR
  • gender = “male” AND orientation = “bisexual” OR
  • gender = “female” AND orientation = “straight” OR
  • gender = “female” AND orientation = “bisexual”

Yikes. I came to realize that the easier way to do this would be to merge gender and orientation into one über field (gender+orientation). In effect this allows you to always halve the number of elements you have to search on.

I created a quick logic table to figure out how I could get it to work:

Straight Guys (1) Gay Guys (3)
Bisexual Guys (5)
Straight Girls (2)
Gay Girls (4)
Bisexual Girls (6)
Straight Guys (1)
xmark xmark xmark checkmark xmark checkmark
Gay Guys (3) xmark checkmark checkmark xmark xmark xmark
Bisexual Guys (5) xmark checkmark checkmark checkmark xmark checkmark
Straight Girls (2) checkmark xmark checkmark xmark xmark xmark
Gay Girls (4) xmark xmark xmark xmark checkmark checkmark
Bisexual Girls (6) checkmark xmark checkmark xmark checkmark checkmark

Searching now becomes a lot more straightforward. If you’re a 1, you’re looking for a 4 or 6. If you’re a 3, you want a 3 or 5. And so on and so forth. Another nice part of this system is that you can get the gender by doing a simple modulus operation. Divide gender+orientation by 2, and if the remainder is 1 you’re a guy and if the remainder is 0 you’re a girl.

That got me to thinking, are there other places where I could be merging data together to save myself a headache? I scoured through my database and there were a couple places where I could merge some booleans together into a single field using a truth table, but I wouldn’t gain anything extraordinary from it. Anyhow, it’s a good tool to keep in the back of my head in case I run into similar situations in the future.

Posted in development.

Tagged with , , .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.