diff --git a/administrator/components/com_finder/config.xml b/administrator/components/com_finder/config.xml index f2f61b38fe0e8..9bc869619cd2e 100644 --- a/administrator/components/com_finder/config.xml +++ b/administrator/components/com_finder/config.xml @@ -234,6 +234,17 @@ description="COM_FINDER_FIELDSET_INDEX_OPTIONS_DESCRIPTION" > + + + + + get('tuplecount', 1); + } + if (is_null($multilingual)) { $multilingual = Multilanguage::isEnabled(); @@ -127,33 +133,28 @@ public static function tokenize($input, $lang, $phrase = false) $tokens[] = new FinderIndexerToken($terms[$i], $language->language); } - // Create two and three word phrase tokens from the individual words. - for ($i = 0, $n = count($tokens); $i < $n; $i++) + // Create multi-word phrase tokens from the individual words. + if ($tuplecount > 1) { - // Setup the phrase positions. - $i2 = $i + 1; - $i3 = $i + 2; - - // Create the two word phrase. - if ($i2 < $n && isset($tokens[$i2])) + for ($i = 0, $n = count($tokens); $i < $n; $i++) { - // Tokenize the two word phrase. - $token = new FinderIndexerToken(array($tokens[$i]->term, $tokens[$i2]->term), $language->language, $language->spacer); - $token->derived = true; - - // Add the token to the stack. - $tokens[] = $token; - } - - // Create the three word phrase. - if ($i3 < $n && isset($tokens[$i3])) - { - // Tokenize the three word phrase. - $token = new FinderIndexerToken(array($tokens[$i]->term, $tokens[$i2]->term, $tokens[$i3]->term), $language->language, $language->spacer); - $token->derived = true; - - // Add the token to the stack. - $tokens[] = $token; + $temp = array($tokens[$i]->term); + + // Create tokens for 2 to $tuplecount length phrases + for ($j = 1; $j < $tuplecount; $j++) + { + if ($i + $j >= $n || !isset($tokens[$i + $j])) + { + break; + } + + $temp[] = $tokens[$i + $j]->term; + $token = new FinderIndexerToken($temp, $language->language, $language->spacer); + $token->derived = true; + + // Add the token to the stack. + $tokens[] = $token; + } } } } diff --git a/administrator/components/com_finder/helpers/indexer/query.php b/administrator/components/com_finder/helpers/indexer/query.php index 730837b451037..cccea43cc0401 100644 --- a/administrator/components/com_finder/helpers/indexer/query.php +++ b/administrator/components/com_finder/helpers/indexer/query.php @@ -9,6 +9,7 @@ defined('_JEXEC') or die; +use Joomla\CMS\Component\ComponentHelper; use Joomla\Registry\Registry; use Joomla\String\StringHelper; use Joomla\Utilities\ArrayHelper; @@ -738,11 +739,12 @@ protected function processDates($date1, $date2, $when1, $when2) protected function processString($input, $lang, $mode) { // Clean up the input string. - $input = html_entity_decode($input, ENT_QUOTES, 'UTF-8'); - $input = StringHelper::strtolower($input); - $input = preg_replace('#\s+#mi', ' ', $input); - $input = trim($input); - $debug = JFactory::getConfig()->get('debug_lang'); + $input = html_entity_decode($input, ENT_QUOTES, 'UTF-8'); + $input = StringHelper::strtolower($input); + $input = preg_replace('#\s+#mi', ' ', $input); + $input = trim($input); + $debug = JFactory::getConfig()->get('debug_lang'); + $params = ComponentHelper::getParams('com_finder'); /* * First, we need to handle string based modifiers. String based @@ -900,51 +902,33 @@ protected function processString($input, $lang, $mode) // Get the number of words in the phrase. $parts = explode(' ', $match); + $tuplecount = $params->get('tuplecount', 1); - // Check if the phrase is longer than three words. - if (count($parts) > 3) + // Check if the phrase is longer than our $tuplecount. + if (count($parts) > $tuplecount && $tuplecount > 1) { + $chunk = array_slice($parts, 0, $tuplecount); + $parts = array_slice($parts, $tuplecount); + + // If the chunk is not empty, add it as a phrase. + if (count($chunk)) + { + $phrases[] = implode(' ', $chunk); + $terms[] = implode(' ', $chunk); + } + /* - * If the phrase is longer than three words, we need to + * If the phrase is longer than $tuplecount words, we need to * break it down into smaller chunks of phrases that - * are less than or equal to three words. We overlap + * are less than or equal to $tuplecount words. We overlap * the chunks so that we can ensure that a match is * found for the complete phrase and not just portions * of it. */ - for ($i = 0, $c = count($parts); $i < $c; $i += 2) + for ($i = 0, $c = count($parts); $i < $c; $i++) { - // Set up the chunk. - $chunk = array(); - - // The chunk has to be assembled based on how many - // pieces are available to use. - switch ($c - $i) - { - /* - * If only one word is left, we can break from - * the switch and loop because the last word - * was already used at the end of the last - * chunk. - */ - case 1: - break 2; - - // If there words are left, we use them both as - // the last chunk of the phrase and we're done. - case 2: - $chunk[] = $parts[$i]; - $chunk[] = $parts[$i + 1]; - break; - - // If there are three or more words left, we - // build a three word chunk and continue on. - default: - $chunk[] = $parts[$i]; - $chunk[] = $parts[$i + 1]; - $chunk[] = $parts[$i + 2]; - break; - } + array_shift($chunk); + $chunk[] = array_shift($parts); // If the chunk is not empty, add it as a phrase. if (count($chunk)) @@ -956,7 +940,7 @@ protected function processString($input, $lang, $mode) } else { - // The phrase is <= 3 words so we can use it as is. + // The phrase is <= $tuplecount words so we can use it as is. $phrases[] = $match; $terms[] = $match; } @@ -1050,7 +1034,7 @@ protected function processString($input, $lang, $mode) { // Tokenize the current term. $token = FinderIndexerHelper::tokenize($terms[$i], $lang, true); - $token = $this->getTokenData($token); + $token = $this->getTokenData(array_shift($token)); // Set the required flag. $token->required = false; @@ -1071,7 +1055,7 @@ protected function processString($input, $lang, $mode) // Tokenize the term after the next term (current plus two). $other = FinderIndexerHelper::tokenize($terms[$i + 2], $lang, true); - $other = $this->getTokenData($other); + $other = $this->getTokenData(array_shift($other)); // Set the required flag. $other->required = false; @@ -1116,7 +1100,7 @@ protected function processString($input, $lang, $mode) // Tokenize the next term (current plus one). $other = FinderIndexerHelper::tokenize($terms[$i + 1], $lang, true); - $other = $this->getTokenData($other); + $other = $this->getTokenData(array_shift($other)); // Set the required flag. $other->required = false; diff --git a/administrator/language/en-GB/en-GB.com_finder.ini b/administrator/language/en-GB/en-GB.com_finder.ini index b2b136345f524..509a43070a41c 100644 --- a/administrator/language/en-GB/en-GB.com_finder.ini +++ b/administrator/language/en-GB/en-GB.com_finder.ini @@ -46,6 +46,9 @@ COM_FINDER_CONFIG_TEXT_MULTIPLIER_DESCRIPTION="The multiplier is used to control COM_FINDER_CONFIG_TEXT_MULTIPLIER_LABEL="Body Text Weight Multiplier" COM_FINDER_CONFIG_TITLE_MULTIPLIER_DESCRIPTION="The multiplier is used to control how much influence matching text has on the overall relevance score of a search result. A multiplier is considered in relationship to the other multipliers. The title text comes from the title of the content." COM_FINDER_CONFIG_TITLE_MULTIPLIER_LABEL="Title Text Weight Multiplier" +COM_FINDER_CONFIG_TUPLECOUNT_LABEL="Search for Phrases" +COM_FINDER_CONFIG_TUPLECOUNT_PHRASE_DISABLED="Disabled (Improved performance)" +COM_FINDER_CONFIG_TUPLECOUNT_PHRASE_ENABLED="Enabled (Improved search results)" COM_FINDER_CONFIGURATION="Smart Search: Options" COM_FINDER_CREATE_FILTER="Create a filter." COM_FINDER_EDIT_FILTER="Edit Filter" diff --git a/components/com_finder/tmpl/search/default_form.php b/components/com_finder/tmpl/search/default_form.php index e71709acbc11d..2d3ee4cbcceeb 100644 --- a/components/com_finder/tmpl/search/default_form.php +++ b/components/com_finder/tmpl/search/default_form.php @@ -61,7 +61,14 @@ params->get('show_advanced_tips', 1)) : ?>
- + + + + + params->get('tuplecount', 1) > 1) : ?> + + +
diff --git a/language/en-GB/en-GB.com_finder.ini b/language/en-GB/en-GB.com_finder.ini index 982629456a908..8c4ae4e618b23 100644 --- a/language/en-GB/en-GB.com_finder.ini +++ b/language/en-GB/en-GB.com_finder.ini @@ -5,7 +5,12 @@ COM_FINDER="Smart Search" COM_FINDER_ADVANCED_SEARCH_TOGGLE="Advanced Search" -COM_FINDER_ADVANCED_TIPS="

