1
0
mirror of synced 2025-02-01 04:51:45 +03:00
This commit is contained in:
zYne 2007-07-11 13:20:39 +00:00
parent 0813509b5c
commit b32163fab3
4 changed files with 73 additions and 27 deletions

View File

@ -32,7 +32,29 @@
*/ */
class Doctrine_Search class Doctrine_Search
{ {
public function buildDefinition(Doctrine_Record $record) protected $_options = array('generateFiles' => true);
public function __construct(array $options)
{
$this->_options = array_merge($this->_options, $options);
}
public function getOption($option)
{
if (isset($this->_options[$option])) {
return $this->_option[$option];
}
return null;
}
public function setOption($option, $value)
{
$this->_options[$option] = $value;
return $this;
}
public function buildDefinition(Doctrine_Table $table)
{ {
$columns = array('keyword' => array('type' => 'string', $columns = array('keyword' => array('type' => 'string',
@ -44,15 +66,15 @@ class Doctrine_Search
'position' => array('type' => 'integer', 'position' => array('type' => 'integer',
'length' => 8)); 'length' => 8));
$id = $record->getTable()->getIdentifier(); $id = $table->getIdentifier();
$name = $record->getTable()->getComponentName(); $name = $table->getComponentName();
$options = array('className' => $name . 'Index'); $options = array('className' => $name . 'Index');
$fk = array(); $fk = array();
foreach ((array) $id as $column) { foreach ((array) $id as $column) {
$def = $record->getTable()->getDefinitionOf($column); $def = $table->getDefinitionOf($column);
unset($def['autoincrement']); unset($def['autoincrement']);
unset($def['sequence']); unset($def['sequence']);
@ -77,18 +99,12 @@ class Doctrine_Search
$def = $builder->buildDefinition($options, $columns, $relations); $def = $builder->buildDefinition($options, $columns, $relations);
if ( ! $this->_options['generateFiles']) {
eval($def);
}
/**
print "<pre>"; print "<pre>";
print_r($def); print_r(htmlentities($def));
*/
} }
} }
/**
fields:
[keyword] [field] [foreign_id] [position]
fields:
[keyword] [field] [match]
example data:
'orm' 'content' '1:36|2:23'
*/

View File

@ -34,6 +34,12 @@ class Doctrine_Search_Analyzer_Standard implements Doctrine_Search_Analyzer_Inte
{ {
public function analyze($text) public function analyze($text)
{ {
$text = explode(' ', $text);
foreach ($text as $i => $term) {
$text[$i] = strtolower(trim($term));
}
return $text;
} }
} }

View File

@ -32,23 +32,37 @@
*/ */
class Doctrine_Search_Listener extends Doctrine_Record_Listener class Doctrine_Search_Listener extends Doctrine_Record_Listener
{ {
protected $_search;
public function __construct(Doctrine_Search $search)
{
$this->_search = $search;
}
public function preUpdate(Doctrine_Event $event) public function preUpdate(Doctrine_Event $event)
{ {
} }
public function postUpdate(Doctrine_Event $event) public function postUpdate(Doctrine_Event $event)
{ {
} }
public function preInsert(Doctrine_Event $event) public function preInsert(Doctrine_Event $event)
{ {
} }
public function postInsert(Doctrine_Event $event) public function postInsert(Doctrine_Event $event)
{ {
$fields = $this->_search->getOption('fields');
foreach ($fields as $field) {
$terms = $this->_search->analyze($field);
foreach ($terms as $term) {
}
}
} }
} }

View File

@ -32,10 +32,20 @@
*/ */
class Doctrine_Search_Template extends Doctrine_Template class Doctrine_Search_Template extends Doctrine_Template
{ {
protected $_search;
public function __construct(array $options)
{
$this->_search = new Doctrine_Search($options);
}
public function setUp() public function setUp()
{ {
$id = $record->getTable()->getIdentifier(); $this->_search->buildDefinition($this->_table);
$name = $record->getTable()->getComponentName() . 'Index';
$id = $this->_table->getIdentifier();
$name = $this->_table->getComponentName() . 'Index';
$this->_search->setOption('className', $name);
foreach ((array) $id as $column) { foreach ((array) $id as $column) {
$foreign[] = strtolower($name . '_' . $column); $foreign[] = strtolower($name . '_' . $column);
@ -44,7 +54,7 @@ class Doctrine_Search_Template extends Doctrine_Template
$foreign = (count($foreign) > 1) ? array_keys($foreign) : key($foreign); $foreign = (count($foreign) > 1) ? array_keys($foreign) : key($foreign);
$this->hasMany($name, array('local' => $id, 'foreign' => $foreign)); $this->hasMany($name, array('local' => $id, 'foreign' => $foreign));
$this->addListener(new Doctrine_Search_Listener()); $this->addListener(new Doctrine_Search_Listener($this->_search));
} }
} }