Skip to content

Commit

Permalink
Merge branch '4.0-dev' into path1
Browse files Browse the repository at this point in the history
  • Loading branch information
amitranjan2 committed Jan 31, 2019
2 parents 1d2c966 + 747c878 commit b5bc22b
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 29 deletions.
@@ -0,0 +1,5 @@
ALTER TABLE `#__finder_terms`
DROP INDEX `idx_term`,
ADD UNIQUE INDEX `idx_term` (`term`, `language`);
ALTER TABLE `#__finder_terms`
ADD INDEX `language` (`language`);
@@ -0,0 +1,4 @@
ALTER TABLE "#__finder_terms"
DROP CONSTRAINT "#__finder_terms_idx_term",
ADD CONSTRAINT "#__finder_terms_idx_term_language" UNIQUE ("term", "language");
CREATE INDEX "#__finder_terms_idx_language" on "#__finder_terms" ("language");
22 changes: 22 additions & 0 deletions administrator/components/com_finder/config.xml
Expand Up @@ -328,6 +328,28 @@
<option value="">COM_FINDER_CONFIG_LANGUAGE_DEFAULT_NONE</option>
</field>

<field
name="filter_commonwords"
type="radio"
label="COM_FINDER_CONFIG_FILTER_COMMONWORDS_LABEL"
class="switcher"
default="0"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

<field
name="filter_numerics"
type="radio"
label="COM_FINDER_CONFIG_FILTER_NUMERICS_LABEL"
class="switcher"
default="0"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

</fieldset>

<fieldset
Expand Down
Expand Up @@ -300,8 +300,8 @@ public function index($item, $format = 'html')
' FROM ' . $db->quoteName('#__finder_tokens') . ' AS t1' .
' WHERE t1.context = %d' .
' ) AS t1' .
' JOIN ' . $db->quoteName('#__finder_tokens') . ' AS t2 ON t2.term = t1.term' .
' LEFT JOIN ' . $db->quoteName('#__finder_terms') . ' AS t ON t.term = t1.term' .
' JOIN ' . $db->quoteName('#__finder_tokens') . ' AS t2 ON t2.term = t1.term AND t2.language = t1.language' .
' LEFT JOIN ' . $db->quoteName('#__finder_terms') . ' AS t ON t.term = t1.term AND t.language = t1.language' .
' WHERE t2.context = %d' .
' GROUP BY t1.term, t.term_id, t1.term, t1.stem, t1.common, t1.phrase, t1.weight, t1.context, t1.language' .
' ORDER BY t1.term DESC';
Expand Down Expand Up @@ -347,7 +347,7 @@ public function index($item, $format = 'html')
*/
$query = $db->getQuery(true)
->update($db->quoteName('#__finder_tokens_aggregate') . ' AS ta')
->join('INNER', $db->quoteName('#__finder_terms') . ' AS t ON t.term = ta.term')
->join('INNER', $db->quoteName('#__finder_terms') . ' AS t ON t.term = ta.term AND t.language = ta.language')
->set('ta.term_id = t.term_id')
->where('ta.term_id = 0');
$db->setQuery($query);
Expand Down
34 changes: 24 additions & 10 deletions administrator/components/com_finder/helpers/indexer/helper.php
Expand Up @@ -269,26 +269,40 @@ public static function addContentType($title, $mime = null)
*/
public static function isCommon($token, $lang)
{
static $data;
static $default;
static $data, $default, $multilingual;

$langCode = $lang;
if (is_null($multilingual))
{
$multilingual = Multilanguage::isEnabled();
$config = ComponentHelper::getParams('com_finder');

if ($config->get('language_default', '') == '')
{
$default = '*';
}
elseif ($config->get('language_default', '') == '-1')
{
$default = self::getPrimaryLanguage(self::getDefaultLanguage());
}
else
{
$default = self::getPrimaryLanguage($config->get('language_default'));
}
}

// If language requested is wildcard, use the default language.
if ($lang == '*')
if (!$multilingual || $lang == '*')
{
$default = $default === null ? substr(self::getDefaultLanguage(), 0, 2) : $default;
$langCode = $default;
$lang = $default;
}

// Load the common tokens for the language if necessary.
if (!isset($data[$langCode]))
if (!isset($data[$lang]))
{
$data[$langCode] = self::getCommonWords($langCode);
$data[$lang] = self::getCommonWords($lang);
}

// Check if the token is in the common array.
return in_array($token, $data[$langCode], true);
return in_array($token, $data[$lang], true);
}

