/** * Set up a small index of items to test against. */ function _setup() { $this->config('search.settings')->set('index.minimum_word_size', 3)->save(); for ($i = 1; $i <= 7; ++$i) { search_index(SEARCH_TYPE, $i, LanguageInterface::LANGCODE_NOT_SPECIFIED, $this->getText($i)); } for ($i = 1; $i <= 5; ++$i) { search_index(SEARCH_TYPE_2, $i + 7, LanguageInterface::LANGCODE_NOT_SPECIFIED, $this->getText2($i)); } // No getText builder function for Japanese text; just a simple array. foreach (array(13 => '以呂波耳・ほへとち。リヌルヲ。', 14 => 'ドルーパルが大好きよ!', 15 => 'コーヒーとケーキ') as $i => $jpn) { search_index(SEARCH_TYPE_JPN, $i, LanguageInterface::LANGCODE_NOT_SPECIFIED, $jpn); } search_update_totals(); }
/** * Indexes a single node. * * @param \Drupal\node\NodeInterface $node * The node to index. */ protected function indexNode(NodeInterface $node) { $languages = $node->getTranslationLanguages(); $node_render = $this->entityManager->getViewBuilder('node'); foreach ($languages as $language) { $node = $node->getTranslation($language->getId()); // Render the node. $build = $node_render->view($node, 'search_index', $language->getId()); unset($build['#theme']); $rendered = $this->renderer->renderPlain($build); $text = '<h1>' . SafeMarkup::checkPlain($node->label($language->getId())) . '</h1>' . $rendered; // Fetch extra data normally not visible. $extra = $this->moduleHandler->invokeAll('node_update_index', array($node, $language->getId())); foreach ($extra as $t) { $text .= $t; } // Update index, using search index "type" equal to the plugin ID. search_index($this->getPluginId(), $node->id(), $language->getId(), $text); } }
/** * Update Drupal's full-text index for this module. * * Modules can implement this hook if they want to use the full-text indexing * mechanism in Drupal. * * This hook is called every cron run if search.module is enabled. A module * should check which of its items were modified or added since the last * run. It is advised that you implement a throttling mechanism which indexes * at most 'search_cron_limit' items per run (see example below). * * You should also be aware that indexing may take too long and be aborted if * there is a PHP time limit. That's why you should update your internal * bookkeeping multiple times per run, preferably after every item that * is indexed. * * Per item that needs to be indexed, you should call search_index() with * its content as a single HTML string. The search indexer will analyse the * HTML and use it to assign higher weights to important words (such as * titles). It will also check for links that point to nodes, and use them to * boost the ranking of the target nodes. * * @ingroup search */ function hook_update_index() { $limit = (int) variable_get('search_cron_limit', 100); $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit); foreach ($result as $node) { $node = node_load($node->nid); // Save the changed time of the most recent indexed node, for the search // results half-life calculation. variable_set('node_cron_last', $node->changed); // Render the node. node_build_content($node, 'search_index'); $node->rendered = drupal_render($node->content); $text = '<h1>' . check_plain($node->title) . '</h1>' . $node->rendered; // Fetch extra data normally not visible $extra = module_invoke_all('node_update_index', $node); foreach ($extra as $t) { $text .= $t; } // Update index search_index($node->nid, 'node', $text); } }
/** * Indexes a single node. * * @param \Drupal\node\NodeInterface $node * The node to index. */ protected function indexNode(NodeInterface $node) { $languages = $node->getTranslationLanguages(); $node_render = $this->entityManager->getViewBuilder('node'); foreach ($languages as $language) { $node = $node->getTranslation($language->getId()); // Render the node. $build = $node_render->view($node, 'search_index', $language->getId()); unset($build['#theme']); // Add the title to text so it is searchable. $build['search_title'] = ['#prefix' => '<h1>', '#plain_text' => $node->label(), '#suffix' => '</h1>', '#weight' => -1000]; $text = $this->renderer->renderPlain($build); // Fetch extra data normally not visible. $extra = $this->moduleHandler->invokeAll('node_update_index', [$node]); foreach ($extra as $t) { $text .= $t; } // Update index, using search index "type" equal to the plugin ID. search_index($this->getPluginId(), $node->id(), $language->getId(), $text); } }
/** * Tests the indexing throttle and search results with multilingual nodes. */ function testMultilingualSearch() { // Index only 2 nodes per cron run. We cannot do this setting in the UI, // because it doesn't go this low. $this->config('search.settings')->set('index.cron_limit', 2)->save(); // Get a new search plugin, to make sure it has this setting. $this->plugin = $this->container->get('plugin.manager.search')->createInstance('node_search'); // Update the index. This does the initial processing. $this->plugin->updateIndex(); // Run the shutdown function. Testing is a unique case where indexing // and searching has to happen in the same request, so running the shutdown // function manually is needed to finish the indexing process. search_update_totals(); $this->assertIndexCounts(6, 8, 'after updating partially'); $this->assertDatabaseCounts(2, 0, 'after updating partially'); // Now index the rest of the nodes. // Make sure index throttle is high enough, via the UI. $this->drupalPostForm('admin/config/search/pages', array('cron_limit' => 20), t('Save configuration')); $this->assertEqual(20, $this->config('search.settings')->get('index.cron_limit', 100), 'Config setting was saved correctly'); // Get a new search plugin, to make sure it has this setting. $this->plugin = $this->container->get('plugin.manager.search')->createInstance('node_search'); $this->plugin->updateIndex(); search_update_totals(); $this->assertIndexCounts(0, 8, 'after updating fully'); $this->assertDatabaseCounts(8, 0, 'after updating fully'); // Click the reindex button on the admin page, verify counts, and reindex. $this->drupalPostForm('admin/config/search/pages', array(), t('Re-index site')); $this->drupalPostForm(NULL, array(), t('Re-index site')); $this->assertIndexCounts(8, 8, 'after reindex'); $this->assertDatabaseCounts(8, 0, 'after reindex'); $this->plugin->updateIndex(); search_update_totals(); // Test search results. // This should find two results for the second and third node. $this->plugin->setSearch('English OR Hungarian', array(), array()); $search_result = $this->plugin->execute(); $this->assertEqual(count($search_result), 2, 'Found two results.'); // Nodes are saved directly after each other and have the same created time // so testing for the order is not possible. $results = array($search_result[0]['title'], $search_result[1]['title']); $this->assertTrue(in_array('Third node this is the Hungarian title', $results), 'The search finds the correct Hungarian title.'); $this->assertTrue(in_array('Second node this is the English title', $results), 'The search finds the correct English title.'); // Now filter for Hungarian results only. $this->plugin->setSearch('English OR Hungarian', array('f' => array('language:hu')), array()); $search_result = $this->plugin->execute(); $this->assertEqual(count($search_result), 1, 'The search found only one result'); $this->assertEqual($search_result[0]['title'], 'Third node this is the Hungarian title', 'The search finds the correct Hungarian title.'); // Test for search with common key word across multiple languages. $this->plugin->setSearch('node', array(), array()); $search_result = $this->plugin->execute(); $this->assertEqual(count($search_result), 6, 'The search found total six results'); // Test with language filters and common key word. $this->plugin->setSearch('node', array('f' => array('language:hu')), array()); $search_result = $this->plugin->execute(); $this->assertEqual(count($search_result), 2, 'The search found 2 results'); // Test to check for the language of result items. foreach ($search_result as $result) { $this->assertEqual($result['langcode'], 'hu', 'The search found the correct Hungarian result'); } // Mark one of the nodes for reindexing, using the API function, and // verify indexing status. search_mark_for_reindex('node_search', $this->searchableNodes[0]->id()); $this->assertIndexCounts(1, 8, 'after marking one node to reindex via API function'); // Update the index and verify the totals again. $this->plugin = $this->container->get('plugin.manager.search')->createInstance('node_search'); $this->plugin->updateIndex(); search_update_totals(); $this->assertIndexCounts(0, 8, 'after indexing again'); // Mark one node for reindexing by saving it, and verify indexing status. $this->searchableNodes[1]->save(); $this->assertIndexCounts(1, 8, 'after marking one node to reindex via save'); // The request time is always the same throughout test runs. Update the // request time to a previous time, to simulate it having been marked // previously. $current = REQUEST_TIME; $old = $current - 10; db_update('search_dataset')->fields(array('reindex' => $old))->condition('reindex', $current, '>=')->execute(); // Save the node again. Verify that the request time on it is not updated. $this->searchableNodes[1]->save(); $result = db_select('search_dataset', 'd')->fields('d', array('reindex'))->condition('type', 'node_search')->condition('sid', $this->searchableNodes[1]->id())->execute()->fetchField(); $this->assertEqual($result, $old, 'Reindex time was not updated if node was already marked'); // Add a bogus entry to the search index table using a different search // type. This will not appear in the index status, because it is not // managed by a plugin. search_index('foo', $this->searchableNodes[0]->id(), 'en', 'some text'); $this->assertIndexCounts(1, 8, 'after adding a different index item'); // Mark just this "foo" index for reindexing. search_mark_for_reindex('foo'); $this->assertIndexCounts(1, 8, 'after reindexing the other search type'); // Mark everything for reindexing. search_mark_for_reindex(); $this->assertIndexCounts(8, 8, 'after reindexing everything'); // Clear one item from the index, but with wrong language. $this->assertDatabaseCounts(8, 1, 'before clear'); search_index_clear('node_search', $this->searchableNodes[0]->id(), 'hu'); $this->assertDatabaseCounts(8, 1, 'after clear with wrong language'); // Clear using correct language. search_index_clear('node_search', $this->searchableNodes[0]->id(), 'en'); $this->assertDatabaseCounts(7, 1, 'after clear with right language'); // Don't specify language. search_index_clear('node_search', $this->searchableNodes[1]->id()); $this->assertDatabaseCounts(6, 1, 'unspecified language clear'); // Clear everything in 'foo'. search_index_clear('foo'); $this->assertDatabaseCounts(6, 0, 'other index clear'); // Clear everything. search_index_clear(); $this->assertDatabaseCounts(0, 0, 'complete clear'); }
function do_update() { $query = $this->EE->db->query("SELECT COUNT(*) AS count FROM exp_template_groups"); $num = $query->row('count') + 1; $this->EE->db->query("insert into exp_template_groups(group_name, group_order) values ('search', '$num')"); $id = $DB->insert_id; $Q[] = "insert into exp_templates(group_id, template_name, template_data) values ('$id', 'index', '".addslashes(search_index())."')"; $Q[] = "insert into exp_templates(group_id, template_name, template_data) values ('$id', 'results', '".addslashes(search_results())."')"; $Q[] = "insert into exp_templates(group_id, template_name, template_type, template_data) values ('$id', 'search_css', 'css', '".addslashes(search_css())."')"; // Define the table changes $Q[] = "ALTER TABLE exp_member_groups ADD COLUMN can_search char(1) NOT NULL default 'n'"; $Q[] = "ALTER TABLE exp_member_groups ADD COLUMN search_flood_control mediumint(5) unsigned NOT NULL"; $Q[] = "ALTER TABLE exp_member_groups ADD COLUMN can_moderate_comments char(1) NOT NULL default 'n'"; $Q[] = "ALTER TABLE exp_weblogs ADD COLUMN search_excerpt int(4) unsigned NOT NULL"; $Q[] = "ALTER TABLE exp_weblogs ADD COLUMN comment_moderate char(1) NOT NULL default 'n'"; $Q[] = "ALTER TABLE exp_comments ADD COLUMN status char(1) NOT NULL default 'o'"; $Q[] = "ALTER TABLE exp_referrers ADD COLUMN ref_ip varchar(16) default '0' NOT NULL"; $Q[] = "ALTER TABLE exp_referrers ADD COLUMN ref_date int(10) unsigned default '0' NOT NULL"; $Q[] = "ALTER TABLE exp_referrers ADD COLUMN ref_agent varchar(100) NOT NULL"; $Q[] = "ALTER TABLE exp_templates ADD COLUMN php_parse_location char(1) NOT NULL default 'o'"; // Fix DB typos $Q[] = "ALTER TABLE exp_member_homepage CHANGE COLUMN memeber_search_form member_search_form char(1) NOT NULL default 'n'"; $Q[] = "ALTER TABLE exp_member_homepage CHANGE COLUMN memeber_search_form_order member_search_form_order int(3) unsigned NOT NULL default '0'"; $Q[] = "UPDATE exp_actions SET method = 'retrieve_password' WHERE class = 'Member' AND method = 'retreive_password'"; // Add keys to some tables $Q[] = "ALTER TABLE exp_weblog_titles ADD INDEX(weblog_id)"; $Q[] = "ALTER TABLE exp_weblog_titles ADD INDEX(author_id)"; $Q[] = "ALTER TABLE exp_category_posts ADD INDEX(entry_id)"; $Q[] = "ALTER TABLE exp_category_posts ADD INDEX(cat_id)"; $Q[] = "ALTER TABLE exp_weblogs ADD INDEX(cat_group)"; $Q[] = "ALTER TABLE exp_weblogs ADD INDEX(status_group)"; $Q[] = "ALTER TABLE exp_weblogs ADD INDEX(field_group)"; // Search module $Q[] = "INSERT INTO exp_modules (module_name, module_version, has_cp_backend) VALUES ('Search', '1.0', 'n')"; $Q[] = "INSERT INTO exp_actions (class, method) VALUES ('Search', 'do_search')"; // Email module $Q[] = "INSERT INTO exp_modules (module_name, module_version, has_cp_backend) VALUES ('Email', '1.0', 'n')"; $Q[] = "INSERT INTO exp_actions (class, method) VALUES ('Email', 'send_email')"; $Q[] = "CREATE TABLE IF NOT EXISTS exp_search ( search_id varchar(32) NOT NULL, search_date int(10) NOT NULL, member_id int(10) unsigned NOT NULL, ip_address varchar(16) NOT NULL, total_results int(6) NOT NULL, per_page tinyint(3) unsigned NOT NULL, query text NOT NULL, result_page varchar(70) NOT NULL, PRIMARY KEY `search_id` (`search_id`) )"; $Q[] = "CREATE TABLE IF NOT EXISTS exp_blacklisted ( blacklisted_type VARCHAR(20) NOT NULL, blacklisted_value TEXT NOT NULL )"; $Q[] = "CREATE TABLE IF NOT EXISTS exp_email_tracker ( email_id int(10) unsigned NOT NULL auto_increment, email_date int(10) unsigned default '0' NOT NULL, sender_ip varchar(16) NOT NULL, sender_email varchar(75) NOT NULL , sender_username varchar(50) NOT NULL , number_recipients int(4) unsigned default '1' NOT NULL, PRIMARY KEY `email_id` (`email_id`) )"; // Run the queries foreach ($Q as $sql) { $this->EE->db->query($sql); } /** ----------------------------------------- /** Update Member Groups with search prefs /** -----------------------------------------*/ $query = $this->EE->db->query("SELECT group_id FROM exp_member_groups ORDER BY group_id"); foreach ($query->result_array() as $row) { $flood = ($row['group_id'] == 1) ? '0' : '30'; $this->EE->db->query("UPDATE exp_member_groups SET can_search = 'y', search_flood_control = '$flood' WHERE group_id = '".$row['group_id']."'"); $st = ($row['group_id'] == 1) ? 'y' : 'n'; $this->EE->db->query("UPDATE exp_member_groups SET can_moderate_comments = '$st' WHERE group_id = '".$row['group_id']."'"); } /** ----------------------------------------- /** Fix pm member import problem /** -----------------------------------------*/ // Do we have custom fields? $query = $this->EE->db->query("SELECT COUNT(*) AS count FROM exp_member_data"); $md_exists = ($query->row('count') > 0) ? TRUE : FALSE; // We need to run through the member table and add two fields if they are missing $query = $this->EE->db->query("SELECT member_id FROM exp_members"); foreach ($query->result_array() as $row) { $member_id = $row['member_id']; $res = $this->EE->db->query("SELECT member_id FROM exp_member_homepage WHERE member_id = '$member_id'"); if ($res->num_rows() == 0) $this->EE->db->query("INSERT INTO exp_member_homepage (member_id) VALUES ('$member_id')"); if ($md_exists == TRUE) { $res = $this->EE->db->query("SELECT member_id FROM exp_member_data WHERE member_id = '$member_id'"); if ($resnum_rows() == 0) { $this->EE->db->query("INSERT INTO exp_member_data (member_id) VALUES ('$member_id')"); } } } /** ----------------------------------------- /** Update config file with new prefs /** -----------------------------------------*/ $data = array( 'word_separator' => '_', 'license_number' => '' ); $this->EE->config->_append_config_1x($data); return TRUE; }
/** * Update Drupal's full-text index for this module. * * Modules can implement this hook if they want to use the full-text indexing * mechanism in Drupal. * * This hook is called every cron run if search.module is enabled. A module * should check which of its items were modified or added since the last * run. It is advised that you implement a throttling mechanism which indexes * at most 'search_cron_limit' items per run (see example below). * * You should also be aware that indexing may take too long and be aborted if * there is a PHP time limit. That's why you should update your internal * bookkeeping multiple times per run, preferably after every item that * is indexed. * * Per item that needs to be indexed, you should call search_index() with * its content as a single HTML string. The search indexer will analyse the * HTML and use it to assign higher weights to important words (such as * titles). It will also check for links that point to nodes, and use them to * boost the ranking of the target nodes. * * @ingroup search */ function hook_update_index() { $last = variable_get('node_cron_last', 0); $limit = (int) variable_get('search_cron_limit', 100); $result = db_query_range('SELECT n.nid, c.last_comment_timestamp FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d) ORDER BY GREATEST(n.created, n.changed, c.last_comment_timestamp) ASC', $last, $last, $last, 0, $limit); while ($node = db_fetch_object($result)) { $last_comment = $node->last_comment_timestamp; $node = node_load(array('nid' => $node->nid)); // We update this variable per node in case cron times out, or if the node // cannot be indexed (PHP nodes which call drupal_goto, for example). // In rare cases this can mean a node is only partially indexed, but the // chances of this happening are very small. variable_set('node_cron_last', max($last_comment, $node->changed, $node->created)); // Get node output (filtered and with module-specific fields). if (node_hook($node, 'view')) { node_invoke($node, 'view', false, false); } else { $node = node_prepare($node, false); } // Allow modules to change $node->body before viewing. module_invoke_all('node_view', $node, false, false); $text = '<h1>' . drupal_specialchars($node->title) . '</h1>' . $node->body; // Fetch extra data normally not visible $extra = module_invoke_all('node_update_index', $node); foreach ($extra as $t) { $text .= $t; } // Update index search_index($node->nid, 'node', $text); } }
/** * Returns the search form and (possibly) the search results. * * @uses search_index * @return string */ function search_result() { global $Cfg, $Current_weblog, $search_a; $search_formname = lang('accessibility', 'search_formname'); $search_fldname = lang('accessibility', 'search_fldname'); $search_idname = lang('accessibility', 'search_idname'); $search_placeholder = lang('accessibility', 'search_placeholder'); // build up accessible form, keeping track of current weblog (if multiple) $form = '<form method="post" action="search.php" class="pivot-search-result">' . "\n"; $form .= '<fieldset><legend>' . $search_formname . '</legend>' . "\n"; $form .= '<label for="' . $search_idname . '">' . $search_fldname . '</label>' . "\n"; $form .= '<input id="' . $search_idname . '" type="text" name="search" class="result-searchbox" value="'; $form .= htmlspecialchars($search_a[0]) . '" onfocus="this.select();" />' . "\n"; $form .= '<input type="submit" class="result-searchbutton" value="' . lang('weblog_text', 'search') . '" />' . "\n"; if ($Cfg['weblog_count'] > 1) { $form .= '<input type="hidden" name="w" value="' . $Current_weblog . '" />' . "\n"; } $form .= '</fieldset></form>' . "\n"; // add search results - if any $output = search_index($search_a); $output = str_replace("%search_form%", $form, $output); return $output; }
$object->addSoftkey('5', Aastra_get_label('Move Down', $language), $XML_SERVER . '?user='******'&action=down'); $object->addSoftkey('6', Aastra_get_label('Exit', $language), 'SoftKey:Exit'); } else { $object->addSoftkey('3', Aastra_get_label('Move Up', $language), $XML_SERVER . '?user='******'&action=up'); $object->addSoftkey('8', Aastra_get_label('Move Down', $language), $XML_SERVER . '?user='******'&action=down'); $object->addSoftkey('6', Aastra_get_label('Clear', $language), $XML_SERVER . '?user='******'&action=clear'); $object->addSoftkey('9', Aastra_get_label('Back', $language), $XML_SERVER . '?user='******'&action=list'); $object->setCancelAction($XML_SERVER . '?user='******'&action=list'); $object->addSoftkey('10', Aastra_get_label('Exit', $language), 'SoftKey:Exit'); } } break; case 'zoom': case 'zoomfav': # Retrieve city index $key = search_index($city, $array); # Open and retrieve RSS XML file $http = 'http://timeanddate.com/worldclock/city.html?n=' . $city; $handle = @fopen($http, 'r'); $found = 0; $title = $array[$key]['name']; if ($handle) { while ($line = fgets($handle, 1000) and $found != 2) { switch ($found) { case '0': $value = trim($previous_line, '\\n') . trim($line, '\\n'); if (stristr($value, 'Current Time')) { $found = 1; } break; case '1':
/** * Indexes a single node. * * @param \Drupal\node\NodeInterface $node * The node to index. */ protected function indexNode(NodeInterface $node) { // Save the changed time of the most recent indexed node, for the search // results half-life calculation. $this->state->set('node.cron_last', $node->getChangedTime()); $languages = $node->getTranslationLanguages(); $node_render = $this->entityManager->getViewBuilder('node'); foreach ($languages as $language) { $node = $node->getTranslation($language->id); // Render the node. $build = $node_render->view($node, 'search_index', $language->id); unset($build['#theme']); $node->rendered = drupal_render($build); $text = '<h1>' . String::checkPlain($node->label($language->id)) . '</h1>' . $node->rendered; // Fetch extra data normally not visible. $extra = $this->moduleHandler->invokeAll('node_update_index', array($node, $language->id)); foreach ($extra as $t) { $text .= $t; } // Update index. search_index($node->id(), $this->getPluginId(), $text, $language->id); } }
function random_refresh_filegal() { global $feature_galleries; global $tikilib; $cant = $tikilib->getOne("select count(*) from `tiki_file_galleries`", array()); if ($cant > 0) { $query = "select * from `tiki_file_galleries`"; $result = $tikilib->query($query, array(), 1, rand(0, $cant - 1)); $res = $result->fetchRow(); $words =& search_index($res["name"] . " " . $res["description"]); insert_index($words, "filegal", $res["galleryId"]); } }
function refresh_index($object_type, $object_id = null) { if (empty($object_type)) { return false; } global $tikilib; $wiki_html = ''; $query_from = " from `tiki_{$object_type}`"; $query_limit = -1; $query_offset = 0; $query_vars = array(); $query_where = ''; $query_fields = ''; $cant_query = 'select count(*)' . $query_from; $cant_vars = null; //$filtering_expr = array('$content = strip_tags($content);'); // strip tags seems to be bugged (maybe due to UTF-8 content ?) $mb = function_exists('mb_ereg_replace') ? 'mb_' : ''; $filtering_expr = array('$content = ' . $mb . 'ereg_replace("<\\s*/?\\s*([a-zA-Z]+)[^>]*>", " ", $content);'); switch ($object_type) { case 'articles': //case 'art': case 'article': $index_type = 'article'; $f_id = 'articleId'; $f_content = array('title', 'authorName', 'heading', 'body', 'author', 'topline', 'subtitle'); break; case 'blog_posts': //case 'blog': case 'blog_post': $index_type = 'blog_post'; $f_id = 'postId'; $f_content = array('title', 'user', 'data'); break; case 'blogs': $index_type = 'blog'; $f_id = 'blogId'; $f_content = array('title', 'user', 'description'); break; case 'directory_categories': //case 'dir_cat': $index_type = 'dir_cat'; $f_id = 'categId'; $f_content = array('name', 'description'); break; case 'directory_sites': //case 'dir': case 'dir_site': $index_type = 'dir_site'; $f_id = 'siteId'; $f_content = array('name', 'description'); break; case 'comments': //case 'wiki comment': case 'comment': $f_index_type = 'objectType'; $filtering_expr[] = '$index_type .= "comment";'; $f_id = 'threadId'; $f_content = array('title', 'data', 'summary', 'objectType'); break; case 'faq_questions': $index_type = 'faq_question'; $f_id = 'questionId'; $f_content = array('question', 'answer'); break; case 'faqs': //case 'faq': $index_type = 'faq'; $f_id = 'faqId'; $f_content = array('title', 'description'); break; case 'file_galleries': $index_type = 'filegal'; $f_id = 'galleryId'; $f_content = array('name', 'description'); break; case 'files': //case 'fgal': case 'file': $index_type = 'file'; $f_id = 'fileId'; $f_content = array('data', 'description', 'name', 'search_data', 'filename', 'comment'); $f_other = array('archiveId', 'filetype'); $query_where = ' where archiveId = ?'; $query_vars = array(0); $fulltext_mimetypes_pattern = '/^text\\//i'; // Mimetypes that will be fulltext indexed unset($filtering_expr); break; case 'forums': //case 'forum': $index_type = 'forum'; $f_id = 'forumId'; $f_content = array('name', 'description', 'moderator'); break; case 'images': //case 'gal': case 'img': $index_type = 'img'; $f_id = 'imageId'; $f_content = array('name', 'description'); break; case 'pages': //case 'wiki page': case 'wiki': $index_type = 'wiki'; $f_id = 'pageName'; $f_content = array('data', 'description', 'pageName'); array_unshift($filtering_expr, '$content = $tikilib->parse_data($content, $res["is_html"]);'); $wiki_html = ', `is_html`'; break; case 'tracker_items': //case 'track': case 'trackeritem': $cant_query = 'select count(*) from `tiki_tracker_item_fields` f, `tiki_tracker_fields` tf where tf.`type` in (?,?) and tf.`fieldId`=f.`fieldId`'; $cant_vars = array('t', 'a'); $index_type = 'trackeritem'; $query_from = ' from `tiki_tracker_item_fields` f, `tiki_tracker_fields` tf'; $query_where = ' where tf.`type` in (?,?) and tf.`fieldId`=f.`fieldId`'; $query_vars = array('t', 'a'); $f_id = array('id1' => 'f.`itemId`', 'id2' => 'f.`fieldId`'); $f_content = array('content' => 'f.`value`'); break; case 'trackers': //case 'tracker': $index_type = 'tracker'; $f_id = 'trackerId'; $f_content = array('name', 'description'); break; case 'galleries': // case 'imggal': $index_type = 'imggal'; $f_id = 'galleryId'; $f_content = array('name', 'description'); break; } if ($object_id == -1) { // Random indexation... $query_limit = 1; $cant = $tikilib->getOne($cant_query, $cant_vars); if ($cant > 0) { $query_offset = rand(0, $cant - 1); } else { return true; } } elseif (is_integer($object_id) && $object_id != 0 || is_string($object_id)) { // Index one object identified by its id $query_vars[] = $object_id; $query_where .= ($query_where == '' ? ' where ' : ' and ') . (is_array($f_id) ? $f_id['id1'] : $f_id) . ' = ?'; } if (!empty($f_id) && !empty($f_content)) { if (!is_array($f_id)) { $f_id = array($f_id); } if (!is_array($f_content)) { $f_content = array($f_content); } foreach ($f_id as $k_id => $v_id) { $query_fields .= ($query_fields != '' ? ', ' : '') . $v_id . (is_string($k_id) ? ' as ' . $k_id : ''); } foreach ($f_content as $k_content => $v_content) { $query_fields .= ', ' . $v_content . (is_string($k_content) ? ' as ' . $k_content : ''); } if (!empty($f_other)) { $query_fields .= ', ' . (is_array($f_other) ? implode(', ', $f_other) : $f_other); } $result = $tikilib->query('select ' . $query_fields . $wiki_html . $query_from . $query_where, $query_vars, $query_limit, $query_offset); if ($result) { while ($res = $result->fetchRow()) { if (is_array($res)) { $id = ''; $content = ''; // For performance reasons, do not index all files with fulltext (depending on their mimetypes) if ($index_type == 'file' && !preg_match($fulltext_mimetypes_pattern, $res['filetype'])) { $res['data'] = ''; } foreach ($f_id as $k_id => $v_id) { $id .= ($id != '' ? '#' : '') . $res[is_string($k_id) ? $k_id : $v_id]; } foreach ($f_content as $k_content => $v_content) { $content .= ' ' . $res[is_string($k_content) ? $k_content : $v_content]; } if (isset($f_index_type) && $f_index_type != '') { $index_type = $res[$f_index_type]; } if (is_array($filtering_expr)) { foreach ($filtering_expr as $expr) { eval($expr); } } if ($content != '' && $index_type != '' && $id != '') { insert_index(search_index($content), $index_type, $id); } } } } } return true; }
/** * {@inheritdoc} */ public function updateIndex() { // Interpret the cron limit setting as the maximum number of nodes to index // per cron run. $limit = (int)$this->searchSettings->get('index.cron_limit'); $language = \Drupal::languageManager()->getCurrentLanguage()->getId(); $topics = $this->getSids($this->advancedHelp->getTopics()); // If we got interrupted by limit, this will contain the last module // and topic we looked at. $last = \Drupal::state()->get($this->getPluginId() . '.last_cron', ['time' => 0]); $count = 0; foreach ($topics as $module => $module_topics) { // Fast forward if necessary. if (!empty($last['module']) && $last['module'] != $module) { continue; } foreach ($module_topics as $topic => $info) { // Fast forward if necessary. if (!empty($last['topic']) && $last['topic'] != $topic) { continue; } //If we've been looking to catch up, and we have, reset so we // stop fast forwarding. if (!empty($last['module'])) { unset($last['topic']); unset($last['module']); } $file = $this->advancedHelp->getTopicFileName($module, $topic); if ($file && (empty($info['sid']) || filemtime($file) > $last['time'])) { if (empty($info['sid'])) { $info['sid'] = $this->database->insert('advanced_help_index') ->fields([ 'module' => $module, 'topic' => $topic, 'langcode' => $language ]) ->execute(); } } // Update index, using search index "type" equal to the plugin ID. search_index($this->getPluginId(), $info['sid'], $language, file_get_contents($file)); $count++; if ($count >= $limit) { $last['module'] = $module; $last['topic'] = $topic; \Drupal::state()->set($this->getPluginId() . '.last_cron', $last); return; } } } \Drupal::state()->set($this->getPluginId() . '.last_cron', ['time' => time()]); }