Find by LIKE in 1.6

22 views
Skip to first unread message

Aaron Vegh

unread,
Dec 30, 2005, 8:23:40 AM12/30/05
to Php-Object...@googlegroups.com
Hi Joel,
Welcome back! And thanks for getting back early, I missed you! :-)

Your release notes for 1.6 indicate that searching by LIKE has not
been implemented, but that there were workarounds. Well, it just so
happens that I need a LIKE search; can you help me out?

Cheers!
Aaron.

Joel

unread,
Dec 30, 2005, 12:40:59 PM12/30/05
to Php Object Generator
Hi Aaron,

I assume that you're using base64 encode to store your data right?

If you're not (i.e you disabled the Escape and Unescape feature), you
can simply pass "LIKE" as the comparator and %partialstring% as the
value. This should return the correct value(s).

If your data is encoded in the database, then you will need to change
your object manually. I will send you a code example later today.

Hope this helps.
Joel

Aaron Vegh

unread,
Dec 30, 2005, 12:45:54 PM12/30/05
to Php-Object...@googlegroups.com
Naturally, I am using the base64 encoding. It is otherwise so nice.
Looking at the code, I can see why the Base64 presents the problem to
a LIKE query. Looking forward to your code sample.

Cheers,
Aaron.

Joel

unread,
Dec 30, 2005, 8:55:06 PM12/30/05
to Php Object Generator
Hi Aaron,

To get partial string matching to work with the GetList() function,
you'll need to create a Filter function (similar to the Compare
functions that allows pog to sort objects). It should look like this:

function FilterList($objectList, $attributeToCompare, $value)
{
$filteredList = array();
foreach ($objectList as $object)
{
if (strpos($object->{$attributeToCompare}, $value))
{
$filteredList[] = $object;
}
}
return $filteredList;
}

Then you can call this function whenever you need to filter your object
list as follows:

$objectList = $objectList->FilterList($objectList, $attributeName,
$value);


However, what this means is that you'll first need to get the entire
object list (or a sublist using another condition) and *then* filter
it. I would suggest coding to accommodate for POG in this scenario, i.e
if you absolutely need partial string matching, then use another
condition to shorten the list.

This is, as you see, not very efficient at all, and that's why we
didn't put it in 1.6. It would have penalized GetList() to accomodate
partial string matching. I don't think there's a way to improve this
drastically, unless base64 is supported natively by mysql or any other
database....

I encourage anyone who might have a better solution to let us know.

But I hope this *patch* helps you get the job done.

Let me know.

Joel

Reply all
Reply to author
Forward
0 new messages