public function __construct(SearchItem $item) { if (!$item->Description()) { $item->Description($item->FullText()); } $description = strip_tags(trim($item->Description())); $break = strpos($description, "\n"); if ($break !== false and $break > 0) { $description = substr($description, 0, $break - 1); } $item->Description($description); # Assign more weight to newer articles $weight = intval($item->ContentDate()->format('U')) / 60 / 60 / 24 / 365; $item->WeightWithinType($weight); $this->searchable = $item; }
private function IndexPages() { require_once "search/search-item.class.php"; $this->SearchIndexer()->DeleteFromIndexByType("page"); # Use INNER JOIN to enable pages to be hidden from search by not having a description, eg Play! which is not really a WordPress page $results = $this->GetDataConnection()->query("\r\n\t\tSELECT id, post_name, post_parent, post_title, meta_value AS description, post_content\r\n\t\tFROM nsa_wp_posts p INNER JOIN nsa_wp_postmeta pm ON (p.id = pm.post_id AND meta_key = 'Description')\r\n\t\tWHERE post_type = 'page' AND post_status = 'publish'"); while ($row = $results->fetch()) { $url = "/" . $row->post_name . "/"; $parent = $row->post_parent; while ($parent != "0") { $url_result = $this->GetDataConnection()->query("SELECT post_name, post_parent FROM nsa_wp_posts WHERE id = " . $parent); $url_row = $url_result->fetch(); $url = "/" . $url_row->post_name . $url; $parent = $url_row->post_parent; } $item = new SearchItem("page", $row->id, $url, $row->post_title, $row->description); $item->FullText($row->post_content); $this->SearchIndexer()->Index($item); } $this->SearchIndexer()->CommitChanges(); }
/** * Queues the item to be added to the index when CommitChanges is called */ public function Index(SearchItem $item) { $this->index_queue[] = "INSERT INTO nsa_search_index SET \n search_index_id = " . Sql::ProtectString($this->connection, $item->SearchItemId()) . ",\n indexed_item_type = " . Sql::ProtectString($this->connection, $item->SearchItemType()) . ",\n url = " . Sql::ProtectString($this->connection, $item->Url()) . ",\n title = " . Sql::ProtectString($this->connection, $item->Title()) . ",\n keywords = " . Sql::ProtectString($this->connection, $item->Keywords()) . ",\n description = " . Sql::ProtectString($this->connection, $item->Description()) . ",\n related_links_html = " . Sql::ProtectString($this->connection, $item->RelatedLinksHtml()) . ",\n full_text = " . Sql::ProtectString($this->connection, $item->FullText()) . ",\n weight_of_type = " . Sql::ProtectNumeric($item->WeightOfType(), false, false) . ",\n weight_within_type = " . Sql::ProtectNumeric($item->WeightWithinType(), false, false); }
/** * Add a WordPress post to search results when it is published * @param $post_id int */ public function PublishPost($post_id) { $post = get_post($post_id); require_once "search/mysql-search-indexer.class.php"; require_once "search/blog-post-search-adapter.class.php"; require_once "search/search-item.class.php"; require_once "data/mysql-connection.class.php"; $search = new MySqlSearchIndexer(new MySqlConnection($this->settings->DatabaseHost(), $this->settings->DatabaseUser(), $this->settings->DatabasePassword(), $this->settings->DatabaseName())); $search->DeleteFromIndexById("post" . $post_id); $item = new SearchItem("post", $post_id, get_permalink($post_id), $post->post_title); $item->ContentDate(new DateTime($post->post_date)); $item->FullText($post->post_content); $adapter = new BlogPostSearchAdapter($item); $search->Index($adapter->GetSearchableItem()); $search->CommitChanges(); }