Browse Source

Merge https://github.com/Spuds/playpen

emanuele 13 years ago
parent
commit
7b108e57da
4 changed files with 52 additions and 18 deletions
  1. 1 1
      Sources/PackageGet.php
  2. 16 10
      Sources/Search.php
  3. 28 2
      Sources/SearchAPI-Fulltext.php
  4. 7 5
      Themes/default/index.template.php

+ 1 - 1
Sources/PackageGet.php

@@ -632,7 +632,7 @@ function PackageUpload()
 	if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '')
 		fatal_lang_error('package_upload_error_nofile');
 	elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name'])))
-		fatal_lang_error('package_upload_error_failure');
+		fatal_lang_error('package_upload_error_failed');
 
 	// Make sure it has a sane filename.
 	$_FILES['package']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['package']['name']);

+ 16 - 10
Sources/Search.php

@@ -56,6 +56,9 @@ function PlushSearch1()
 		'name' => $txt['search']
 	);
 
+	// This is hard coded maximum string length.
+	$context['search_string_limit'] = 100;
+
 	$context['require_verification'] = $user_info['is_guest'] && !empty($modSettings['search_enable_captcha']) && empty($_SESSION['ss_vv_passed']);
 	if ($context['require_verification'])
 	{
@@ -617,7 +620,7 @@ function PlushSearch2()
 	// Remove the phrase parts and extract the words.
 	$wordArray = preg_replace('~(?:^|\s)(?:[-]?)"(?:[^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), ' ', $search_params['search']);
 	$wordArray = explode(' ',  $smcFunc['htmlspecialchars'](un_htmlspecialchars($wordArray), ENT_QUOTES));
-	
+
 	// A minus sign in front of a word excludes the word.... so...
 	$excludedWords = array();
 	$excludedIndexWords = array();
@@ -633,7 +636,7 @@ function PlushSearch2()
 				$excludedWords[] = $word;
 			unset($phraseArray[$index]);
 		}
-		}
+	}
 
 	// Now we look for -test, etc.... normaller.
 	foreach ($wordArray as $index => $word)
@@ -708,6 +711,7 @@ function PlushSearch2()
 			'words' => array(),
 			'subject_words' => array(),
 			'all_words' => array(),
+			'complex_words' => array(),
 		);
 
 		// Sort the indexed words (large words -> small words -> excluded words).
@@ -752,6 +756,7 @@ function PlushSearch2()
 		{
 			$searchWords[$orIndex]['indexed_words'] = array_slice($searchWords[$orIndex]['indexed_words'], 0, 7);
 			$searchWords[$orIndex]['subject_words'] = array_slice($searchWords[$orIndex]['subject_words'], 0, 7);
+			$searchWords[$orIndex]['words'] = array_slice($searchWords[$orIndex]['words'], 0, 4);
 		}
 	}
 
@@ -1646,7 +1651,7 @@ function PlushSearch2()
 					else
 						$_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows']();
 				}
-				else
+				elseif ($_SESSION['search_cache']['num_results'] == -1)
 					$_SESSION['search_cache']['num_results'] = 0;
 			}
 		}
@@ -1821,7 +1826,7 @@ function PlushSearch2()
  *
  * What it does:
  * - callback function for the results sub template.
-		- loads the necessary contextual data to show a search result.
+ * - loads the necessary contextual data to show a search result.
  *
  * @param $reset = false
  * @return array
@@ -1907,9 +1912,9 @@ function prepareSearchContext($reset = false)
 				$message['body'] = un_htmlspecialchars(strtr($message['body'], array('&nbsp;' => ' ', '<br />' => "\n", '&#91;' => '[', '&#93;' => ']', '&#58;' => ':', '&#64;' => '@')));
 
 				if (empty($modSettings['search_method']) || $force_partial_word)
-					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
+					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
 				else
-					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
+					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
 
 				$message['body'] = '';
 				foreach ($matches[0] as $index => $match)
