- md5
- 19e8a9c31bfdecfd5b1d84f298e2ca6e
- sha1
- 840580e7aa1d5d74a26ad709b993769ad1ec61b8
- sha256
- 9eb11b2d0ed171585ea20b32044075ba1f9f38076048a4c21ab28713612f1656
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
<?php
/**
* @package Joomla.Administrator
* @subpackage com_finder
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\String\StringHelper;
/**
* Language support class for the Finder indexer package.
*
* @since 4.0.0
*/
class FinderIndexerLanguage
{
/**
* Language support instances container.
*
* @var FinderIndexerLanguage[]
* @since 4.0.0
*/
protected $instances = array();
/**
* Language locale of the class
*
* @var string
* @since 4.0.0
*/
public $language;
/**
* Spacer to use between terms
*
* @var string
* @since 4.0.0
*/
public $spacer = ' ';
/**
* Method to get a language support object.
*
* @param string $language The language of the support object.
*
* @return FinderIndexerLanguage A FinderIndexerLanguage instance.
*
* @since 4.0.0
*/
public static function getInstance($language)
{
if (isset($instances[$language]))
{
return $instances[$language];
}
if ($language == '*')
{
$instances[$language] = new FinderIndexerLanguage;
return $instances[$language];
}
$locale = FinderIndexerHelper::getPrimaryLanguage($language);
$class = 'FinderIndexerLanguage' . $locale;
$path = __DIR__ . '/language/' . $locale . '.php';
if (is_file($path))
{
JLoader::register($class, $path);
}
if (class_exists($class))
{
$instances[$language] = new $class;
}
else
{
$instances[$language] = new FinderIndexerLanguage;
$instances[$language]->language = $locale;
}
return $instances[$language];
}
/**
* Method to tokenise a text string.
*
* @param string $input The input to tokenise.
*
* @return array An array of term strings.
*
* @since 4.0.0
*/
public function tokenise($input)
{
$quotes = html_entity_decode('‘’'', ENT_QUOTES, 'UTF-8');
/*
* Parsing the string input into terms is a multi-step process.
*
* Regexes:
* 1. Remove everything except letters, numbers, quotes, apostrophe, plus, dash, period, and comma.
* 2. Remove plus, dash, period, and comma characters located before letter characters.
* 3. Remove plus, dash, period, and comma characters located after other characters.
* 4. Remove plus, period, and comma characters enclosed in alphabetical characters. Ungreedy.
* 5. Remove orphaned apostrophe, plus, dash, period, and comma characters.
* 6. Remove orphaned quote characters.
* 7. Replace the assorted single quotation marks with the ASCII standard single quotation.
* 8. Remove multiple space characters and replaces with a single space.
*/
$input = StringHelper::strtolower($input);
$input = preg_replace('#[^\pL\pM\pN\p{Pi}\p{Pf}\'+-.,]+#mui', ' ', $input);
$input = preg_replace('#(^|\s)[+-.,]+([\pL\pM]+)#mui', ' $1', $input);
$input = preg_replace('#([\pL\pM\pN]+)[+-.,]+(\s|$)#mui', '$1 ', $input);
$input = preg_replace('#([\pL\pM]+)[+.,]+([\pL\pM]+)#muiU', '$1 $2', $input);
$input = preg_replace('#(^|\s)[\'+-.,]+(\s|$)#mui', ' ', $input);
$input = preg_replace('#(^|\s)[\p{Pi}\p{Pf}]+(\s|$)#mui', ' ', $input);
$input = preg_replace('#[' . $quotes . ']+#mui', '\'', $input);
$input = preg_replace('#\s+#mui', ' ', $input);
$input = trim($input);
// Explode the normalized string to get the terms.
$terms = explode(' ', $input);
return $terms;
}
/**
* Method to stem a token.
*
* @param string $token The token to stem.
*
* @return string The stemmed token.
*
* @since 4.0.0
*/
public function stem($token)
{
return $token;
}
}
The same content is in 2 releases, Joomla 4.0.0-alpha5 to 4.0.0-alpha6. See them all, or every version of this file.