views:

216

answers:

2

I am looking for information on handling search in different ORMs.

Currently I am redeveloping some old application in PHP and one of requirements is: make everything or almost everything searchable, so user just types "punkrock live" and the app finds videos clips, music tracks, reviews, upcoming events or even user comments labeled that way.

In environment where everything is searchable ORM need to support this feature in two ways:

  • providing some indexing API on "O" side of ORM
  • providing means for bulk database retrieval on "R" side

Ideal solution would return ready made objects based on searched string. Do you know any good end-to-end solutions that does the job, not necessarily in PHP? If you dealt with similar problem it would be nice to listen what your experience is. Something more than Use Lucene or semantic web is the way oneliners, tho ;-)*

+2  A: 

I have recently integrated the Compass search engine into a Java EE 5 application. It is based on Lucene Java and supports different ORM frameworks as well as other types of models like XML or no real model at all ;)

In the case of an object model managed by an ORM framework you can annotate your classes with special annotations (e.g. @Searchable), register your classes and let Compass index them on application startup and listen to changes to the model automatically.

When it comes to searching, you have the power of Lucene at hand. Compass then gives you instances of your model objects as search result.

It's not PHP, but you said it didn't have to be PHP necessarily ;) Don't know if this helps, though...

Martin Klinke
+1  A: 

In a Propel 1.3 schema.xml file, you can specify that you'd like all your models to extend a "BaseModel" class that YOU create.

In that BaseModel, you're going to re-define the save() method to be something like this:

public function save(PropelPDO $con = null)
{
    if($this->getIsSearchable())
    {
             // update your search index here. Lucene, Sphinx, or otherwise
    }

    return parent::save($conn);
}

That takes care of keeping everything indexed. As for searching, I'd suggest creating a Search class with a few methods.

class Search
{
   protected $_searchableTypes = array('music','video','blog');

   public method findAll($search_term)
   {
      $results = array();

      foreach($this->_searchableTypes as $type)
      {
         $results[] = $this->findType($type, $search_term);
      }

      return $results;
   }
}
lo_fye