Wie kann ich bestimmte Inhalts-Typen von der Such-Indizierung ausnehmen?
Eingetragen von maximago (860) am 20.08.2007 - 14:05 Uhr in
Es kann gewünscht sein, dass bestimmte Inhalte nicht mit in den Index aufgenommen werden. z.B. um die Anzeige in den Suchergebnissen zu unterbinden.
Dies kann mit einem kleinen Modul leicht realisiert werden:
<?php
/**
* Implementation of hook_perm().
*/
function searchfilter_perm() {
return array('manage searchfilter');
}
/**
* Implementation of hook_access().
*/
function searchfilter_access($op, $node) {
global $user;
switch ($op) {
case ('create'):
return user_access('manage searchfilter');
break;
}
}
function searchfilter_menu($may_cache) {
$items = array();
$items[] = array(
'path' => 'admin/settings/searchfilter',
'title' => t('Searchfilter'),
'description' => t('Configure Searchfilter.'),
'type' => MENU_NORMAL_ITEM,
'weight' => 1,
'priority' => 1,
'access' => user_access('manage searchfilter'),
'callback' => 'drupal_get_form',
'callback arguments' => array('searchfilter_settings'),
);
return $items;
}
function searchfilter_settings() {
$contenttypes = array();
$result = db_query("SELECT type, name, description FROM {node_type} ORDER BY name");
while ($contenttype = db_fetch_object($result)) {
$contenttypes[$contenttype->type] = $contenttype->name . "<br/>" . $contenttype->description;
}
$current = variable_get('searchfilter_type', '');
$current[0] = 0;
$form['searchfilter']['heading1'] = array(
'#type' => 'markup',
'#value' => t('<p>Configure the searchfilter here. By activating a contenttype, it will be removed from index and not be found by search.</p>'),
);
$form['searchfilter']['#type'] = 'fieldset';
$form['searchfilter']['#title'] = t('Available contenttypes');
$form['searchfilter']['searchfilter_type'] = array(
'#type' => 'checkboxes',
'#title' => t('Select contenttypes to disable'),
'#default_value' => $current,
'#options' => $contenttypes,
'#multiple' => TRUE,
);
return system_settings_form($form);
}
// hook_update_index implementation. Ensure special content-types aren't shown in search
function searchfilter_update_index() {
if (function_exists('search_wipe')) {
$searchfilter_types = (array) variable_get('searchfilter_type',0);
$search_string = '';
foreach ($searchfilter_types as $searchfilter_type) {
$search_string = ($searchfilter_type==NULL ? $search_string : $search_string." OR '".$searchfilter_type."'");
}
$search_string = substr($search_string, 4, strlen($search_string));
$search_string = "SELECT nid FROM {node} WHERE type = ".$search_string;
$result = db_query($search_string);
while ($data = db_fetch_object($result)) {
search_wipe($data->nid, 'node');
}
}
}
- Anmelden oder Registrieren um Kommentare zu schreiben
Neue Kommentare
vor 1 Stunde 42 Minuten
vor 1 Tag 1 Stunde
vor 1 Tag 8 Stunden
vor 1 Tag 18 Stunden
vor 1 Tag 18 Stunden
vor 1 Tag 19 Stunden
vor 1 Tag 19 Stunden
vor 1 Tag 19 Stunden
vor 1 Tag 20 Stunden
vor 1 Tag 22 Stunden