Преглед на файлове

! missing var initialization for advanced search
! fix for paging error on cached results
! fix for highlight now working when search term was at end of the message
! improved logic for determining when to use complex search terms on a fulltext index

Spuds преди 12 години
родител
ревизия
7bcec8a9a2
променени са 2 файла, в които са добавени 22 реда и са изтрити 9 реда
  1. 8 5
      Sources/Search.php
  2. 14 4
      Sources/SearchAPI-Fulltext.php

+ 8 - 5
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)
@@ -1648,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;
 			}
 		}
@@ -1909,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)

+ 14 - 4
Sources/SearchAPI-Fulltext.php

@@ -120,17 +120,27 @@ class fulltext_search
 
 		if (!$this->canDoBooleanSearch && count($subwords) > 1 && empty($modSettings['search_force_index']))
 			$wordsSearch['words'][] = $word;
-		// boolean capable search engine but perhaps using special characters or a short word and not forced to only use an index, Regex it is then
 		elseif (empty($modSettings['search_force_index']) && $this->canDoBooleanSearch)
 		{
-			if ((count($subwords) > 1 && preg_match('~[.:@]~', $word)) || ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length))
+			// 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))
 			{
-				// this will be used in a LIKE or RLIKE term, we will remove it (later) from our indexed_words array
+				// 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)
 		{
 			$fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"';