open ( $fileName ); // Read relations and search for officeDocument $relations = simplexml_load_string ( $package->getFromName ( "_rels/.rels" ) ); foreach ( $relations->Relationship as $rel ) { if ($rel ["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) { // Found office document! Read in contents... $contents = simplexml_load_string ( $package->getFromName ( $this->absoluteZipPath ( dirname ( $rel ["Target"] ) . "/" . basename ( $rel ["Target"] ) ) ) ); $contents->registerXPathNamespace ( "w", Zend_Search_Lucene_Document_Docx::SCHEMA_WORDPROCESSINGML ); $paragraphs = $contents->xpath ( '//w:body/w:p' ); foreach ( $paragraphs as $paragraph ) { $runs = $paragraph->xpath ( '//w:r/w:t' ); foreach ( $runs as $run ) { $documentBody [] = ( string ) $run; } } break; } } // Read core properties $coreProperties = $this->extractMetaData ( $package ); // Close file $package->close (); // Store filename $this->addField ( Zend_Search_Lucene_Field::Text ( 'filename', $fileName ) ); // Store contents if ($storeContent) { $this->addField ( Zend_Search_Lucene_Field::Text ( 'body', implode ( ' ', $documentBody ) ) ); } else { $this->addField ( Zend_Search_Lucene_Field::UnStored ( 'body', implode ( ' ', $documentBody ) ) ); } // Store meta data properties foreach ( $coreProperties as $key => $value ) { $this->addField ( Zend_Search_Lucene_Field::Text ( $key, $value ) ); } // Store title (if not present in meta data) if (! isset ( $coreProperties ['title'] )) { $this->addField ( Zend_Search_Lucene_Field::Text ( 'title', $fileName ) ); } } /** * Load Docx document from a file * * @param string $fileName * @param boolean $storeContent * @return Zend_Search_Lucene_Document_Docx */ public static function loadDocxFile($fileName, $storeContent = false) { return new Zend_Search_Lucene_Document_Docx ( $fileName, $storeContent ); } } } // end if (class_exists('ZipArchive'))