static function AddToIndex(SearchableObject $object, $commitOnEnd = true) { $doc = new Zend_Search_Lucene_Document(); $doc->addField(Zend_Search_Lucene_Field::Keyword('combinedid', $object->getRelObjectManager() . $object->getRelObjectId())); $doc->addField(Zend_Search_Lucene_Field::UnIndexed('objectid', $object->getRelObjectId())); $doc->addField(Zend_Search_Lucene_Field::Keyword('manager', $object->getRelObjectManager())); $doc->addField(Zend_Search_Lucene_Field::UnIndexed('column', $object->getColumnName())); $doc->addField(Zend_Search_Lucene_Field::UnStored('text', $object->getContent())); $doc->addField(Zend_Search_Lucene_Field::Text('workspaces', "ws" . $object->getProjectId() . " ")); $doc->addField(Zend_Search_Lucene_Field::Text('isprivate', ($object->getIsPrivate() ? '1' : '0') . " ")); self::GetIndex()->addDocument($doc); if ($commitOnEnd) { self::GetIndex()->commit(); } return true; }
function addToSearchableObjects($wasNew = false) { $columns_to_drop = array(); if ($wasNew) { $columns_to_drop = $this->getSearchableColumns(); } else { $searchable_columns = $this->getSearchableColumns(); if (is_array($searchable_columns)) { foreach ($searchable_columns as $column_name) { if (isset($this->searchable_composite_columns[$column_name])) { foreach ($this->searchable_composite_columns[$column_name] as $colName) { if ($this->isColumnModified($colName)) { $columns_to_drop[] = $column_name; break; } } } else { if ($this->isColumnModified($column_name)) { $columns_to_drop[] = $column_name; } } } } $searchable_columns = null; } if (count($columns_to_drop) > 0) { if (!$wasNew) { SearchableObjects::dropContentByObjectColumns($this, $columns_to_drop); } $docx_id = FileTypes::findOne(array('id' => true, 'conditions' => '`extension` = ' . DB::escape('docx'))); $pdf_id = FileTypes::findOne(array('id' => true, 'conditions' => '`extension` = ' . DB::escape('pdf'))); $odt_id = FileTypes::findOne(array('id' => true, 'conditions' => '`extension` = ' . DB::escape('odt'))); $fodt_id = FileTypes::findOne(array('id' => true, 'conditions' => '`extension` = ' . DB::escape('fodt'))); foreach ($columns_to_drop as $column_name) { $content = $this->getSearchableColumnContent($column_name); if (get_class($this->manager()) == 'ProjectFiles') { $content = utf8_encode($content); } elseif (get_class($this->manager()) == 'ProjectFileRevisions') { if ($column_name == "filecontent") { $file = ProjectFileRevisions::findById($this->getObjectId()); try { if ($file->getFileTypeId() == $docx_id) { if (class_exists('DOMDocument')) { $file_path = "tmp/doc_filecontent_" . $this->getObjectId() . ".docx"; $file_tmp = @fopen($file_path, 'w'); if ($file_tmp) { fwrite($file_tmp, $file->getFileContent()); fclose($file_tmp); $content = docx2text($file_path); unlink($file_path); } } } elseif ($file->getFileTypeId() == $pdf_id) { $file_path = "tmp/pdf_filecontent_" . $this->getObjectId() . ".pdf"; $file_tmp = @fopen($file_path, 'w'); if ($file_tmp) { fwrite($file_tmp, $file->getFileContent()); fclose($file_tmp); $content = pdf2text($file_path); unlink($file_path); } } elseif ($file->getFileTypeId() == $odt_id) { if (class_exists('DOMDocument')) { $file_path = "tmp/odt_filecontent_" . $this->getObjectId() . ".odt"; $file_tmp = @fopen($file_path, 'w'); if ($file_tmp) { fwrite($file_tmp, $file->getFileContent()); fclose($file_tmp); $content = odt2text($file_path); unlink($file_path); } } } elseif ($file->getFileTypeId() == $fodt_id) { $file_path = "tmp/fodt_filecontent_" . $this->getObjectId() . ".fodt"; $file_tmp = @fopen($file_path, 'w'); if ($file_tmp) { fwrite($file_tmp, $file->getFileContent()); fclose($file_tmp); $content = fodt2text($file_path, $this->getObjectId()); unlink($file_path); } } } catch (FileNotInRepositoryError $e) { $content = ""; } } else { $content = utf8_encode($content); } } if (trim($content) != '') { $searchable_object = new SearchableObject(); $searchable_object->setRelObjectId($this->getObjectId()); $searchable_object->setColumnName(DB::escape($column_name)); if (strlen($content) > 65535) { $content = utf8_safe(substr($content, 0, 65535)); } $content = DB::escape($content); $sql = "\n\t\t\t\t\t\tINSERT INTO " . TABLE_PREFIX . "searchable_objects (rel_object_id, column_name, content)\n\t\t\t\t\t\tVALUES (" . $searchable_object->getRelObjectId() . "," . $searchable_object->getColumnName() . "," . $content . ")\n\t\t\t\t\t\tON DUPLICATE KEY UPDATE content = {$content}"; DB::execute($sql); $searchable_object = null; } $content = null; } } $columns_to_drop = null; }