// not sure this test is fine ... float computation might differ from cpu to cpu
$s = inst()->addProximity(37.7752, -122.4192, 200)->getQuery();
$expected = '(latitude:[35.9785590093 TO 39.5718409907] AND longitude:[-124.6922199992 TO -120.1461800008])';
$t->cmp_ok($s, '===', $expected, '->addProximity()');
$t->diag('testing getNewCriteria()');
$t->isa_ok(inst()->getNewCriteria(), 'sfLuceneCriteria', '->getNewCriteria() returns a new instance of sfLuceneCriteria');
$s = inst()->add('toto')->add(' ')->add('pipop')->getQuery();
$expected = 'toto AND pipop';
$t->cmp_ok($s, '===', $expected, '->add() with empty string');
$t->diag('testing addPhraseGuess()');
$s = inst()->addPhraseGuess('Thomas -"zend framework"')->getQuery();
$expected = '(-("zend framework")) AND (("Thomas"))';
$t->cmp_ok($s, '===', $expected, '->addPhraseGuess()');
$s = inst()->addPhraseGuess('"Thomas"   -"zend framework"')->getQuery();
$expected = '(-("zend framework")) AND (("Thomas"))';
$t->cmp_ok($s, '===', $expected, '->addPhraseGuess()');
$s = inst()->addPhraseGuess('"Thomas"   -.zend')->getQuery();
$expected = '(-(".zend")) AND (("Thomas"))';
$t->cmp_ok($s, '===', $expected, '->addPhraseGuess()');
$s = inst()->addPhraseGuess('Thomas Rabaix +"symfony expert" -"zend framework" +javascript -.net')->getQuery();
$expected = '(+("symfony expert") AND +("javascript")) AND (-("zend framework") AND -(".net")) AND (("Thomas") OR ("Rabaix"))';
$t->cmp_ok($s, '===', $expected, '->addPhraseGuess()');
$s = inst()->addPhraseGuess('Thomas Rabaix +"sym"fony expert" -"zen-d framework" +javascript -.net')->getQuery();
$expected = '(+("sym") AND +("javascript")) AND (-("zen-d framework") AND -(".net")) AND (("Thomas") OR ("Rabaix") OR ("fony") OR ("expert"))';
$t->cmp_ok($s, '===', $expected, '->addPhraseGuess()');
$s = inst()->addPhraseFieldGuess('name', 'Thomas Rabaix +"sym"fony expert" -"zen-d framework" +javascript -.net')->getQuery();
$expected = 'name:(((+("sym") AND +("javascript")) AND (-("zen-d framework") AND -(".net")) AND (("Thomas") OR ("Rabaix") OR ("fony") OR ("expert"))))';
$t->cmp_ok($s, '===', $expected, '->addPhraseGuess()');
$s = inst()->addPhraseFieldGuess('name', 'poulet -sel -chasseur')->getQuery();
$expected = 'name:(((-("sel") AND -("chasseur")) AND (("poulet"))))';
$t->cmp_ok($s, '===', $expected, '->addPhraseGuess()');
示例#2
0
 function run_program($bundle)
 {
     $command = $bundle->get_command();
     $command = "ulimit -v 262144 && ulimit -t 300 && {$command}";
     global $opt_verbose;
     if ($opt_verbose) {
         print "Running command: {$command}\n";
     }
     inst("Running prog: {$command}");
     // now start this process and add it to the list
     $descriptorspec = array(1 => array("pipe", "w"), 2 => array("pipe", "w"));
     $in = $bundle->get_in();
     if ($in) {
         $descriptorspec[0] = array("pipe", "r");
     }
     $pipes = array();
     $handle = proc_open($command, $descriptorspec, $pipes);
     stream_set_blocking($pipes[1], 0);
     stream_set_blocking($pipes[2], 0);
     if ($in) {
         fwrite($pipes[0], $in);
         fclose($pipes[0]);
     }
     $bundle->handle = $handle;
     $bundle->pipes = $pipes;
     $bundle->start_time = time();
     $bundle->out = "";
     $bundle->err = "";
     unset($bundle->exit);
     $this->running_procs[] = $bundle;
 }
$s = $s[0]->getSubqueries();
$t->ok($s[0]->isInclusive(), '->addProximity() uses inclusive range queries');
$t->ok($s[1]->isInclusive(), '->addProximity() uses inclusive range queries');
$t->is_deeply(explode(chr(0), $s[0]->getLowerTerm()->key()), array('latitude', '35.9785590093'), '->addProximity() calculates correct lower bound latitude');
$t->is_deeply(explode(chr(0), $s[0]->getUpperTerm()->key()), array('latitude', '39.5718409907'), '->addProximity() calculates correct upper bound latitude');
$t->is_deeply(explode(chr(0), $s[1]->getLowerTerm()->key()), array('longitude', '-124.692219999'), '->addProximity() calculates correct lower bound longitude');
$t->is_deeply(explode(chr(0), $s[1]->getUpperTerm()->key()), array('longitude', '-120.146180001'), '->addProximity() calculates correct upper bound longitude');
$t->diag('testing sorting');
$sorts = inst()->addSortBy('foo', SORT_ASC, SORT_REGULAR)->addSortBy('bar', SORT_DESC, SORT_NUMERIC)->getSorts();
$t->is_deeply($sorts, array(array('field' => 'foo', 'order' => SORT_ASC, 'type' => SORT_REGULAR), array('field' => 'bar', 'order' => SORT_DESC, 'type' => SORT_NUMERIC)), '->addSortBy() correctly adds the sort fields');
$sorts = inst()->addAscendingSortBy('foo', SORT_STRING)->getSorts();
$t->is_deeply($sorts, array(array('field' => 'foo', 'order' => SORT_ASC, 'type' => SORT_STRING)), '->addAscendingSortBy() correctly adds a sort field');
$sorts = inst()->addDescendingSortBy('foo', SORT_STRING)->getSorts();
$t->is_deeply($sorts, array(array('field' => 'foo', 'order' => SORT_DESC, 'type' => SORT_STRING)), '->addDescendingSortBy() correctly adds a sort field');
$t->diag('testing scoring');
class FooScoring extends Zend_Search_Lucene_Search_Similarity_Default
{
}
$fooScoring = new FooScoring();
$t->is(inst()->getScoringAlgorithm(), null, '->getScoringAlgorithm() is null by default');
$t->ok(inst()->setScoringAlgorithm($fooScoring)->getScoringAlgorithm() === $fooScoring, '->setScoringAlgorithm() changes the algorithm');
$t->is(inst()->setScoringAlgorithm(null)->getScoringAlgorithm(), null, '->setScoringAlgorithm() with null algorithm reverts to default');
try {
    inst()->setScoringAlgorithm('foo');
    $t->fail('->setScoringAlgorithm() rejects invalid algorithms');
} catch (Exception $e) {
    $t->pass('->setScoringAlgorithm() rejects invalid algorithms');
}
$t->diag('testing getNewCriteria()');
$t->isa_ok(inst()->getNewCriteria(), 'sfLuceneCriteria', '->getNewCriteria() returns a new instance of sfLuceneCriteria');
示例#4
0
 public function testInstFunction()
 {
     $closure = inst();
     $this->assertInstanceOf(Misc\SomeClass::class, $closure(Misc\SomeClass::class));
 }