Hi! Building a light weight search engine for books.
I've a search field for searchterms. The problem is that the searchterms need to be splitted into words and every word has to be looked for in combination with the all the other words. I've a solution to it, see code below. I now wonders if there's any easier, and prettier way to do this in Symfony. I use Propel, though I start to believe Doctrine might do this better, right? The code looks like this: if ($searchtext){ $searchterms = array(); $searchterms = preg_split("/[\s,]+/", $searchtext); $i = true; foreach($searchterms as $s) { // Build criterion object with OR separator if($i == true) { $c_title = $c->getNewCriterion(BookPeer::TITLE, '%' . $s . '%', Criteria::LIKE); $c_desc = $c->getNewCriterion(BookPeer::DESCRIPTION, '%' . $s . '%', Criteria::LIKE); $c_isbn = $c->getNewCriterion(BookPeer::ISBN, '%' . $s . '%', Criteria::LIKE); $c_name = $c->getNewCriterion(AuthorPeer::NAME, '%' . $s . '%', Criteria::LIKE); $c_pubname = $c->getNewCriterion(PublisherPeer::NAME, '%' . $s . '%', Criteria::LIKE); } else { $c_title -> addAnd($c->getNewCriterion(BookPeer::TITLE, '%' . $s . '%', Criteria::LIKE)); $c_desc -> addAnd($c->getNewCriterion(BookPeer::DESCRIPTION, '%' . $s . '%', Criteria::LIKE)); $c_isbn -> addAnd($c->getNewCriterion(BookPeer::ISBN, '%' . $s . '%', Criteria::LIKE)); $c_name -> addAnd($c->getNewCriterion(AuthorPeer::NAME, '%' . $s . '%', Criteria::LIKE)); $c_pubname -> addAnd($c->getNewCriterion(PublisherPeer::NAME, '%' . $s . '%', Criteria::LIKE)); } $i=false; // Add criterion } $c_title->addOr($c_desc); $c_title->addOr($c_isbn); $c_title->addOr($c_name); $c_title->addOr($c_pubname); $c->add($c_title); } Not so nice. But it works. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---