So I was a tad mistaken in my last post, displaying the tinyint data in user
profiles didn't cut down on the code, it added a touch more but that's okay,
it works just fine.

ie.

// SEEKING DATA
$values = array(1,2,4,8,16,32,64);
$storedValue = $user['Seeking']['seeking'];
$seeking = array();

if($values[0] & $storedValue){ array_push($seeking, 'Friends'); }
if($values[1] & $storedValue){ array_push($seeking, 'Someone to hang out
with'); }
if($values[2] & $storedValue){ array_push($seeking, 'Dating'); }
if($values[3] & $storedValue){ array_push($seeking, 'Serious relationship');
}
if($values[4] & $storedValue){ array_push($seeking, 'Someone to talk to /
email'); }
if($values[5] & $storedValue){ array_push($seeking, 'Intimate encounter');
}
if($values[6] & $storedValue){ array_push($seeking, 'Other'); }

$lookingFor = $text->toList($seeking, ',');

Seems okay, no? It works.

I ran a few "non-query" test cases and it seemed as though I was able to
find the intersecting bits without it having to be an exact match ... so far
so good.

The problem I'm running into is getting the query to accept the operator
without it throwing an error. I tried a few different ways but nothing seems
to work.

'conditions' => array(
 'Seeking.seeking &' => $seeking,  // <-- ??
 'Seeking.orientation' => $orientation,
 'User.gender' => $gender,
 'User.age BETWEEN ? AND ?' => array($minAge, $maxAge),
 'User.country' => $country,
 'User.region' => $region
     ),
@John:

Are you using the db to cache your search results on the server side? I
learned some hard lessons in the past and need to cut down the load wherever
I can. Is there any specific advantages to setting up your search the way
you have it?

- Ed

On Wed, Jun 9, 2010 at 8:09 PM, Ed Propsner <crotchf...@gmail.com> wrote:

> @Calvin:
>
> I have very little experience with bitwise operations but if the concept
> was totally escaping me and you saw this don't ever be hesitant to tell me
> I'm being a dummy. I have no reservations with diving into a tutorial and
> picking up on something new. I never expect the answer but will always
> appreciate you pointing me in the right direction where i can play around,
> experiment, and hopefully come up with a somewhat feasible solution on my
> own.
>
> I found a tutorial on bitwise operations and realized I was WAY far off
> from anything you were suggesting. You were right on the mark! (you the
> man!) I'll stop being cryptic and let you know I'm working on a makeover for
> a social networking site for singles. I'll never claim to know everything
> (even common sense things) I should know to make this all work but  what I
> do appreciate is people like you taking the time to point me in the right
> direction (and don''t forget John Anderson or Jeremy Burns) they have been
> instrumental in keeping me  on a direct path with Cake conventions. (I still
> have a few questions for you John but I'll get back to you) . Anyhow there
> was a time when I thought I was king $hit on turd island with conventional
> PHP but Cake has totally knocked the wind out of my sails but I'm totally
> addicted and can't see doing it any other way at this point (thank you guys
> for all your help ).
>
> Just displaying the data using tinyint cut my code down drastically. I
> haven't implemented the search yet and while I have a busy night in front of
> me (Stanley Cup finals and all) I'll start the search tomorrow and let you
> know how I make out. I'm not expecting any problems. Where have bitwise
> operations been all this time? I'll throw all my code at you sometime
> tomorrow. 8-)
>
> Cya  Then
>
> - Ed
>
> Sooooo ... being a complete idiot on bitwise operations I took the tutorial
> and O' my God,.... Thanks Calvin!
> .
>
>
> On Wed, Jun 9, 2010 at 4:20 PM, calvin <cal...@rottenrecords.com> wrote:
>
>> Manipulating bit fields can be confusing at times (e.g. on Monday it
>> took me a while to realize the query in my original post didn't do
>> what I thought it would), and there's usually more than one way to do
>> it. But, basically, the way I approached it was to group all of the OR
>> conditions together and treat them collectively as another AND
>> condition (so the search has to match all of the ANDs, and at least
>> one of the ORs). That may not be what you want for your search, but it
>> demonstrates how you'd evaluate  AND & OR conditions.
>>
>> So taking your example of a record that has the bitfield value of 3,
>> if you want to do a purely OR search for Videos(1) or Photos(4) or
>> Text(8), you'd only use the first half the query I wrote:
>>
>> Model.type & $orOptions > 0
>>
>> So the database engine would evaluate:
>>
>> 3 & 13 > 0
>>
>> The bit fields in big-endian notation would be:
>> 0011 (3)
>> 1101 (13)
>>
>> So the result is 0001 because both the search params and the record
>> field have the bit for "Video" set. And since 1 > 0, that record would
>> be returned as a match.
>>
>> To perform the same search using AND, you'd simply check to see if 3 &
>> 13 = 13, which it obviously does not. But a record that has a value of
>> 13 for the type field would evaluate to:
>>
>> 1101 & 1101 = 1101
>>
>> So such a record would be return as a result.
>>
>> On Jun 8, 10:36 am, Ed Propsner <crotchf...@gmail.com> wrote:
>> > @Calvin:
>> >
>> > I do like the idea of using array_sum() and storing the options as an
>> INT,
>> > I've taken this approach in the past with a different app (once) and it
>> > worked out just fine. In this case let's say you have a value of 3
>> stored in
>> > the db representing 2 options ... '1' => 'video, '2' => 'audio. A search
>> on
>> > that column would only hit on an exact match, no? I only need the stored
>> > value and the search criteria to have one of their values in common, not
>> > all. In this case if a user searched just '1' => 'video' it should
>> return
>> > the column containing the value of 3 because both the search and the
>> stored
>> > data have '1' => 'video' in common.
>> >
>> > I won't stress the checkbox search too much at this time. I did get it
>> > working without writing any kind of custom query. The query itself is to
>> the
>> > point but checking the values of the array and setting up the $orOptions
>> to
>> > account for each possibility was a tad lengthy. About the checkboxes ...
>> > well ... I was submitting them as separate input fields instead of one
>> > 'multiple' ... don't ask! 8-).
>> >
>> > The query giving me problems at this time is the advanced search. It's
>> not
>> > much a problem more than I'm unsure of how to approach it. I want to toy
>> > around with it for a bit then I'll let know what issues I'm having.
>> >
>> > @John:
>> >
>> > [quote]
>> >
>> > When the user submits the search, the first thing I do, is to save the
>> > search parameters in the database (Enquiry model), so as to get an ID..
>> >
>> > [/quote]
>> >
>> > Errr ... Something came up and I have to leave the house but I have a
>> few
>> > questions for ya' ... I'll get back you when I get back in.
>> >
>> > On Tue, Jun 8, 2010 at 3:38 AM, John Andersen <j.andersen...@gmail.com
>> >wrote:
>> >
>> > > This may not be relevant to your issue, but maybe to your solution. I
>> > > will try to explain how I did my search functionality.
>> >
>> > > In my application, the user will search for a specific object
>> > > (Article, Author, Blog, etc.), not a combination of these.
>> >
>> > > The search form provides the following entries:
>> > > Words [text] - one or more words
>> >
>> > > Word criteria [radiogroup] - :
>> > > 1) must contain all words.
>> > > 2) must contain at least one word.
>> > > 3) must contain exact phrase.
>> >
>> > > Search criteria [checkbox] - :
>> > > 1) In title (default).
>> > > 2) In summary.
>> > > 3) In body.
>> >
>> > > Category(ies) [checkbox] - all categories.
>> >
>> > > When the user submits the search, the first thing I do, is to save the
>> > > search parameters in the database (Enquiry model), so as to get an ID.
>> >
>> > > The search parameters are then passed on to the responsible model
>> > > (Article, Author, Blog, etc), which then performs the actual search.
>> > > The resulting rows (ids) are passed back to the Enquiry model, which
>> > > saves the result (creates relationships between Enquiry model and
>> > > responsible model).
>> >
>> > > I then uses the ID to paginate the result, when presenting it to the
>> > > user.
>> >
>> > > Building the search query:
>> > > 1) I split into single words from the Words entry.
>> > > 2) Based on the Word criteria, I prepare the respective AND, OR, or
>> > > phrase condition(s) for all possible Search criteria. That is one for
>> > > Title, one for Summary and one for Body.
>> > > 3) Based on the Search criteria, I include the respective conditions
>> > > for Title, Summary and/or Body.
>> >
>> > > The resulting find conditions looks like this (Words equal "a b c",
>> > > Word criteria "must contain all words", Search critera "In title, In
>> > > summary, In body":
>> > > [code]
>> > > Array
>> > > (
>> > >   [OR] => Array
>> > >      (
>> > >         [0] => Array
>> > >            (
>> > >               [AND] => Array
>> > >                  (
>> > >                     [0] => Array
>> > >                        (
>> > >                           [LOWER(Article.title) LIKE] => %a%
>> > >                        )
>> > >                     [1] => Array
>> > >                        (
>> > >                           [LOWER(Article.title) LIKE] => %b%
>> > >                        )
>> > >                     [2] => Array
>> > >                        (
>> > >                           [LOWER(Article.title) LIKE] => %c%
>> > >                        )
>> > >                  )
>> > >            )
>> > >         [1] => Array
>> > >            (
>> > >               [AND] => Array
>> > >                  (
>> > >                     [0] => Array
>> > >                        (
>> > >                           [LOWER(Article.summary) LIKE] => %a%
>> > >                        )
>> > >                     [1] => Array
>> > >                        (
>> > >                           [LOWER(Article.summary) LIKE] => %b%
>> > >                        )
>> > >                     [2] => Array
>> > >                        (
>> > >                           [LOWER(Article.summary) LIKE] => %c%
>> > >                        )
>> > >                  )
>> > >            )
>> > >         [2] => Array
>> > >            (
>> > >               [AND] => Array
>> > >                  (
>> > >                     [0] => Array
>> > >                        (
>> > >                           [LOWER(Article.content) LIKE] => %a%
>> > >                        )
>> > >                     [1] => Array
>> > >                        (
>> > >                           [LOWER(Article.content) LIKE] => %b%
>> > >                        )
>> > >                     [2] => Array
>> > >                        (
>> > >                           [LOWER(Article.content) LIKE] => %c%
>> > >                        )
>> > >                   )
>> > >             )
>> > >      )
>> > >   [Article.state] => 2
>> > > )
>> > > [/code]
>> >
>> > > If you have questions to the above, or just curious about other
>> > > things, feel free to ask :) Hope you will get your search up and
>> > > running!
>> > > Enjoy,
>> > >   John
>> >
>> > > [snip]
>> >
>> > > Check out the new CakePHP Questions sitehttp://cakeqs.organd help
>> others
>> > > with their CakePHP related questions.
>> >
>> > > You received this message because you are subscribed to the Google
>> Groups
>> > > "CakePHP" group.
>> > > To post to this group, send email to cake-php@googlegroups.com
>> > > To unsubscribe from this group, send email to
>> > > cake-php+unsubscr...@googlegroups.com<cake-php%2bunsubscr...@googlegroups.com>
>> <cake-php%2bunsubscr...@googlegroups.com<cake-php%252bunsubscr...@googlegroups.com>>For
>> more options, visit this group at
>> > >http://groups.google.com/group/cake-php?hl=en
>>
>> Check out the new CakePHP Questions site http://cakeqs.org and help
>> others with their CakePHP related questions.
>>
>> You received this message because you are subscribed to the Google Groups
>> "CakePHP" group.
>> To post to this group, send email to cake-php@googlegroups.com
>> To unsubscribe from this group, send email to
>> cake-php+unsubscr...@googlegroups.com<cake-php%2bunsubscr...@googlegroups.com>For
>>  more options, visit this group at
>> http://groups.google.com/group/cake-php?hl=en
>>
>
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to