<?php require_once 'PHPUnit/Framework.php'; require_once dirname(__FILE__) . '/../lib/SwiSolr.php'; SwiSolr::autoload('SolrConfiguration'); /** * Test class for Configuration. * Generated by PHPUnit on 2009-06-16 at 12:39:09. */ class ConfigurationTest extends PHPUnit_Framework_TestCase { /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { Configuration::reset(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @access protected */ protected function tearDown() { } /**
<?php require_once 'PHPUnit/Framework.php'; require_once dirname(__FILE__) . '/../lib/SwiSolr.php'; SwiSolr::autoload('SwiSolrQuery'); SwiSolr::autoload('SolrSimpleSearchField'); /** * Description of SwiSolrQueryTest * * @author developer */ class SwiSolrQueryTest extends PHPUnit_Framework_Testcase { private $queryString; function setUp() { $this->queryString = 'blog'; } /** * test successful initialization by string */ public function testInitilizationWithString() { $query = new SwiSolrQuery($this->queryString); $this->assertType('SolrQuery', $query); $this->assertType('SwiSolrQuery', $query); $this->assertEquals($this->queryString, $query->getQuery()); } /** * test successful initialization by SolrSearchField objects */
<?php require_once 'PHPUnit/Framework.php'; require_once dirname(__FILE__) . '/../lib/SwiSolr.php'; SwiSolr::autoload('SolrSimplePrioritySearchField'); /** * Description of SolrSimplePrioritySearchFieldTest * * @author developer */ class SolrSimplePrioritySearchFieldTest extends PHPUnit_Framework_Testcase { var $searchKeyword; function setUp() { $this->searchKeyword = "blog"; } function testSuccessfulInitialization() { $this->searchKeyword = 'blog'; $searchField = new SolrSimplePrioritySearchField($this->searchKeyword); $this->assertEquals($this->searchKeyword, $searchField->getKeyword()); } function testQueryBuildingAccordingToPriority() { $this->searchKeyword = 'blog'; $expecedQuery = 'title:blog^10.0 content:blog^1.0 '; $searchField = new SolrSimplePrioritySearchField($this->searchKeyword); $this->assertEquals($expecedQuery, $searchField->toQuery()); } }
<?php require_once dirname(__FILE__) . '/lib/SwiSolr.php'; SwiSolr::autoload('SolrSimpleDocument'); SwiSolr::autoload('SolrSimpleField'); // $solr = SwiSolr::connect('http://127.0.0.1:8080/solr'); $solr = SwiSolr::connect('http://127.0.0.1:9080/solr1/'); $doc = new SolrSimpleDocument(array(new SolrSimpleField('id', 'blog-6'), new SolrSimpleField('contentType', 'post'), new SolrSimpleField('dbId', '6'), new SolrSimpleField('title', 'this is'), new SolrSimpleField('content', 'that is'))); try { $solr->add($doc); $solr->commit(); } catch (Exception $e) { echo $e; } /* * delete the previous data. there is also another function named deleteByQuery. * but deleteById is safer */ // $solr->deleteById('blog-4'); $solr->commit(); /* now optimize the index */ // $solr->optimize(); echo "Successfully added the document";
<?php require_once 'PHPUnit/Framework.php'; require_once dirname(__FILE__) . '/../lib/SwiSolr.php'; SwiSolr::autoload('SolrCurrencyField'); /** * Description of SolrCurrencyFieldTest * * @author chowdhury ashabul yeameen * @since 28 May, 2009 */ class SolrCurrencyFieldTest extends PHPUnit_Framework_Testcase { private $fieldName; private $fieldValue; private $boost; function setUp() { $this->fieldName = 'fieldName'; $this->fieldValue = 123.12; $this->boost = 30.4; } /** * check if field initialization is successful with all valied * values and without boost value */ function testInitializationWithoutBoost() { // test without boost value $field = new SolrCurrencyField($this->fieldName, $this->fieldValue); // check if this is an instance of SolrField and has those values
public function __construct() { SwiSolr::autoload('SolrDocument'); SwiSolr::autoload('SolrConfiguration'); }