@@ -2055,6 +2060,7 @@ function prepareSearchContext($reset = false)
 	{
 		// Fix the international characters in the keyword too.
 		$query = un_htmlspecialchars($query);
+		$query = trim($query, "\*+");
 		$query = strtr($smcFunc['htmlspecialchars']($query), array('\\\'' => '\''));
 
 		$body_highlighted = preg_replace('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => '&#039;')), '/') . ')/ie' . ($context['utf8'] ? 'u' : ''), "'\$2' == '\$1' ? stripslashes('\$1') : '<strong class=\"highlight\">\$1</strong>'", $body_highlighted);
@@ -2087,10 +2093,10 @@ function prepareSearchContext($reset = false)
 	return $output;
 }
 
-/*
+/**
  * Creates a search API and returns the object.
  *
-*/
+ */
 function findSearchAPI()
 {
 	global $sourcedir, $modSettings, $search_versions, $searchAPI, $txt;
@@ -2127,8 +2133,8 @@ function findSearchAPI()
 /**
  * This function compares the length of two strings plus a little.
  * What it does:
-		- callback function for usort used to sort the fulltext results.
-		- passes sorting duty to the current API.
+ * - callback function for usort used to sort the fulltext results.
+ * - passes sorting duty to the current API.
  *
  * @param string $a
  * @param string $b

+ 28 - 2
Sources/SearchAPI-Fulltext.php

@@ -114,12 +114,32 @@ class fulltext_search
 	// Do we have to do some work with the words we are searching for to prepare them?
 	public function prepareIndexes($word, &$wordsSearch, &$wordsExclude, $isExcluded)
 	{
-		global $modSettings;
+		global $modSettings, $smcFunc;
 
 		$subwords = text2words($word, null, false);
 
 		if (!$this->canDoBooleanSearch && count($subwords) > 1 && empty($modSettings['search_force_index']))
 			$wordsSearch['words'][] = $word;
+		elseif (empty($modSettings['search_force_index']) && $this->canDoBooleanSearch)
+		{
+			// A boolean capable search engine and not forced to only use an index, we may use a non index search
+			// this is harder on the server so we are restrictive here
+			if (count($subwords) > 1 && preg_match('~[.:@$]~', $word))
+			{
+				// using special characters that a full index would ignore and the remaining words are short which would also be ignored
+				if (($smcFunc['strlen'](current($subwords)) < $this->min_word_length) && ($smcFunc['strlen'](next($subwords)) < $this->min_word_length))
+				{
+					$wordsSearch['words'][] = trim($word, "/*- ");
+					$wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"';
+				}
+			}
+			elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length)
+			{
+				// short words have feelings too
+				$wordsSearch['words'][] = trim($word, "/*- ");
+				$wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"';
+			}
+		}
 
 		if ($this->canDoBooleanSearch)
 		{
@@ -208,11 +228,17 @@ class fulltext_search
 		elseif ($this->canDoBooleanSearch)
 		{
 			$query_params['boolean_match'] = '';
+
+			// remove any indexed words that are used in the complex body search terms
+			$words['indexed_words'] = array_diff($words['indexed_words'], $words['complex_words']);
+
 			foreach ($words['indexed_words'] as $fulltextWord)
 				$query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' ';
 			$query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1);
 
-			$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
+			// if we have bool terms to search, add them in
+			if ($query_params['boolean_match'])
+				$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
 		}
 		else
 		{

+ 7 - 5
Themes/default/index.template.php

@@ -113,11 +113,6 @@ function template_html_above()
 
 	// Here comes the JavaScript bits!
 	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-			$(document).ready(function() { 
-				$("ul.dropmenu").superfish(); 
-			});
-	// ]]></script>
 	<script type="text/javascript"><!-- // --><![CDATA[
 		var smf_theme_url = "', $settings['theme_url'], '";
 		var smf_default_theme_url = "', $settings['default_theme_url'], '";
@@ -139,6 +134,13 @@ function template_html_above()
 	// ]]></script>';
 
 	template_javascript();
+	
+	echo '
+	<script type="text/javascript"><!-- // --><![CDATA[
+			$(document).ready(function() { 
+				$("ul.dropmenu").superfish(); 
+			});
+	// ]]></script>';
 
 	echo '
 	<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />