I have set up search in my application, but wish to expand it to index properties related in a one-to-many way. For instance, a person can have many usernames, so they have to be kept separate, as in the following example:
person:
id: ~
name: {type: varchar(100), required: true}
username:
person_id: {type: integer, foreignTable: person, foreignReference: id}
username: {type: varchar(20), primaryKey: true, required: true}
So far I have followed the Jobeet example to use Zend Lucene within my application, and I can search on properties of name within Person, such as Name.
I couldn't find any way to do this automatically through Symfony or Lucene, so I attempted to add the items in the Person's index like so:
foreach ($this->getUsernames() as $i => $username)
{
$doc->addField(Zend_Search_Lucene_Field::Text('username' . $i,
$username->getUsername(), 'utf-8'));
}
I then attempted to update this index whenever a new Username is added by updating Username's save function:
public function save(PropelPDO $con = null)
{
$ret = parent::save($con);
// reindex the person
$person = $this->getPerson();
$person->save();
return $ret;
}
This works fine as long as the person is created at run-time, but if loaded from fixtures, getUsernames()
returns nothing. The code is executed twice (once while loading Person, and once when adding the Username). Is there any reason for this? Can I get around this somehow?
Another way of doing this would also be appreciated. It appears that Lucene can search over multiple indices using the Zend_Lucene_Search_Interface_MultiSearcher class, as described in this question. However, I can't seem to get this working.
I found a similar question here, but found no pointers.
I am now using Propel 1.6.