Commit b32163fa authored by zYne's avatar zYne

--no commit message

--no commit message
parent 0813509b
......@@ -32,7 +32,29 @@
*/
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',
......@@ -44,15 +66,15 @@ class Doctrine_Search
'position' => array('type' => 'integer',
'length' => 8));
$id = $record->getTable()->getIdentifier();
$name = $record->getTable()->getComponentName();
$id = $table->getIdentifier();
$name = $table->getComponentName();
$options = array('className' => $name . 'Index');
$fk = array();
foreach ((array) $id as $column) {
$def = $record->getTable()->getDefinitionOf($column);
$def = $table->getDefinitionOf($column);
unset($def['autoincrement']);
unset($def['sequence']);
......@@ -77,18 +99,12 @@ class Doctrine_Search
$def = $builder->buildDefinition($options, $columns, $relations);
if ( ! $this->_options['generateFiles']) {
eval($def);
}
/**
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'
*/
......@@ -34,6 +34,12 @@ class Doctrine_Search_Analyzer_Standard implements Doctrine_Search_Analyzer_Inte
{
public function analyze($text)
{
$text = explode(' ', $text);
foreach ($text as $i => $term) {
$text[$i] = strtolower(trim($term));
}
return $text;
}
}
......@@ -32,23 +32,37 @@
*/
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 postUpdate(Doctrine_Event $event)
{
{
}
public function preInsert(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) {
}
}
}
}
......@@ -32,10 +32,20 @@
*/
class Doctrine_Search_Template extends Doctrine_Template
{
protected $_search;
public function __construct(array $options)
{
$this->_search = new Doctrine_Search($options);
}
public function setUp()
{
$id = $record->getTable()->getIdentifier();
$name = $record->getTable()->getComponentName() . 'Index';
$this->_search->buildDefinition($this->_table);
$id = $this->_table->getIdentifier();
$name = $this->_table->getComponentName() . 'Index';
$this->_search->setOption('className', $name);
foreach ((array) $id as $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);
$this->hasMany($name, array('local' => $id, 'foreign' => $foreign));
$this->addListener(new Doctrine_Search_Listener());
$this->addListener(new Doctrine_Search_Listener($this->_search));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment