Yeah what I am trying is the 'LIKE statement with OR between them'. I split
the terms @ ',' into an array , trim the spaces around each word so I am
left strictly with the values. But having a hard time making the search
string to create.

//create an array of search terms if more than 1 was entered
                 $string = split(",", $string);
                 foreach ($string as $key => $value) {
                         
                         //strip white space befor and after each term
                         $value = trim($value);
                         echo  "Post.title LIKE '%" . $value . "%' OR
Post.description LIKE '%" . $value . "%' OR ";
                         //remove trailing OR
                         substr_replace($string ,"",-3); 

The echo statement there I believe has to go but I cant figure out how to
add to the "Post.title LIKE '%" . $value . "%' OR Post.description LIKE '%"
. $value . "%' OR "; for each in a loop.

Ideas?

Thanks,

Dave


-----Original Message-----
From: John Andersen [mailto:[email protected]] 
Sent: August-12-09 8:24 AM
To: CakePHP
Subject: Re: Search function


As soon as you have more than one word, for which to make a search for
within a text, it becomes more complex!
You can do as JamesF wrote, write the find, so each word is included in a
LIKE statement with OR between them.
You can also do as Smelly Eddie wrote, use tags instead, but the problem is
to ensure that the user only enters valid tags then!

Or you can use Soundex values! Or metaphone if you are using only english!
See the PHP manual.

Let's say you want to search for the words "cake" and "orange" in your
table.

The search functionality would first convert the words into soundex values.
The find would then query the table records which are related to the soundex
values through a HABTM relationship.

contentTable -> HABTM -> soundexTable

The solution means that each word in your content should be processed to
create soundex values to which the content then will be related.

Just an idea, maybe you could use it! :) Enjoy,
   John

On Aug 12, 1:27 pm, Smelly Eddie <[email protected]> wrote:
> better yet avvoid storing multiplee values in one field. Create a 
> reference table (tags) and add those values one per record. It. Will 
> save the code maintainers sanity down the road
>
> On Aug 11, 11:32 pm, JamesF <[email protected]> wrote:
>
> > some fancy combos 'LIKE' and 'OR' in your find conditions array 
> > should get it done. The trick is formatting your array.
>
> >http://book.cakephp.org/view/74/Complex-Find-Conditions
>
> > On Aug 11, 8:55 pm, "Dave Maharaj :: WidePixels.com"
>
> > <[email protected]> wrote:
> > > I am building a new search function for a input single field.
>
> > > I have the basic set up running but as I move forward I want the 
> > > user to be able to enter more than 1 word coma separated.
>
> > > How would I do this?
>
> > > spilt the $queryValues = $query split ','
>
> > > So i now have an array of values that they entered but how do I 
> > > then query each of those values?
>
> > > Is there a better way to do this?
>
> > > thanks,
>
> > > Dave


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

Reply via email to