/** * Cooperates with the cron system to automatically find content that is * not index in the _search table and add it to the index. */ function IndexOldStuff() { $class = get_class(); $auto_create = function ($db_error) use($class) { if ($db_error != 1146) { // Perform the standard error handling return true; } // Create the search table automatically $class::__init(); }; // THREADS ---------------------------------- $sql = "SELECT A1.`id`, A1.`title`, A1.`body`, A1.`format` FROM `" . TICKET_THREAD_TABLE . "` A1\n LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`id` = A2.`object_id` AND A2.`object_type`='H')\n WHERE A2.`object_id` IS NULL AND (A1.poster <> 'SYSTEM')\n AND (LENGTH(A1.`title`) + LENGTH(A1.`body`) > 0)\n ORDER BY A1.`id` DESC"; if (!($res = db_query_unbuffered($sql, $auto_create))) { return false; } while ($row = db_fetch_row($res)) { $body = ThreadBody::fromFormattedText($row[2], $row[3]); $body = $body->getSearchable(); $title = Format::searchable($row[1]); if (!$body && !$title) { continue; } $record = array('H', $row[0], $title, $body); if (!$this->__index($record)) { return; } } // TICKETS ---------------------------------- $sql = "SELECT A1.`ticket_id` FROM `" . TICKET_TABLE . "` A1\n LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`ticket_id` = A2.`object_id` AND A2.`object_type`='T')\n WHERE A2.`object_id` IS NULL\n ORDER BY A1.`ticket_id` DESC"; if (!($res = db_query_unbuffered($sql, $auto_create))) { return false; } while ($row = db_fetch_row($res)) { $ticket = Ticket::lookup($row[0]); $cdata = $ticket->loadDynamicData(); $content = array(); foreach ($cdata as $k => $a) { if ($k != 'subject' && ($v = $a->getSearchable())) { $content[] = $v; } } $record = array('T', $ticket->getId(), Format::searchable($ticket->getNumber() . ' ' . $ticket->getSubject()), implode("\n", $content)); if (!$this->__index($record)) { return; } } // USERS ------------------------------------ $sql = "SELECT A1.`id` FROM `" . USER_TABLE . "` A1\n LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`id` = A2.`object_id` AND A2.`object_type`='U')\n WHERE A2.`object_id` IS NULL\n ORDER BY A1.`id` DESC"; if (!($res = db_query_unbuffered($sql, $auto_create))) { return false; } while ($row = db_fetch_row($res)) { $user = User::lookup($row[0]); $cdata = $user->getDynamicData(); $content = array(); foreach ($user->emails as $e) { $content[] = $e->address; } foreach ($cdata as $e) { foreach ($e->getAnswers() as $a) { if ($c = $a->getSearchable()) { $content[] = $c; } } } $record = array('U', $user->getId(), Format::searchable($user->getFullName()), trim(implode("\n", $content))); if (!$this->__index($record)) { return; } } // ORGANIZATIONS ---------------------------- $sql = "SELECT A1.`id` FROM `" . ORGANIZATION_TABLE . "` A1\n LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`id` = A2.`object_id` AND A2.`object_type`='O')\n WHERE A2.`object_id` IS NULL\n ORDER BY A1.`id` DESC"; if (!($res = db_query_unbuffered($sql, $auto_create))) { return false; } while ($row = db_fetch_row($res)) { $org = Organization::lookup($row[0]); $cdata = $org->getDynamicData(); $content = array(); foreach ($cdata as $e) { foreach ($e->getAnswers() as $a) { if ($c = $a->getSearchable()) { $content[] = $c; } } } $record = array('O', $org->getId(), Format::searchable($org->getName()), trim(implode("\n", $content))); if (!$this->__index($record)) { return null; } } // KNOWLEDGEBASE ---------------------------- require_once INCLUDE_DIR . 'class.faq.php'; $sql = "SELECT A1.`faq_id` FROM `" . FAQ_TABLE . "` A1\n LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`faq_id` = A2.`object_id` AND A2.`object_type`='K')\n WHERE A2.`object_id` IS NULL\n ORDER BY A1.`faq_id` DESC"; if (!($res = db_query_unbuffered($sql, $auto_create))) { return false; } while ($row = db_fetch_row($res)) { $faq = FAQ::lookup($row[0]); $q = $faq->getQuestion(); if ($k = $faq->getKeywords()) { $q = $k . ' ' . $q; } $record = array('K', $faq->getId(), Format::searchable($q), $faq->getSearchableAnswer()); if (!$this->__index($record)) { return; } } // FILES ------------------------------------ // Flush non-full batch of records $this->__index(null, true); if (!$this->_reindexed) { // Stop rebuilding the index $this->getConfig()->set('reindex', 0); } }
function getSearchable($include_label = false) { if ($include_label) { $label = Format::searchable($this->getField()->getLabel()) . " "; } return sprintf("%s%s", $label, $this->getField()->searchable($this->getValue())); }
function getSearchable() { // <br> -> \n $body = preg_replace(array('`<br(\\s*)?/?>`i', '`</div>`i'), "\n", $this->body); $body = Format::htmldecode(Format::striptags($body)); return Format::searchable($body); }
function searchable($value) { $value = preg_replace(array('`<br(\\s*)?/?>`i', '`</div>`i'), "\n", $value); $value = Format::htmldecode(Format::striptags($value)); return Format::searchable($value); }
function getSearchable() { // Replace tag chars with spaces (to ensure words are separated) $body = Format::html($this->body, array('hook_tag' => function ($el, $attributes = 0) { static $non_ws = array('wbr' => 1); return isset($non_ws[$el]) ? '' : ' '; })); // Collapse multiple white-spaces $body = html_entity_decode($body, ENT_QUOTES); $body = preg_replace('`\\s+`u', ' ', $body); return Format::searchable($body); }