/**
Expand Down
29 changes: 26 additions & 3 deletions administrator/components/com_finder/helpers/indexer/indexer.php
Expand Up @@ -9,6 +9,7 @@

defined('_JEXEC') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\String\StringHelper;

JLoader::register('FinderIndexerHelper', __DIR__ . '/helper.php');
Expand Down Expand Up @@ -483,8 +484,8 @@ private function tokenizeToDbShort($input, $context, $lang, $format, $count)
/**
* Method to add a set of tokens to the database.
*
* @param mixed $tokens An array or single FinderIndexerToken object.
* @param mixed $context The context of the tokens. See context constants. [optional]
* @param FinderIndexerToken[] $tokens An array or single FinderIndexerToken object.
* @param mixed $context The context of the tokens. See context constants. [optional]
*
* @return integer The number of tokens inserted into the database.
*
Expand All @@ -493,6 +494,15 @@ private function tokenizeToDbShort($input, $context, $lang, $format, $count)
*/
protected function addTokensToDb($tokens, $context = '')
{
static $filterCommon, $filterNumeric;

if (is_null($filterCommon))
{
$params = ComponentHelper::getParams('com_finder');
$filterCommon = $params->get('filter_commonwords', false);
$filterNumeric = $params->get('filter_numerics', false);
}

// Get the database object.
$db = $this->db;

Expand All @@ -514,6 +524,16 @@ protected function addTokensToDb($tokens, $context = '')
// Iterate through the tokens to create SQL value sets.
foreach ($tokens as $token)
{
if ($filterCommon && $token->common)
{
continue;
}

if ($filterNumeric && $token->numeric)
{
continue;
}

$query->values(
$db->quote($token->term) . ', '
. $db->quote($token->stem) . ', '
Expand All @@ -526,7 +546,10 @@ protected function addTokensToDb($tokens, $context = '')
++$values;
}

$db->setQuery($query)->execute();
if ($query->values)
{
$db->setQuery($query)->execute();
}
}

return $values;
Expand Down
87 changes: 81 additions & 6 deletions administrator/components/com_finder/helpers/indexer/query.php
Expand Up @@ -111,7 +111,7 @@ class FinderIndexerQuery
* Allow empty searches
*
* @var boolean
* @since 4.0.0
* @since __DEPLOY_VERSION__
*/
public $empty;

Expand Down Expand Up @@ -384,7 +384,10 @@ public function getExcludedTermIds()
// Iterate through the excluded tokens and compile the matching terms.
for ($i = 0, $c = count($this->excluded); $i < $c; $i++)
{
$results = array_merge($results, $this->excluded[$i]->matches);
foreach ($this->excluded[$i]->matches as $match)
{
$results = array_merge($results, $match);
}
}

// Sanitize the terms.
Expand Down Expand Up @@ -423,7 +426,10 @@ public function getIncludedTermIds()
}

// Add the matches to the stack.
$results[$term] = array_merge($results[$term], $this->included[$i]->matches);
foreach ($this->included[$i]->matches as $match)
{
$results[$term] = array_merge($results[$term], $match);
}
}

// Sanitize the terms.
Expand Down Expand Up @@ -463,7 +469,10 @@ public function getRequiredTermIds()
}

// Add the matches to the stack.
$results[$term] = array_merge($results[$term], $this->included[$i]->matches);
foreach ($this->included[$i]->matches as $match)
{
$results[$term] = array_merge($results[$term], $match);
}
}
}

Expand Down Expand Up @@ -987,6 +996,16 @@ protected function processString($input, $lang, $mode)
$token = FinderIndexerHelper::tokenize($terms[$i], $lang, true);
$token = $this->getTokenData(array_shift($token));

if ($params->get('filter_commonwords', 0) && $token->common)
{
continue;
}

if ($params->get('filter_numeric', 0) && $token->numeric)
{
continue;
}

// Set the required flag.
$token->required = true;

Expand Down Expand Up @@ -1035,6 +1054,16 @@ protected function processString($input, $lang, $mode)
$token = FinderIndexerHelper::tokenize($terms[$i], $lang, true);
$token = $this->getTokenData(array_shift($token));

if ($params->get('filter_commonwords', 0) && $token->common)
{
continue;
}

if ($params->get('filter_numeric', 0) && $token->numeric)
{
continue;
}

// Set the required flag.
$token->required = false;

Expand Down Expand Up @@ -1101,6 +1130,16 @@ protected function processString($input, $lang, $mode)
$other = FinderIndexerHelper::tokenize($terms[$i + 1], $lang, true);
$other = $this->getTokenData(array_shift($other));

if ($params->get('filter_commonwords', 0) && $token->common)
{
continue;
}

if ($params->get('filter_numeric', 0) && $token->numeric)
{
continue;
}

// Set the required flag.
$other->required = false;

Expand Down Expand Up @@ -1139,6 +1178,16 @@ protected function processString($input, $lang, $mode)
$other = FinderIndexerHelper::tokenize($terms[$i + 1], $lang, true);
$other = $this->getTokenData(array_shift($other));

if ($params->get('filter_commonwords', 0) && $token->common)
{
continue;
}

if ($params->get('filter_numeric', 0) && $token->numeric)
{
continue;
}

// Set the required flag.
$other->required = false;

