Ejemplo n.º 1
0
 public function testAddFile()
 {
     $doc = new Elastica_Document();
     $returnValue = $doc->addFile('key', '/dev/null');
     $this->assertInstanceOf('Elastica_Document', $returnValue);
 }
Ejemplo n.º 2
0
	public function testExcludeFileSource() {

		$indexMapping = array('file' => array('type' => 'attachment', 'store' => 'yes'), 'text' => array('type' => 'string', 'store' => 'yes'),
			'title' => array('type' => 'string', 'store' => 'yes'),);

		$indexParams = array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0),);

		$index = $this->_createIndex();
		$type = new Elastica_Type($index, 'content');

		$mapping = Elastica_Type_Mapping::create($indexMapping);
		$mapping->setSource(array('excludes' => array('file')));

		$mapping->setType($type);

		$index->create($indexParams, true);
		$type->setMapping($mapping);

		$docId = 1;
		$text = 'Basel World';
		$title = 'No Title';

		$doc1 = new Elastica_Document($docId);
		$doc1->addFile('file', BASE_PATH . '/data/test.docx');
		$doc1->add('text', $text);
		$doc1->add('title', $title);
		$type->addDocument($doc1);

		// Optimization necessary, as otherwise source still in realtime get
		$index->optimize();

		$data = $type->getDocument($docId)->getData();
		$this->assertEquals($data['title'], $title);
		$this->assertEquals($data['text'], $text);
		$this->assertFalse(isset($data['file']));
	}
Ejemplo n.º 3
0
 public function testAddWordxFile()
 {
     $indexMapping = array('file' => array('type' => 'attachment'), 'text' => array('type' => 'string', 'store' => 'no'));
     $indexParams = array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0));
     $client = new Elastica_Client();
     $index = new Elastica_Index($client, 'content');
     $type = new Elastica_Type($index, 'content');
     $index->create($indexParams, true);
     $type->setMapping($indexMapping);
     $doc1 = new Elastica_Document(1);
     $doc1->addFile('file', BASE_PATH . '/data/test.docx');
     $doc1->add('text', 'basel world');
     $type->addDocument($doc1);
     $doc2 = new Elastica_Document(2);
     $doc2->add('text', 'running in basel');
     $type->addDocument($doc2);
     $index->optimize();
     $resultSet = $type->search('xodoa');
     $this->assertEquals(1, $resultSet->count());
     $resultSet = $type->search('basel');
     $this->assertEquals(2, $resultSet->count());
     $resultSet = $type->search('ruflin');
     $this->assertEquals(0, $resultSet->count());
 }