Example #1
0
 /**
  * Gets the solr client instance
  * @return SolrClient the solr client
  */
 public function getClient()
 {
     if ($this->_writeConnection === null) {
         if ($this->_readConnection === null) {
             return null;
         } else {
             return $this->_readConnection->getClient();
         }
     } else {
         return $this->_writeConnection->getClient();
     }
 }
Example #2
0
 /**
  * Tests performing a facetted search without getting results at the same time
  */
 public function testFacetsWithoutResults()
 {
     $connection = new ASolrConnection();
     $connection->clientOptions->hostname = SOLR_HOSTNAME;
     $connection->clientOptions->port = SOLR_PORT;
     $connection->clientOptions->path = SOLR_PATH;
     $doc = new SolrInputDocument();
     $doc->addField('id', 334455);
     $doc->addField('cat', 'Software');
     $doc->addField('cat', 'Lucene');
     $doc->addField("popularity", 20);
     $doc->addField("incubationdate_dt", date("Y-m-d\\TH:i:s\\Z"));
     $this->assertTrue($connection->index($doc));
     $this->assertTrue($connection->commit());
     $criteria = new ASolrCriteria();
     $criteria->query = "lucene";
     $criteria->offset = 0;
     $criteria->limit = 0;
     $criteria->facet = true;
     $criteria->addFacetField("cat")->addFacetField("name");
     $criteria->addFacetDateField("incubationdate_dt");
     $criteria->facetDateStart = "2005-10-10T00:00:00Z";
     $criteria->facetDateEnd = "2015-10-10T00:00:00Z";
     $criteria->facetDateGap = "+12MONTH";
     $criteria->addFacetQuery("popularity:[* TO 10]");
     $criteria->addFacetQuery("popularity:[10 TO 20]");
     $criteria->addFacetQuery("popularity:[20 TO *]");
     $response = $connection->search($criteria);
     $this->assertTrue($response instanceof ASolrQueryResponse);
     $this->assertTrue(isset($response->getDateFacets()->incubationdate_dt));
     $this->assertTrue($response->getDateFacets()->incubationdate_dt instanceof ASolrFacet);
     $results = $response->getResults();
     $this->assertEquals(0, count($results));
     $this->assertTrue($connection->delete(334455));
     $this->assertTrue($connection->commit());
 }
Example #3
0
 /**
  * Tests the delete method
  */
 public function testDelete()
 {
     $connection = new ASolrConnection();
     $connection->clientOptions->hostname = SOLR_HOSTNAME;
     $connection->clientOptions->port = SOLR_PORT;
     $connection->clientOptions->path = SOLR_PATH;
     ASolrDocument::$solr = $connection;
     foreach ($this->fixtureData() as $attributes) {
         $doc = ASolrDocument::model()->findByPk($attributes['id']);
         $this->assertTrue(is_object($doc));
         $this->assertTrue($doc->delete());
     }
     $connection->commit();
     // now check if they were really deleted
     foreach ($this->fixtureData() as $attributes) {
         $doc = ASolrDocument::model()->findByPk($attributes['id']);
         $this->assertFalse(is_object($doc));
     }
 }