Here are a few examples of how you can use the search feature:

Entering this and that into the search form will return results with both "this" and "that".

Entering this not that into the search form will return results with "this" and not "that".

Entering this or that into the search form will return results with either "this" or "that".

Entering "this and that" (with quotes) into the search form will return results with the exact phrase "this and that".

Search results can also be filtered using a variety of criteria. Select one or more filters below to get started.

" +COM_FINDER_ADVANCED_TIPS_INTRO="

Here are a few examples of how you can use the search feature:

" +COM_FINDER_ADVANCED_TIPS_AND="

Entering this and that into the search form will return results containing both "this" and "that".

" +COM_FINDER_ADVANCED_TIPS_NOT="

Entering this not that into the search form will return results containing "this" and not "that".

" +COM_FINDER_ADVANCED_TIPS_OR="

Entering this or that into the search form will return results containing either "this" or "that".

" +COM_FINDER_ADVANCED_TIPS_PHRASE="

Entering "this and that" (with quotes) into the search form will return results containing the exact phrase "this and that".

" +COM_FINDER_ADVANCED_TIPS_OUTRO="

Search results can also be filtered using a variety of criteria. Select one or more filters below to get started.

" COM_FINDER_DEFAULT_PAGE_TITLE="Search Results" COM_FINDER_FILTER_BRANCH_LABEL="Search by %s" COM_FINDER_FILTER_DATE_BEFORE="Before"