コード例 #1
0
class Foo
{
}
function inst()
{
    return sfLuceneCriteria::newInstance();
}
$t->isa_ok(sfLuceneCriteria::newInstance(), 'sfLuceneCriteria', '::newInstance() returns an sfLuceneCriteria object');
$criteria = inst();
$t->diag('testing ->getQuery()');
$t->ok(is_string($criteria->getQuery()), '->getQuery() returns an instance a string');
$t->diag('testing ->add()');
$criteria->add('test', sfLuceneCriteria::TYPE_AND);
$t->pass('->add() accepts a string');
$queries = inst()->add('foo')->add('bar')->getQuery();
$t->cmp_ok($queries, '===', 'foo AND bar', '->add() correctly parses and adds text queries');
$queries = inst()->add('foo')->add('bar', sfLuceneCriteria::TYPE_OR)->getQuery();
$t->cmp_ok($queries, '===', 'foo OR bar', '->add() correctly parses and adds text queries');
$query = inst();
$query->add('foo');
$criteria->add($query, null);
$t->pass('->add() accepts sfLuceneCriteria');
$luceneQuery = inst()->add($query);
$luceneQuery->add('bar', sfLuceneCriteria::TYPE_OR);
$subqueries = inst()->add($luceneQuery)->getQuery();
$t->cmp_ok($subqueries, '==', '((foo) OR bar)', '->getQuery() correctly combines sfLuceneCriteria queries');
try {
    $criteria->add($criteria, true);
    $t->fail('->add() rejects itself');
} catch (Exception $e) {
    $t->pass('->add() rejects itself');
コード例 #2
0
<?php

require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(3, limeade_output::get());
$val = "this is my+ es\\caped ?*string";
$escaped = Apache_Solr_Service::escape($val);
$expected = 'this is my\\+ es\\\\caped \\?\\*string';
$t->cmp_ok($escaped, '===', $expected, "::escape  ok");
$val = "this is \"my escaped\" phrase";
$escaped = Apache_Solr_Service::escapePhrase($val);
$expected = 'this is \\"my escaped\\" phrase';
$t->cmp_ok($escaped, '===', $expected, "::escapePhrase  ok");
$escaped = Apache_Solr_Service::phrase($val);
$expected = '"this is \\"my escaped\\" phrase"';
$t->cmp_ok($escaped, '===', $expected, "::phrase  ok");
コード例 #3
0
<?php

require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(2, limeade_output::get());
$t->diag('document format a document');
$document = new Apache_Solr_Document();
$document->setBoost(10);
$document->setField('sfl_guid', 'GUID_1234');
$document->setField('name', 'Thomas Rabaix', 1);
$document->setMultiValue('skills', 'php');
$document->setMultiValue('skills', 'symfony');
$document->addField('skills', 'objective-c');
$expected = array('name' => 'skills', 'value' => array(0 => 'php', 1 => 'symfony', 2 => 'objective-c'), 'boost' => false);
$t->cmp_ok($document->getField('skills'), '==', $expected, '::getField test multivalue setter');
$expected = array('name' => 'name', 'value' => 'Thomas Rabaix', 'boost' => 1);
$t->cmp_ok($document->getField('name'), '==', $expected, '::getField test setter');
コード例 #4
0
    $t->fail('->setMaxPerPage() accepts an integer per page');
}
$t->is($pager->getPage(), 2, '->getPage() returns current page');
$t->is($pager->getMaxPerPage(), 10, '->getMaxPerPage() returns the max per page');
$t->is($pager->getNbResults(), 1001, '->getNbResults() returns the total number of results');
$t->ok($pager->haveToPaginate(), '->haveToPaginate() returns correct value');
$pager->setPage(0);
$t->is($pager->getPage(), 1, '->setPage() to 0 sets the page to 1');
$pager->setPage(100000);
$t->is($pager->getPage(), 101, '->setPage() above to upper bound resets to last page');
$pager->setPage(2);
$t->diag('testing ->getResults()');
$results = $pager->getResults()->toArray();
foreach (range(10, 19) as $id) {
    $guid = 'GUID_' . $id;
    $t->cmp_ok($results[$id - 10]->sfl_guid, '==', $guid, '->getResults() returns the correct range, sfl_guid:' . $guid);
}
$pager->setPage(3);
$results = $pager->getResults()->toArray();
foreach (range(20, 29) as $id) {
    $guid = 'GUID_' . $id;
    $t->cmp_ok($results[$id - 20]->sfl_guid, '==', $guid, '->getResults() returns the correct range after page change, sfl_guid:' . $guid);
}
$pager->setMaxPerPage(20);
$t->diag('testing page numbers');
$t->is($pager->getFirstPage(), 1, '->getFirstPage() returns 1 as first page');
$t->is($pager->getLastPage(), 51, '->getLastPage() returns the last page in the range');
$t->is($pager->getNextPage(), 4, '->getNextPage() returns the next page');
$pager->setPage(101);
$t->is($pager->getNextPage(), 51, '->getNextPage() returns last page if at end');
$pager->setPage(4);
コード例 #5
0
 * (c) 2009 Thomas Rabaix <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
