Beispiel #1
0
 public function testCreateIndex()
 {
     $tokenizer = new core_kernel_classes_Resource(RawValue::URI);
     $id = 'test_index_' . helpers_Random::generateString(8);
     $index = IndexService::createIndex($this->property, $id, $tokenizer, true, true);
     $this->assertIsA($index, 'oat\\tao\\model\\search\\Index');
     $this->assertTrue($index->exists());
     $indexToo = IndexService::getIndexById($id);
     $this->assertIsA($indexToo, 'oat\\tao\\model\\search\\Index');
     $this->assertTrue($index->equals($indexToo));
     $this->assertEquals($id, $index->getIdentifier());
     $this->assertTrue($index->isDefaultSearchable());
     $this->assertTrue($index->isFuzzyMatching());
     $tokenizer = $index->getTokenizer();
     $this->assertIsA($tokenizer, 'oat\\tao\\model\\search\\tokenizer\\Tokenizer');
     $indexes = IndexService::getIndexes($this->property);
     $this->assertTrue(is_array($indexes));
     $this->assertEquals(1, count($indexes));
     $indexToo = reset($indexes);
     $this->assertIsA($indexToo, 'oat\\tao\\model\\search\\Index');
     $this->assertTrue($index->equals($indexToo));
     return $index;
 }
 protected function savePropertyIndex($indexValues)
 {
     $values = array();
     foreach ($indexValues as $key => $value) {
         $values[tao_helpers_Uri::decode($key)] = tao_helpers_Uri::decode($value);
     }
     $validator = new tao_helpers_form_validators_IndexIdentifier();
     // if the identifier is valid
     $values[INDEX_PROPERTY_IDENTIFIER] = strtolower($values[INDEX_PROPERTY_IDENTIFIER]);
     if (!$validator->evaluate($values[INDEX_PROPERTY_IDENTIFIER])) {
         throw new Exception($validator->getMessage());
     }
     //if the property exists edit it, else create one
     $existingIndex = \oat\tao\model\search\IndexService::getIndexById($values[INDEX_PROPERTY_IDENTIFIER]);
     $indexProperty = new core_kernel_classes_Property($values['uri']);
     if (!is_null($existingIndex) && !$existingIndex->equals($indexProperty)) {
         throw new Exception("The index identifier should be unique");
     }
     unset($values['uri']);
     $this->bindProperties($indexProperty, $values);
 }