function ajaxsearchpro_deactivate_fulltext() { global $wpdb; $fulltext = wpdreams_fulltext::getInstance(); $indexes = array('posts' => array('asp_title', 'asp_content', 'asp_excerpt', 'asp_title_content', 'asp_title_excerpt', 'asp_content_excerpt', 'asp_title_content_excerpt')); $blogs = wpdreams_get_blog_list(0, 'all'); if (is_multisite() && is_array($blogs) && count($blogs)) { foreach ($blogs as $k => $blog) { switch_to_blog($blog['blog_id']); $fulltext->removeIndexes($indexes); } restore_current_blog(); } else { $fulltext->removeIndexes($indexes); } update_option('asp_fulltext_indexed', 0); print "<div class='psuccessMsg'>Indexes removed!</div>"; die; }
<div class="item"> <p class='infoMsg'>Only set to YES if you have performance issues!</p> <?php $o = new wpdreamsYesNo("asp_dbuseregularwhenshort", "Use regular search if the phrase is lower then the min. char count, instead of Boolean mode ", postval_or_getoption('asp_dbuseregularwhenshort')); ?> </div> <div class="item"> <input type='submit' class='submit' value='Save options'/> </div> <?php $_r = ob_get_clean(); ?> <?php $fulltext = wpdreams_fulltext::getInstance(); $fulltext_enabled = $fulltext->check(array('posts')); $fulltext_indexed = $fulltext->indexExists('posts', 'asp_title'); $updated = false; if (isset($_POST) && isset($_POST['fulltext']) && wpdreamsType::getErrorNum() == 0) { foreach ($_POST as $key => $value) { if (is_string($key) && strpos('asp_', $key) == 0) { update_option($key, $value); $updated = true; } } } ?> <?php $_comp = wpdreamsCompatibility::Instance(); if ($_comp->has_errors()) {
protected function do_search() { global $wpdb; global $q_config; if (isset($wpdb->base_prefix)) { $_prefix = $wpdb->base_prefix; } else { $_prefix = $wpdb->prefix; } $options = $this->options; $searchData = $this->searchData; $s = $this->s; $_s = $this->_s; $q_config['language'] = $options['qtranslate_lang']; $rel_title = ""; $rel_content = ""; $rel_excerpt = ""; $rel_terms = ""; $like = ""; $rel_title = ""; /** * Fallback or Boolean when strlen < N */ $is_too_short = false; $not_exact_phrase = ''; $fulltext = wpdreams_fulltext::getInstance(); foreach ($_s as $_pp) { if (strlen($_pp) < $fulltext->getMinWordLength()) { $is_too_short = true; $not_exact_phrase .= " " . $_pp . "*"; } else { $not_exact_phrase .= " " . $_pp; } } $not_exact_phrase = trim($not_exact_phrase); $exact_phrase = '"' . $s . '"'; if (get_option('asp_dbuseregularwhenshort') == 1 && $is_too_short) { return parent::do_search(); } /** * Construct the INDEX name to search */ $match_against = '1'; $relevance = ''; $fixed_phrase = !$options['set_exactonly'] ? $exact_phrase : $not_exact_phrase; $boolean_mode = get_option('asp_fulltext_indexed') == 0 || $is_too_short || !$options['set_exactonly'] ? ' IN BOOLEAN MODE' : ''; $index_name = $options['set_intitle'] ? "{$wpdb->posts}.post_title" : ''; if ($index_name == '') { $index_name .= $options['set_incontent'] ? "{$wpdb->posts}.post_content" : ''; } else { $index_name .= $options['set_incontent'] ? ", {$wpdb->posts}.post_content" : ''; } if ($index_name == '') { $index_name .= $options['set_inexcerpt'] ? "{$wpdb->posts}.post_excerpt" : ''; } else { $index_name .= $options['set_inexcerpt'] ? ", {$wpdb->posts}.post_excerpt" : ''; } if ($index_name != '') { $match_against = " MATCH(" . $index_name . ") AGAINST ('" . $fixed_phrase . "'" . $boolean_mode . ") "; } if ($match_against != '1') { $relevance = "\n (\n MATCH(" . $index_name . ") AGAINST ('" . $exact_phrase . "'" . $boolean_mode . ") + \n MATCH(" . $index_name . ") AGAINST ('" . $not_exact_phrase . "'" . $boolean_mode . ")\n )\n "; } $selected_customs = array(); if (isset($options['customset'])) { $selected_customs = $options['customset']; } if (is_array($selected_customs)) { foreach ($selected_customs as $k => $v) { if ($where != "") { $where .= " OR {$wpdb->posts}.post_type='" . $v . "'"; } else { $where = "{$wpdb->posts}.post_type='" . $v . "'"; } } } $where = $where == '' ? '1' : $where; $_sr = implode("%' OR lower({$wpdb->terms}.name) like '%", $_s); $rel_terms = ""; if ($searchData['searchinterms']) { if ($options['set_exactonly']) { $sr = $_sr; if ($like != "") { $sr = " OR lower({$wpdb->terms}.name) like '%" . $sr . "%'"; } else { $sr = " lower({$wpdb->terms}.name) like '%" . $sr . "%'"; } } else { if ($like != "") { $sr = " OR lower({$wpdb->terms}.name) like '%" . $s . "%'"; } else { $sr = " lower({$wpdb->terms}.name) like '%" . $s . "%'"; } } $like .= $sr; } $selected_customfields = $searchData['selected-customfields']; if (is_array($selected_customfields) && count($selected_customfields) > 0) { if ($options['set_exactonly']) { $sr = implode("%' OR lower({$wpdb->postmeta}.meta_value) like '%", $_s); $sr = "lower({$wpdb->postmeta}.meta_value) like '%" . $sr . "%'"; } else { $sr = "lower({$wpdb->postmeta}.meta_value) like '%" . $s . "%'"; } $ws = ""; foreach ($selected_customfields as $k => $v) { if ($ws != "") { $ws .= " OR {$wpdb->postmeta}.meta_key='" . $v . "'"; } else { $ws .= "{$wpdb->postmeta}.meta_key='" . $v . "'"; } } if ($like != "") { $like .= " OR ((" . $sr . ") AND (" . $ws . "))"; } else { $like .= "((" . $sr . ") AND (" . $ws . "))"; } } if (isset($searchData['excludeposts']) && $searchData['excludeposts'] != "") { $exclude_posts = "{$wpdb->posts}.ID NOT IN (" . $searchData['excludeposts'] . ")"; } else { $exclude_posts = "{$wpdb->posts}.ID NOT IN (-55)"; } $like = $like == '' ? 0 : $like; $orderby = isset($searchData['selected-orderby']) && $searchData['selected-orderby'] != '' ? $searchData['selected-orderby'] : "post_date DESC"; //$s=strtolower(addslashes($_POST['aspp'])); $querystr = "\n \t\tSELECT \n {$wpdb->posts}.post_title as title,\n {$wpdb->posts}.ID as id,\n {$wpdb->posts}.post_date as date, \n {$wpdb->posts}.post_content as content,\n {$wpdb->posts}.post_excerpt as excerpt,\n {$wpdb->users}.user_nicename as author,\n GROUP_CONCAT(DISTINCT {$wpdb->terms}.term_id) as term_id,\n {$wpdb->posts}.post_type as post_type,"; if ($searchData['userelevance'] == 1 && $relevance != '') { $querystr .= $relevance; } else { $querystr .= "1 "; } $querystr .= " \n as relevance\n \t\tFROM {$wpdb->posts}\n LEFT JOIN {$wpdb->postmeta} ON {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID\n LEFT JOIN {$wpdb->users} ON {$wpdb->users}.ID = {$wpdb->posts}.post_author\n LEFT JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id\n LEFT JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id\n LEFT JOIN {$wpdb->terms} ON {$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id\n \t\tWHERE\n ({$wpdb->posts}.post_status='publish' {$searchin}) AND\n (" . $where . ") \n AND (" . $match_against . " OR (" . $like . "))\n AND (" . $exclude_posts . ")\n GROUP BY\n {$wpdb->posts}.ID"; $querystr .= " ORDER BY relevance DESC, " . $wpdb->posts . "." . $orderby . "\n LIMIT " . $searchData['maxresults']; $pageposts = $wpdb->get_results($querystr, OBJECT); //var_dump($querystr); var_dump($pageposts);die("!!"); $this->results = $pageposts; return $pageposts; }
function fulltext() { global $wpdb; $fulltext = wpdreams_fulltext::getInstance(); $tables = array('posts'); $blogs = wpdreams_get_blog_list(0, 'all'); update_option('asp_fulltext', 0); update_option('asp_fulltext_indexed', 0); if (is_multisite() && is_array($blogs) && count($blogs)) { foreach ($blogs as $k => $blog) { switch_to_blog($blog['blog_id']); if ($fulltext->check($tables)) { update_option('asp_fulltext', 1); } } restore_current_blog(); } else { if ($fulltext->check($tables)) { update_option('asp_fulltext', 1); } } }