/**
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Thomas Rabaix
 * @version SVN: $Id$
 */
require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(11, limeade_output::get());
$lucene = sfLucene::getInstance('index', 'en', $app_configuration);
$luke = new sfLuceneLuke($lucene);
$t->cmp_ok($luke->getRequestHandlerUrl(), '===', 'http://localhost:8983/solr/index_en/admin/luke', '::getRequestUrl() ok');
if ($lucene->getSearchService()->ping()) {
    $t->diag('Solr available');
    $luke->loadInformation();
    $t->cmp_ok($luke->getNumDocs(), '===', 3, '::getNumDocs() ok');
    $t->cmp_ok($luke->getMaxDoc(), '>', 0, '::getMaxDoc() ok');
    $t->cmp_ok($luke->getNumTerms(), '===', 38, '::getNumTerms() ok');
    $t->cmp_ok(date("U", $luke->getVersion()), '!==', false, '::getVersion() ok');
    $t->cmp_ok($luke->getOptimized(), '===', true, '::getOptimized() ok');
    $t->cmp_ok($luke->getCurrent(), '===', true, '::getCurrent() ok');
    $t->ok(is_bool($luke->getHasDeletions()), '::getHasDeletions() ok');
    $t->ok(is_string($luke->getDirectory()), '::getDirectory() ok');
    $t->ok(strtotime($luke->getLastModified()), '::getLastModified() ok');
    $t->cmp_ok($luke->getStats('prout', 'null'), '===', null, '::getStats() ok');
} else {
    $t->skip('::getNumDocs()');
コード例 #6
0
}
$t->is($service->getHost(), '127.0.0.1', '->getHost() ok');
$t->is($service->getPort(), '8983', '->getPort() ok');
$t->is($service->getPath(), '/solr/', '->getPath() ok');
$service->setPath('/solr/index_fr/');
$t->is($service->getPath(), '/solr/index_fr/', '->setPath() ok');
try {
    $response = $service->deleteByQuery('non_existent_field:asd');
    $t->fail('::deleteByQuery refers to a non existent field');
} catch (Exception $e) {
    $t->pass('::deleteByQuery raise an error on non existent field');
}
$t->diag("search for rande, limit:2, offset:0");
$response = $service->search('rande', 0, 2);
$t->ok($response instanceof sfLuceneDocument, '::search returns Apache_Solr_Response object');
$t->cmp_ok($response->getHttpStatusMessage(), '===', 'OK', '::getHttpStatusMessage return OK');
$t->cmp_ok($response->getHttpStatus(), '===', '200', '::getHttpStatus return code 200');
$t->cmp_ok($response->response->numFound, '===', 3, '->response->numFound return 3 entries');
$t->cmp_ok(count($response->response->docs), '===', 2, '->response->numFound return 2 entries');
$t->ok($response->response->docs[0] instanceof sfLuceneDocument, '->response->docs[0] return an instance sfLuceneDocument');
$t->cmp_ok($response->response->docs[0]->sfl_guid, '===', 'GUID_1', '->response->docs[0]->sfl_guid ok');
$t->cmp_ok($response->response->docs[1]->sfl_guid, '===', 'GUID_2', '->response->docs[1]->sfl_guid ok');
//
$t->diag("search for rande, limit:1, offset:2");
$response = $service->search('rande', 2, 1);
$t->ok($response instanceof sfLuceneDocument, '::search returns Apache_Solr_Response object');
$t->cmp_ok($response->getHttpStatusMessage(), '===', 'OK', '::getHttpStatusMessage return OK');
$t->cmp_ok($response->getHttpStatus(), '===', '200', '::getHttpStatus return code 200');
$t->cmp_ok($response->response->numFound, '===', 3, '->response->numFound return 3 entries');
$t->cmp_ok(count($response->response->docs), '===', 1, '->response->numFound return 2 entries');
$t->ok($response->response->docs[0] instanceof sfLuceneDocument, '->response->docs[0] return an instance sfLuceneDocument');
コード例 #7
0
ファイル: sfLuceneTest.php プロジェクト: rande/sfSolrPlugin
 * This file is part of the sfLucenePlugin package
 * (c) 2007 - 2008 Carl Vondrick <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
