/** * @param \Tripod\Mongo\Driver $tripod * @param string $readPreference * @throws \Tripod\Exceptions\SearchException */ public function __construct(\Tripod\Mongo\Driver $tripod, $readPreference = ReadPreference::RP_PRIMARY) { $this->tripod = $tripod; $this->storeName = $tripod->getStoreName(); $this->podName = $tripod->podName; $this->labeller = new Labeller(); $this->stat = $tripod->getStat(); $this->config = Config::getInstance(); $provider = $this->config->getSearchProviderClassName($this->tripod->getStoreName()); if (class_exists($provider)) { $this->configuredProvider = new $provider($this->tripod); } else { throw new \Tripod\Exceptions\SearchException("Did not recognise Search Provider, or could not find class: {$provider}"); } $this->readPreference = $readPreference; }
/** * @param Driver $tripod * @param array $opts */ public function __construct(Driver $tripod, $opts = array()) { $this->tripod = $tripod; $this->storeName = $tripod->getStoreName(); $this->podName = $tripod->getPodName(); $this->stat = $tripod->getStat(); $this->labeller = new Labeller(); $opts = array_merge(array('defaultContext' => null, OP_ASYNC => array(OP_VIEWS => false, OP_TABLES => true, OP_SEARCH => true), 'stat' => null, 'readPreference' => ReadPreference::RP_PRIMARY_PREFERRED, 'retriesToGetLock' => 20), $opts); $this->readPreference = $opts['readPreference']; $this->config = $this->getConfigInstance(); // default context $this->defaultContext = $opts['defaultContext']; //max retries to get lock $this->retriesToGetLock = $opts['retriesToGetLock']; // fill in and default any missing keys for $async array $async = $opts[OP_ASYNC]; if (!array_key_exists(OP_VIEWS, $async)) { $async[OP_VIEWS] = false; } if (!array_key_exists(OP_TABLES, $async)) { $async[OP_TABLES] = true; } if (!array_key_exists(OP_SEARCH, $async)) { $async[OP_SEARCH] = true; } // if there is no es configured then remove OP_SEARCH from async (no point putting these onto the queue) TRI-19 if ($this->config->getSearchDocumentSpecifications($this->storeName) == null) { unset($async[OP_SEARCH]); } // If a custom queue name was specified, store it if (array_key_exists(OP_QUEUE, $async)) { $this->queueName = $async[OP_QUEUE]; unset($async[OP_QUEUE]); } $this->async = $async; if (isset($opts['statsConfig'])) { $this->statsConfig = $opts['statsConfig']; } }