Expand Down Expand Up @@ -1179,6 +1228,16 @@ protected function processString($input, $lang, $mode)
$token = FinderIndexerHelper::tokenize($phrases[$i], $lang, true);
$token = $this->getTokenData(array_shift($token));

if ($params->get('filter_commonwords', 0) && $token->common)
{
continue;
}

if ($params->get('filter_numeric', 0) && $token->numeric)
{
continue;
}

// Set the required flag.
$token->required = true;

Expand Down Expand Up @@ -1214,6 +1273,16 @@ protected function processString($input, $lang, $mode)
// Get the token data.
$token = $this->getTokenData($token);

if ($params->get('filter_commonwords', 0) && $token->common)
{
continue;
}

if ($params->get('filter_numerics', 0) && $token->numeric)
{
continue;
}

// Set the required flag for the token.
$token->required = $mode === 'AND' ? ($token->phrase ? false : true) : false;

Expand Down Expand Up @@ -1268,7 +1337,8 @@ protected function getTokenData($token)
{
// Add the term to the query.
$query->where('(t.term = ' . $db->quote($token->term) . ' OR t.stem = ' . $db->quote($token->stem) . ')')
->where('t.phrase = 0');
->where('t.phrase = 0')
->where('t.language IN (\'*\',' . $query->q($token->language) . ')');
}

// Get the terms.
Expand All @@ -1284,7 +1354,12 @@ protected function getTokenData($token)
// Add the matches to the token.
for ($i = 0, $c = count($matches); $i < $c; $i++)
{
$token->matches[$matches[$i]->term] = (int) $matches[$i]->term_id;
if (!isset($token->matches[$matches[$i]->term]))
{
$token->matches[$matches[$i]->term] = array();
}

$token->matches[$matches[$i]->term][] = (int) $matches[$i]->term_id;
}
}

Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/en-GB.com_finder.ini
Expand Up @@ -14,6 +14,8 @@ COM_FINDER_CONFIG_ENABLE_LOGGING_LABEL="Enable Logging"
COM_FINDER_CONFIG_EXPAND_ADVANCED_LABEL="Expand Advanced Search"
COM_FINDER_CONFIG_FIELD_OPENSEARCH_DESCRIPTON_LABEL="OpenSearch Description"
COM_FINDER_CONFIG_FIELD_OPENSEARCH_NAME_LABEL="OpenSearch Name"
COM_FINDER_CONFIG_FILTER_COMMONWORDS_LABEL="Filter Common Words"
COM_FINDER_CONFIG_FILTER_NUMERICS_LABEL="Filter Numeric Terms"
COM_FINDER_CONFIG_GATHER_SEARCH_STATISTICS_LABEL="Gather Search Statistics"
COM_FINDER_CONFIG_HILIGHT_CONTENT_SEARCH_TERMS_LABEL="Highlight Search Terms"
COM_FINDER_CONFIG_LANGUAGE_DEFAULT_DEFAULT_LANGUAGE="Default Site Language"
Expand Down
12 changes: 7 additions & 5 deletions components/com_finder/Model/SearchModel.php
Expand Up @@ -320,6 +320,7 @@ protected function getListQuery()
else
{
$query->where('false');
break;
}
}
}
Expand Down Expand Up @@ -381,10 +382,11 @@ protected function getStoreId($id = '', $page = true)
protected function populateState($ordering = null, $direction = null)
{
// Get the configuration options.
$app = \JFactory::getApplication();
$input = $app->input;
$params = $app->getParams();
$user = \JFactory::getUser();
$app = \JFactory::getApplication();
$input = $app->input;
$params = $app->getParams();
$user = \JFactory::getUser();
$language = \JFactory::getLanguage();

$this->setState('filter.language', Multilanguage::isEnabled());

Expand All @@ -404,7 +406,7 @@ protected function populateState($ordering = null, $direction = null)
$options['input'] = $request->getString('q', $params->get('q', ''));

// Get the query language.
$options['language'] = $request->getCmd('l', $params->get('l', ''));
$options['language'] = $request->getCmd('l', $params->get('l', $language->getTag()));

// Get the start date and start date modifier filters.
$options['date1'] = $request->getString('d1', $params->get('d1', ''));
Expand Down
2 changes: 1 addition & 1 deletion installation/sql/mysql/joomla.sql
Expand Up @@ -929,7 +929,7 @@ CREATE TABLE IF NOT EXISTS `#__finder_terms` (
`links` int(10) NOT NULL DEFAULT 0,
`language` char(7) NOT NULL DEFAULT '',
PRIMARY KEY (`term_id`),
UNIQUE KEY `idx_term` (`term`),
UNIQUE KEY `idx_term` (`term`,`language`),
KEY `idx_term_phrase` (`term`,`phrase`),
KEY `idx_stem_phrase` (`stem`,`phrase`),
KEY `idx_soundex_phrase` (`soundex`,`phrase`)
Expand Down

0 comments on commit b5bc22b

Please sign in to comment.