/** * Parses configuration options from YAML configuration files related to the * configurable object. * * This method throws the SearchEvents::CONFIG_LOAD event. If configurations * are loaded during this event, processing stops and the directories are * not scanned for configuration files. * * @return array * An associative array of options. * * @throws ParseException */ public function load() { $log = $this->_agent->getLogger(); $context = array('collection' => $this->_collection->getId()); // Allow the schema to be loaded from another source. $event = new SchemaLoaderEvent($this->_agent, $this->_collection); $this->_agent->dispatchEvent(SearchEvents::SCHEMA_LOAD, $event); if (!($options = $event->getOptions())) { if ($conf_dir = $this->getConfDir()) { $filename = $this->_collection->getConfigBasename() . '.yml'; $filepath = $conf_dir . '/' . $filename; $context['filepath'] = $filepath; $log->debug('Attempting to parse schema configuration file', $context); $options = Yaml::parse($filepath); $log->debug('Schema options parsed from configuration file', $context); } else { $log->notice('Path to conf directory could not be resolved', $context); } } else { $log->debug('Schema configuration loaded from an external source.', $context); } $schema = new Schema(); $schema->build($options); return $schema; }
/** * Queues the items scheduled for indexing for the collection. * * @param CollectionAbstract $collection * The collection that fetches the items scheduled for indexing. * * @return int * The number of items sent to the queue. */ public function queueCollection(CollectionAbstract $collection) { $log = $this->getLogger(); $context = array('collection' => $collection->getId()); $log->info('Begin fetching items that are scheduled for indexing', $context); $event = new CollectionEvent($this, $collection); $this->dispatchEvent(SearchEvents::COLLECTION_PRE_QUEUE, $event, $context); // The producer fetches the items scheduled for indexing from the // collection and publishes them to the indexing queue. $producer = new QueueProducer($this, $collection); foreach ($producer as $message) { // @todo Have this return a boolean suceess flag and modify the log // message accordingly? $message->publish(); $context['item'] = $message->getBody(); $log->debug('Published item scheduled for indexing to queue', $context); } unset($context['item']); // The item is no longer in context. $this->dispatchEvent(SearchEvents::COLLECTION_POST_QUEUE, $event, $context); // Get and log the number of items queued for this collection. $num_queued = count($producer); $context['queued'] = $num_queued; $log->info('Finished fetching and queueing items that are scheduled for indexing', $context); return $num_queued; }
/** * * @param CollectionAbstract $collection * * @return Schema * * @throws */ public function loadCollectionSchema(CollectionAbstract $collection) { $loader = new SchemaLoader($this, $collection); $schema = $loader->load(); $context = array('collection' => $collection->getId()); $event = new SchemaEvent($this, $collection, $schema); $this->dispatchEvent(SearchEvents::SCHEMA_ALTER, $event, $context); return $schema; }
/** * Implements SearchEngineAbstract::indexDocument(). * * @param CollectionAbstract $collection * @param IndexDocument $document */ public function indexDocument(CollectionAbstract $collection, IndexDocument $document) { $index_doc = array(); if (null !== ($boost = $document->getBoost())) { $index_doc['_boost'] = $boost; } foreach ($document as $field_id => $normalized_value) { $name = $document->getFieldName($field_id); $index_doc[$name] = $normalized_value; } $native_doc = new Elastica_Document(null, $index_doc); $native_doc->setIndex($this->_activeIndex); $native_doc->setType($collection->getType()); $this->_documents[] = $native_doc; }