/** * Tests the find() and findAll() methods */ public function testFind() { $model = ExampleSolrActiveRecord::model()->find(); $behavior = $model->asa("ASolrSearchable"); /* @var ASolrSearchable $behavior */ $model->index(); $behavior->getSolrDocument()->getSolrConnection()->commit(); $criteria = new ASolrCriteria(); $criteria->query = "id:" . $model->id; $fromSolr = $behavior->findBySolr($criteria); $this->assertTrue($fromSolr instanceof ExampleSolrActiveRecord); foreach ($fromSolr->attributeNames() as $attribute) { $this->assertEquals($model->{$attribute}, $fromSolr->{$attribute}); } $criteria = new ASolrCriteria(); $criteria->setLimit(10); $results = $model->findAllBySolr($criteria); $this->assertEquals(10, count($results)); foreach ($results as $result) { $this->assertTrue($result instanceof ExampleSolrActiveRecord); } }
/** * Counts the number of rows that match the given criteria * @param ASolrCriteria $criteria the search criteria * @return integer the number of matching rows */ public function count(ASolrCriteria $criteria) { $c = new ASolrCriteria(); $c->mergeWith($criteria); $c->setLimit(0); Yii::trace('Counting Results from Solr: ' . (string) $c, 'packages.solr.ASolrConnection'); return $this->rawSearch($c)->response->numFound; }
/** * An example of a solr named scope * @return ExampleExtendedSolrDocument $this with the scope applied */ public function exampleScope() { $criteria = new ASolrCriteria(); $criteria->setLimit(100); $criteria->setQuery('name:test'); $this->getSolrCriteria()->mergeWith($criteria); return $this; }