Пример #1
0
function relevanssi_publish($post, $bypassglobalpost = false)
{
    global $relevanssi_publish_doc;
    $post_status = get_post_status($post);
    if ('auto-draft' == $post_status) {
        return;
    }
    $custom_fields = relevanssi_get_custom_fields();
    relevanssi_index_doc($post, true, $custom_fields, $bypassglobalpost);
}
Пример #2
0
function relevanssi_build_index($extend = false) {
	global $wpdb, $relevanssi_table;
	set_time_limit(0);
	
	$type = get_option("relevanssi_index_type");
	$allow_custom_types = true;
	switch ($type) {
		case "posts":
			$restriction = " AND (post_type = 'post'";
			break;
		case "pages":
			$restriction = " AND (post_type = 'page'";
			break;
		case "public":
			if (function_exists('get_post_types')) {
				$custom_types = implode(',', get_post_types(array('exclude_from_search' => false)));
				$allow_custom_types = false;
			}
			$restriction = "";
			break;
		case "both": 								// really should be "everything"
			$restriction = "";
			$allow_custom_types = false;
			break;
		default:
			$restriction = "";
	}

	if ($allow_custom_types) $custom_types = get_option("relevanssi_custom_types");
	
	if ("" != $custom_types) {
		$types = explode(",", $custom_types);
		if ("" == $restriction) {
			$restriction = " AND (";
		}
		else {
			$restriction .= " OR ";
		}
		$i=0;
		foreach ($types as $type) {
			$type = trim($type);
			if (0 == $i) {
				$restriction .= " post_type = '$type'";
			}
			else {
				$restriction .= " OR post_type = '$type'";
			}
			$i++;
		}
		$restriction .= ")";
	}
	elseif ("" != $restriction) {
		$restriction .= ")";
	}

	$n = 0;
	
	if (!$extend) {
		// truncate table first
		$wpdb->query("TRUNCATE TABLE $relevanssi_table");
		$q = "SELECT *
		FROM $wpdb->posts WHERE (post_status='publish' OR post_status='private')
		AND post_type!='nav_menu_item'" . $restriction;
		update_option('relevanssi_index', '');
	}
	else {
		// extending, so no truncate and skip the posts already in the index
		$limit = get_option('relevanssi_index_limit', 200);
		if ($limit > 0) {
			$limit = " LIMIT $limit";
		}
		$q = "SELECT *
		FROM $wpdb->posts WHERE (post_status='publish' OR post_status='private')
		AND post_type!='nav_menu_item'
		AND ID NOT IN (SELECT DISTINCT(doc) FROM $relevanssi_table)" . $restriction . " $limit";
	}

	$custom_fields = relevanssi_get_custom_fields();

	$content = $wpdb->get_results($q);
	
	foreach ($content as $post) {
		$n += relevanssi_index_doc($post, false, $custom_fields);
		// n calculates the number of insert queries
	}
	
	echo '<div id="message" class="updated fade"><p>' . __("Indexing complete!", "relevanssi") . '</p></div>';
	update_option('relevanssi_indexed', 'done');
}
Пример #3
0
function relevanssi_build_index($extend = false) {
	global $wpdb, $relevanssi_table;
	set_time_limit(0);
	
	get_option('relevanssi_index_attachments') == 'on' ? $attachments = '' : $attachments = "AND post.post_type!='attachment'";
	
	$type = get_option("relevanssi_index_type");
	$allow_custom_types = true;
	switch ($type) {
		case "posts":
			$restriction = " AND (post.post_type = 'post'"; // add table alias to column for modified query - modified by renaissancehack
			break;
		case "pages":
			$restriction = " AND (post.post_type = 'page'"; // add table alias to column for modified query - modified by renaissancehack
			break;
		case "public":
			if (function_exists('get_post_types')) {
				$custom_types = implode(',', get_post_types(array('exclude_from_search' => false)));
				$allow_custom_types = false;
			}
			$restriction = "";
			break;
		case "both": 								// really should be "everything"
			$restriction = "";
			$allow_custom_types = true;
			break;
		default:
			$restriction = "";
	}

	$negative_restriction = "";
	
	if ($allow_custom_types) $custom_types = get_option("relevanssi_custom_types");
	
	if ("" != $custom_types) {
		$types = explode(",", $custom_types);
		if ("" == $restriction) {
			$restriction = " AND (";
		}
		else {
			$restriction .= " OR ";
		}
		$i=0;
		foreach ($types as $type) {
			$type = trim($type);
			if (substr($type, 0, 1) == '-') {
				$type = trim($type, '-');
				$negative_restriction .= "AND post.post_type != '$type'";
				$i--;
			}
			else {
				if (0 == $i) {
					$restriction .= " post.post_type = '$type'";  // add table alias to column for modified query - modified by renaissancehack
				}
				else {
					$restriction .= " OR post.post_type = '$type'";  // add table alias to column for modified query - modified by renaissancehack
				}
			}
			$i++;
		}
		$restriction .= ")";
		if ($restriction == " AND ()") $restriction = "";
	}
	elseif ("" != $restriction) {
		$restriction .= ")";
	}

	$n = 0;
	
	if (!$extend) {
		// truncate table first
		$wpdb->query("TRUNCATE TABLE $relevanssi_table");
// BEGIN modified by renaissancehack
//  modified query to get child records that inherit their post_status
        $q = "SELECT *,parent.post_status as post_status
		FROM $wpdb->posts parent, $wpdb->posts post WHERE
        (parent.post_status='publish' OR parent.post_status='private')
        AND (
            (post.post_status='inherit'
            AND post.post_parent=parent.ID)
            OR
            (parent.ID=post.ID)
        )
		AND post.post_type!='nav_menu_item' AND post.post_type!='revision' $attachments $restriction $negative_restriction";
// END modified by renaissancehack
		update_option('relevanssi_index', '');
	}
	else {
		// extending, so no truncate and skip the posts already in the index
		$limit = get_option('relevanssi_index_limit', 200);
		if ($limit > 0) {
			$limit = " LIMIT $limit";
		}
// BEGIN modified by renaissancehack
//  modified query to get child records that inherit their post_status
        $q = "SELECT *,parent.post_status as post_status
		FROM $wpdb->posts parent, $wpdb->posts post WHERE
        (parent.post_status='publish' OR parent.post_status='private')
        AND (
            (post.post_status='inherit'
            AND post.post_parent=parent.ID)
            OR
            (parent.ID=post.ID)
        )
        AND post.post_type!='nav_menu_item' AND post.post_type!='revision' $attachments
		AND post.ID NOT IN (SELECT DISTINCT(doc) FROM $relevanssi_table) $restriction $limit";
// END modified by renaissancehack
	}

	$custom_fields = relevanssi_get_custom_fields();

	$content = $wpdb->get_results($q);
	
	foreach ($content as $post) {
		$n += relevanssi_index_doc($post, false, $custom_fields);
		// n calculates the number of insert queries
	}
	
	echo '<div id="message" class="updated fade"><p>' . __("Indexing complete!", "relevanssi") . '</p></div>';
	update_option('relevanssi_indexed', 'done');
}
Пример #4
0
function relevanssi_build_index($extend = false)
{
    global $wpdb, $relevanssi_table;
    set_time_limit(0);
    get_option('relevanssi_index_attachments') == 'on' ? $attachments = '' : ($attachments = "AND post.post_type!='attachment'");
    $type = get_option("relevanssi_index_type");
    $allow_custom_types = true;
    $custom_types = "";
    switch ($type) {
        case "posts":
            $restriction = " AND (post.post_type = 'post'";
            // add table alias to column for modified query - modified by renaissancehack
            break;
        case "pages":
            $restriction = " AND (post.post_type = 'page'";
            // add table alias to column for modified query - modified by renaissancehack
            break;
        case "public":
            if (function_exists('get_post_types')) {
                $pt_1 = get_post_types(array('exclude_from_search' => '0'));
                $pt_2 = get_post_types(array('exclude_from_search' => false));
                $custom_types = implode(',', array_merge($pt_1, $pt_2));
                $allow_custom_types = false;
            }
            $restriction = "";
            break;
        case "both":
            // really should be "everything"
            $restriction = "";
            $allow_custom_types = false;
            break;
        case "custom":
            $restriction = "";
            $allow_custom_types = true;
            break;
        default:
            $restriction = "";
    }
    $negative_restriction = "";
    if ($allow_custom_types) {
        $custom_types = get_option("relevanssi_custom_types");
    }
    if (!empty($custom_types)) {
        $types = explode(",", $custom_types);
        if ("" == $restriction) {
            $restriction = " AND (";
        } else {
            $restriction .= " OR ";
        }
        $i = 0;
        foreach ($types as $type) {
            $type = trim($type);
            if (substr($type, 0, 1) == '-') {
                $type = trim($type, '-');
                $negative_restriction .= "AND post.post_type != '{$type}'";
                $i--;
            } else {
                if (0 == $i) {
                    $restriction .= " post.post_type = '{$type}'";
                    // add table alias to column for modified query - modified by renaissancehack
                } else {
                    $restriction .= " OR post.post_type = '{$type}'";
                    // add table alias to column for modified query - modified by renaissancehack
                }
            }
            $i++;
        }
        $restriction .= ")";
        if ($restriction == " AND ()") {
            $restriction = "";
        }
    } elseif ("" != $restriction) {
        $restriction .= ")";
    }
    $n = 0;
    $size = 0;
    if (!$extend) {
        // truncate table first
        relevanssi_clear_index();
        $limit = 0;
    } else {
        $limit = get_option('relevanssi_index_limit', 200);
    }
    $limit_sql = "";
    if ($limit > 0) {
        $size = $limit;
        $limit_sql = " LIMIT {$limit}";
    }
    $q = "SELECT *,parent.post_status as post_status\n\t\tFROM {$wpdb->posts} parent, {$wpdb->posts} post WHERE\n        (parent.post_status IN ('publish', 'private', 'draft', 'pending', 'future'))\n        AND (\n            (post.post_status='inherit'\n            AND post.post_parent=parent.ID)\n            OR\n            (parent.ID=post.ID)\n        )\n\t\tAND post.post_type!='nav_menu_item'\n\t\tAND post.post_type!='revision'\n\t\t{$attachments}\n\t\t{$restriction}\n\t\t{$negative_restriction}\n\t\tAND post.ID NOT IN (SELECT DISTINCT(doc) FROM {$relevanssi_table})\n\t\t{$limit_sql}";
    $custom_fields = relevanssi_get_custom_fields();
    $content = $wpdb->get_results($q);
    foreach ($content as $post) {
        $n += relevanssi_index_doc($post, false, $custom_fields);
        // n calculates the number of insert queries
    }
    echo '<div id="message" class="updated fade"><p>' . __($size == 0 || count($content) < $size ? "Indexing complete!" : "More to index...", "relevanssi") . '</p></div>';
    update_option('relevanssi_indexed', 'done');
    return $size == 0 || count($content) < $size;
}