/**
 * @package sfLucenePlugin
 * @subpackage Test
 * @author Carl Vondrick
 * @version SVN: $Id$
 */
require dirname(__FILE__) . '/../bootstrap/unit.php';
$t = new limeade_test(50, limeade_output::get());
$lucene = sfLucene::getInstance('index', 'en', $app_configuration);
$t->cmp_ok($lucene->getPublicName(), '===', 'index (en)', '::getPublicName()');
$t->cmp_ok($lucene->getParameter('name'), '===', 'index', '::getParameter() - name');
$t->cmp_ok($lucene->getParameter('culture'), '===', 'en', '::getParameter() - culture');
$t->cmp_ok($lucene->getParameter('encoding'), '===', 'UTF-8', '::getParameter() - encoding');
$t->cmp_ok($lucene->getParameter('host'), '===', 'localhost', '::getParameter() - host');
$t->cmp_ok($lucene->getParameter('port'), '===', '8983', '::getParameter() - port');
$t->cmp_ok($lucene->getParameter('base_url'), '===', '/solr', '::getParameter() - base_url');
try {
    $e = $t->no_exception('::getInstance() allows valid cultures');
    $lucene = sfLucene::getInstance('index', 'en', $app_configuration);
    $e->no();
} catch (Exception $ex) {
    $e->caught($ex);
}
$lucene->unlatch();
unset($lucene);
コード例 #8
0
{
    public $name;
    public function __construct($a)
    {
        $this->name = $a;
    }
}
// create fake response
$standard_response = '{"responseHeader":{"status":0,"QTime":0},"response":{"numFound":3,"start":%s,"docs":[%s]}, %s}';
$expected_objects = array();
$results = array();
foreach (range(1, 3) as $num) {
    $results[] = sprintf('{"description":"symfony fan boy","id":%d,"name":"rande","sfl_guid":"GUID_%d","skills":["symfony","php","objective-c"]}', $num, $num);
}
// faceting stuff
$facets = '"facet_counts":{"facet_queries":{"name:[a TO z]":3},"facet_fields":{"sfl_model":{"User":1, "Group": 2}},"facet_dates":{}}';
$standard_response = sprintf($standard_response, 3, implode(", ", $results), $facets);
$response = new sfLuceneResponse($standard_response);
$search = sfLucene::getInstance('index', 'en', $app_configuration);
$results = new sfLuceneFacetsResults($response, $search);
$t->diag('testing facet queries');
$expected_queries = array("name:[a TO z]" => 3);
$t->is_deeply($results->getFacetQueries(), $expected_queries, '->getFacetQueries() returns the expected array');
$t->is_deeply($results->getFacetQuery("name:[a TO z]"), 3, '->getFacetQuery() returns the expected value');
$t->is_deeply($results->getFacetQuery("non_existant_facet"), null, '->getFacetQuery() return correct value on non existant facet');
$t->diag('testing facet fields');
$expected_fields = array('sfl_model' => array("User" => 1, "Group" => 2));
$t->is_deeply($results->getFacetFields(), $expected_fields, '->getFacetFields() returns the expected array');
$t->cmp_ok($results->getFacetsField('non_existant_field'), '===', null, '->getFacetsField() return null on non existant field');
$t->is_deeply($results->getFacetField('sfl_model'), array("User" => 1, "Group" => 2), '->getFacetField() return correct facet\'s value');
$t->is_deeply($results->getFacetField('non_existant_facet'), null, '->getFacetField() return correct value on non existant facet');