Permalink
Browse files

add param to use filtering on a different key with keywords

  • Loading branch information...
Floby committed Sep 20, 2012
1 parent e4b89f1 commit 76836f77f5d384df9ac38225d699ffbf8b0b3f98
Showing with 8 additions and 5 deletions.
  1. +8 −5 models/Crawler/Abstract.php
@@ -97,12 +97,12 @@ protected function _populateArrayFromRow(Centurion_Db_Table_Row_Abstract $row)
* @param (string) $terms a string contains terms or keywords to look for
* @return [Centurion_Db_Table_Row_Abstract]
*/
- public function crawlTable(Centurion_Db_Table_Abstract $table, array $fields, $terms, $limit=0, $select = null)
+ public function crawlTable(Centurion_Db_Table_Abstract $table, array $fields, $terms, $limit=0, $select = null, $key = null)
{
if(null === $select) {
$select = $table->select(true);
}
- $this->selectKeywordsInTextFields($select, $fields, $terms);
+ $this->selectKeywordsInTextFields($select, $fields, $terms, $key);
if(0 < $limit) {
$select->limit($limit);
}
@@ -138,8 +138,11 @@ public function rowsetToArray($rowset)
* @param (string) $terms the keywords to look for
* @return Centurion_Db_Table_Select
*/
- public function selectKeywordsInTextFields($select, $fields, $terms)
+ public function selectKeywordsInTextFields($select, $fields, $terms, $key)
{
+ if(empty($key)) {
+ $key = 'id';
+ }
$columns = (array) $fields;
// make sure we only filter on columns that exist
$columns = array_filter($columns, array($select->getTable(), 'hasColumn'));
@@ -149,7 +152,7 @@ public function selectKeywordsInTextFields($select, $fields, $terms)
// this is because it is very difficult to manage OR operator with the Zend Select object
$keywordsSelect = $select->getTable()->select(true);
$keywordsSelect->reset(Zend_Db_Select::COLUMNS);
- $keywordsSelect->columns(array('id'));
+ $keywordsSelect->columns(array($key));
// split the terms parameter into words
$terms = explode(' ', $terms);
$first = true;
@@ -174,7 +177,7 @@ public function selectKeywordsInTextFields($select, $fields, $terms)
// construct the subrequest expression from this select
$expr = new Zend_Db_Expr('('.$keywordsSelect->__toString().')');
// the subrequest returns a set of ids that match the keywords
- $select->filter(array('id__in' => $expr));
+ $select->filter(array($key.'__in' => $expr));
return $select;
}

0 comments on commit 76836f7

Please sign in to comment.