/** * Transforms given objects into a bulk delete operation * * @param ClassMetadata $metadata * @param array $objects * @return array bulk commands */ public function createBulk(ClassMetadata $metadata, array $objects) { $index = $metadata->getIndex(); $idGetter = 'get' . self::camelize($index->getIdProperty()); $map = array(); foreach ($objects as $object) { $map[] = array('delete' => array('_index' => $index->getName(), '_type' => $metadata->getClassName(), '_id' => $object->$idGetter())); } return $map; }
/** * Transforms object metadata into a mapping definition * * @param ClassMetadata $metadata */ public function createSchema(ClassMetadata $metadata) { $index = $metadata->getIndex(); $settings = array('number_of_shards' => $index->getNumberOfShards(), 'number_of_replicas' => $index->getNumberOfReplicas()); $type = $metadata->getClassName(); $mappings = array($type => array('properties' => array())); $mappings[$type]['properties'] = $this->exportProperties($metadata); return array('settings' => $settings, 'mappings' => $mappings); }
/** * (non-PHPdoc) * @see Ariadne\Engine.Engine::search() */ public function run(ClassMetadata $metadata, Query $query) { $index = $metadata->getIndex()->getName(); $type = $metadata->getClassName(); $query = $this->mapQuery($query); $response = $this->adapter->getClient()->search($index, $type, $query); return $this->mapResult($response, $metadata); }
/** * (non-PHPdoc) * @see Ariadne\Engine.Engine::search() */ public function run(ClassMetadata $metadata, Query $query) { $index = $metadata->getIndex()->getName(); $type = $metadata->getClassName(); $arguments = $this->mapQuery($query); $index = Lucene::open("/tmp/index_$index"); $result = call_user_func_array(array($index, 'find'), $arguments); return $this->mapResult($result, $metadata, $query); }
/** * Export an object recursivly, using associated metadata * * @param ClassMetadata $metadata * @param stdClass $object * @return array object */ protected function exportObject(ClassMetadata $metadata, $object) { $document = new Document(); $idGetter = 'get' . self::camelize($metadata->getIndex()->getIdProperty()); $document->addField(Field::unIndexed('_id', $object->$idGetter())); foreach ($metadata->getFields() as $property => $field) { $getter = 'get' . self::camelize($property); $value = $object->$getter(); if ($value && 'date' === $field->getType()) { $value = $value->format($field->getFormat()); } $type = $field->getType(); $encoding = mb_detect_encoding($value); $isStored = $field->getStore() === 'yes'; $isIndexed = $field->getIndex() != "no"; $isTokenized = $field->getIndex() == "analyzed"; $field = new Field($field->getIndexName(), $value, $encoding, $isStored, $isIndexed, $isTokenized); $document->addField($field); $doc[$property] = $value; } $document->addField(Field::unIndexed('_doc', json_encode($doc))); return $document; }
/** * Transforms given objects into a bulk add operation directive * * @param ClassMetadata $metadata * @param array $objects * @param array bulk commands */ public function run(ClassMetadata $metadata) { $indexName = $metadata->getIndex()->getName(); return $this->adapter->getClient()->dropIndex($indexName); }
/** * Transforms given objects into a bulk add operation directive * * @param ClassMetadata $metadata * @param array $objects * @param array bulk commands */ public function run(ClassMetadata $metadata) { $index = $metadata->getIndex()->getName(); @unlink("/tmp/index_$index"); }
/** * Transforms given objects into a bulk add operation directive * * @param ClassMetadata $metadata * @param array $objects * @param array bulk commands */ public function run(ClassMetadata $metadata) { $index = $metadata->getIndex()->getName(); Lucene::create("/tmp/index_$index"); }