Skip to content

Commit

Permalink
[bugfix]
Browse files Browse the repository at this point in the history
  • Loading branch information
nibsirahsieu committed Jan 8, 2011
1 parent 5a2922f commit 3b8a800
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 47 deletions.
6 changes: 3 additions & 3 deletions lib/behavior/LuceneableBehavior.php
Expand Up @@ -37,7 +37,7 @@ public function addStaticStoredIndex()
{
$table = $this->getTable();
foreach ($table->getColumns() as $col) {
$clo = strtolower($col->getName());
$clo = $col->getPhpName();
if ($col->isPrimaryKey())
{
$clo = 'pk';
Expand All @@ -55,7 +55,7 @@ public function addStaticStoredIndex()
foreach ($columns as $c => $type)
{
$col = $this->getTable()->getColumn($c);
$clo = strtolower($col->getName());
$clo = $col->getPhpName();
$fieldMethod = $this->getLuceneFieldMethod($type);
if (strtolower($type) == 'keyword')
{
Expand All @@ -67,7 +67,7 @@ public function addStaticStoredIndex()
{
$pks = $this->getTable()->getPrimaryKey();
if (count($pks) > 0) $pks = $pks[0];
$data[strtolower($pks->getName())] = $this->getLuceneFieldMethod($type);
$data[$pks->getPhpName()] = $this->getLuceneFieldMethod($type);
}
}
return $this->renderTemplate('staticStoredIndex', array(
Expand Down
46 changes: 11 additions & 35 deletions lib/sfLuceneModelResults.class.php
Expand Up @@ -4,17 +4,20 @@ class sfLuceneModelResults implements Iterator, Countable, ArrayAccess
protected $model;
protected $results;
protected $pointer = 0;
protected $indexedColums = array();
protected $query = null;

public function __construct($model, $results, $query)

public function __construct($model, $pks)
{
$this->model = $model;
$this->results = $results;
$this->query = $query;
$this->indexedColumns = call_user_func(array($model.'Peer', 'getIndexedColumns'));
$this->results = $this->collectResults($model, $pks);
}

protected function collectResults($model, $pks)
{
$indexedColumns = call_user_func(array($model.'Peer', 'getIndexedColumns'));
$columns = array_keys($indexedColumns);
return PropelQuery::from($model)->select($columns)->findPks($pks);
}

public function current()
{
return $this->hydrate($this->results[$this->pointer]);
Expand Down Expand Up @@ -67,37 +70,10 @@ public function offsetUnset($offset)

protected function hydrate($result)
{
$tmp = array();
foreach ($this->indexedColumns as $col => $type)
{
if (strtolower($type) == 'text')
{
$tmp[$col] = $this->query->htmlFragmentHighlightMatches($result->$col);
}
elseif (strtolower($type) == 'keyword')
{
$tmp[$col] = $result->pk;
}
else
{
$tmp[$col] = $result->$col;
}
}
$object = new $this->model;
$object->fromArray($tmp, BasePeer::TYPE_FIELDNAME);
$object->fromArray($result, BasePeer::TYPE_PHPNAME);
$object->setNew(false);
$object->resetModified();
return $object;
}

public function toArray()
{
$retvals = array();
foreach ($this->results as $result)
{
$object = $this->hydrate($result);
$retvals[] = $object;
}
return $retvals;
}
}
8 changes: 2 additions & 6 deletions lib/sfLuceneModelSearch.class.php
Expand Up @@ -6,10 +6,6 @@ class sfLuceneModelSearch

public function __construct($model, $sSearch = null)
{
if (!($sSearch instanceof Zend_Search_Lucene_Search_Query))
{
$sSearch = Zend_Search_Lucene_Search_QueryParser::parse($sSearch);
}
$this->_queryString = $sSearch;
$this->_model = $model;
}
Expand All @@ -22,7 +18,7 @@ public static function create($model, $sSearch = null)
public function find($limit = 10)
{
$hits = sfLuceneableToolkit::getHits($this->_model, $this->_queryString);
return new sfLuceneModelResults($model, $hits, $this->_queryString);
return new sfLuceneModelResults($model, $hits);
}

public function paginate($page, $limit = 10)
Expand All @@ -32,4 +28,4 @@ public function paginate($page, $limit = 10)
$pager->init();
return $pager;
}
}
}
2 changes: 1 addition & 1 deletion lib/sfLucenePager.class.php
Expand Up @@ -102,7 +102,7 @@ public function getResults()
$results = $this->results;
}
$results = array_slice($this->results, $offset, $limit);
return new sfLuceneModelResults($this->model, $results, $this->search);
return new sfLuceneModelResults($this->model, $results);
}

public function getFirstPage()
Expand Down
4 changes: 2 additions & 2 deletions lib/sfLuceneableToolkit.class.php
Expand Up @@ -87,7 +87,7 @@ static public function getHits($model, $query)
$hits = $index->find($query);
foreach ($hits as $hit)
{
$results[] = $hit;
$results[$hit->score] = $hit->pk;
}
}
catch (Exception $e)
Expand All @@ -96,4 +96,4 @@ static public function getHits($model, $query)
}
return $results;
}
}
}

0 comments on commit 3b8a800

Please sign in to comment.