예제 #1
0
 /**
  *
  * @param sfLuceneResults $lucene_results
  * @param sfLucene $search
  */
 public function __construct($lucene_results, $search = null)
 {
     if (!$lucene_results instanceof sfLuceneResults) {
         throw new sfLuceneException('first arguments must be a sfLuceneResults instance');
     }
     $this->lucene_results = $lucene_results;
     $this->results = $lucene_results->toArray();
     $this->search_parameters = $lucene_results->getRawResult()->sf_lucene_search;
     // compute the page number from the results
     $limit = $lucene_results->getRawResult()->sf_lucene_search['limit'];
     $start = $this->getResults()->getRawResult()->response->start;
     $this->setMaxPerPage($limit);
     $this->setPage((int) ($start / $limit) + 1);
     $this->must_reload = false;
     $this->search = $search === null ? $lucene_results->getSearch() : $search;
     if (!$this->search instanceof sfLucene) {
         throw new sfLuceneException('second arguments must be a sfLucene instance');
     }
 }
        return new MockDocument();
    }
}
class MockDocument
{
    public function getFieldValue($field)
    {
        if ($field == 'sfl_type') {
            return 'regular';
        }
        throw new Exception('d');
    }
}
$data = array(new MockResult('foo'), new MockResult('bar'), new MockResult('baz'));
$search = sfLucene::getInstance('testLucene');
$results = new sfLuceneResults($data, $search);
$t->diag('testing ->getSearch(), ->toArray()');
$t->is($results->getSearch(), $search, '->getSearch() returns the same search instance');
$t->is($results->toArray(), $data, '->toArray() returns the same search data');
$t->diag('testing Iterator interface');
$got = array();
$once = false;
foreach ($results as $key => $value) {
    if (!$once) {
        $t->ok($value instanceof sfLuceneResult, 'iterator interface returns instances of sfLuceneResult');
        $once = true;
    }
    $got[$key] = $value->getResult();
}
$t->is($got, $data, 'sfLuceneResults implements the Iterator interface');
$t->diag('testing Countable interface');
예제 #3
0
   '_fieldBoosts' => 
  array (
    'description' => false,
    'id' => false,
    'name' => false,
    'sfl_type' => false,
    'sfl_guid' => false,
    'skills' => false,
  ),
))
VAR_DUMP;
}
$standard_response = sprintf($standard_response, 3, implode(", ", $results));
$response = new sfLuceneResponse($standard_response);
$search = sfLucene::getInstance('index', 'en', $app_configuration);
$results = new sfLuceneResults($response, $search);
$t->diag('testing ->getSearch(), ->toArray()');
$t->is($results->getSearch(), $search, '->getSearch() returns the same search instance');
foreach ($results->toArray() as $pos => $result) {
    $t->is(var_export($result, 1), $expected_objects[$pos], '->toArray() pos #' . $pos);
}
$t->diag('testing Iterator interface');
// $got = array();
// $once = false;
// foreach ($results as $key => $value)
// {
//   if (!$once)
//   {
//     $t->ok($value instanceof sfLuceneResult, 'iterator interface returns instances of sfLuceneResult');
//     $once = true;
//   }