/** * Get search results * @param string $q * @return array */ public function search($q = null) { $params = $this->getParams($q); $result = $this->manganel->getClient()->search($params); if (empty($result) && empty($result['hits']) && empty($result['hits']['hits'])) { return []; // @codeCoverageIgnore } return $result['hits']['hits']; }
public function testIfWillDeleteIndexOfTrashableDocumentAfterTrashingAndRestoreItOnRestore() { $model = new TrashableModel(); $model->_id = new MongoId(); $model->title = 'Connecticut is a state'; // Mock signal receive save (new Receiver())->onSave(new AfterSave($model)); $mnl = Manganel::fly(); $client = $mnl->getClient(); $get = ['index' => $mnl->index, 'type' => CollectionNamer::nameCollection($model), 'id' => (string) $model->_id]; $found = $client->get($get)['_source']; $this->assertSame($model->title, $found['title']); // Should be handle by event handler from Receiver $model->trash(); try { $client->get($get); $this->assertFalse(true, 'That missing exception was not thrown'); } catch (Missing404Exception $e) { $this->assertTrue(true, 'That missing exception was thrown'); } $trash = new Trash(); $trashed = $trash->find(); $this->assertNotNull($trashed, 'That item was found in trash'); $restored = $trashed->restore(); $this->assertTrue($restored, 'That item was successfully restored'); $restoredIndex = $client->get($get)['_source']; $this->assertSame($model->title, $restoredIndex['title'], 'That restored item is back in index'); }
public function testIfCanStoreSomething() { $mnl = Manganel::fly(); $src = array(); $src['body'] = array('testField' => 'abc'); $src['index'] = $mnl->index; $src['type'] = 'my_type'; $src['id'] = 'my_id'; $client = $mnl->getClient(); $client->index($src); $getParams = array(); $getParams['index'] = $mnl->index; $getParams['type'] = 'my_type'; $getParams['id'] = 'my_id'; $doc = $client->get($getParams); $this->assertSame($src['body']['testField'], $doc['_source']['testField']); }
public function testIfWillStoreNestedDocumentFromMockSignal() { $model = new NestedModel(); $model->_id = new MongoId(); codecept_debug((string) $model->_id); $model->username = '******'; $image = new Image(); $image->_id = new MongoId(); $image->filename = 'my-photo.jpg'; $model->avatar = $image; // Mock signal receive (new Receiver())->onSave(new AfterSave($model)); $mnl = Manganel::fly(); $client = $mnl->getClient(); $get = ['index' => $mnl->index, 'type' => CollectionNamer::nameCollection($model), 'id' => (string) $model->_id]; $found = $client->get($get)['_source']; codecept_debug($found); $this->assertSame($model->username, $found['username']); }
public function testBefore(TestEvent $e) { // Wait a bit to avoid illagal index states usleep(25000); $mnl = Manganel::fly(); $params = ['index' => strtolower($mnl->index)]; try { $mnl->getClient()->indices()->delete($params); } catch (Missing404Exception $e) { // Skip missing indexes } try { $mnl->getClient()->indices()->create($params); } catch (Missing404Exception $e) { // Skip missing indexes } // Wait a bit to avoid illagal index states usleep(25000); }
public function testIfWillDropIndex() { $model = new SimpleModel(); $model->_id = new MongoId(); $model->title = 'Jersey'; $im = new IndexManager($model); $im->index(); $found = $im->get(); // Check if is indexed $this->assertTrue($found instanceof SimpleModel); $this->assertSame($model->title, $found->title); $result = Manganel::create($model)->drop(); codecept_debug($result); try { $im->get(); $this->assertFalse(true); } catch (Missing404Exception $ex) { $this->assertTrue(true); } }
/** * Get client * @return Client */ public function getClient() { return $this->manganel->getClient(); }
use Maslosoft\Mangan\Transformers\YamlArray; use Maslosoft\Manganel\Manganel; use Maslosoft\Manganel\SearchArray; use Maslosoft\Signals\Signal; date_default_timezone_set('Europe/Paris'); define('VENDOR_DIR', __DIR__ . '/../../..'); define('YII_DIR', VENDOR_DIR . '/yiisoft/yii/framework/'); require VENDOR_DIR . '/autoload.php'; // Invoker stub for windows if (defined('PHP_WINDOWS_VERSION_MAJOR')) { require __DIR__ . '/../misc/Invoker.php'; } //require $yii = YII_DIR . 'yii.php'; //require_once YII_DIR . 'base/CComponent.php'; //require_once YII_DIR . 'base/CModel.php'; $config = (require __DIR__ . '/../config.php'); $signals = new Signal(); $sMap = [JsonArray::class => [MongoObjectId::class => MongoWriteStringId::class, DateSanitizer::class => DateWriteUnixSanitizer::class], SearchArray::class => [MongoObjectId::class => MongoWriteStringId::class, DateSanitizer::class => DateWriteUnixSanitizer::class], YamlArray::class => [MongoObjectId::class => MongoWriteStringId::class, DateSanitizer::class => DateWriteUnixSanitizer::class]]; $mangan = Mangan::fly(); $mangan->connectionString = 'mongodb://localhost:27017'; $mangan->dbName = 'ManganTest'; $mangan->sanitizersMap = $sMap; $mangan->init(); $mangan2 = Mangan::fly('second'); $mangan2->connectionString = 'mongodb://localhost:27017'; $mangan2->dbName = 'ManganTestSecond'; $mangan2->sanitizersMap = $sMap; $mangan2->init(); $manganel = Manganel::fly(); $manganel->index = strtolower($mangan->dbName); $manganel->hosts = ['localhost:9200'];
public function testIfWillIgnoreExplicitlyNonIndexableFromMockSignal() { $model = new ExplicitlyNonIndexableModel(); $model->_id = new MongoId(); $model->title = 'Alabama is a state'; // Mock signal receive (new Receiver())->onSave(new AfterSave($model)); $mnl = Manganel::fly(); $client = $mnl->getClient(); $get = ['index' => $mnl->index, 'type' => CollectionNamer::nameCollection($model), 'id' => (string) $model->_id]; try { $found = $client->get($get)['_source']; $this->assertFalse(true, 'That missing exception was not thrown'); } catch (Missing404Exception $e) { $this->assertTrue(true, 'That missing exception was thrown'); } }