From d53e2ef32393ea7af70b64ec55315feabad118e5 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 26 Jun 2020 15:49:42 -0400 Subject: [PATCH] Bump version to 3.0.161 --- wire/core/DatabaseQuerySelectFulltext.php | 38 ++++++++++++++++++++--- wire/core/Field.php | 2 +- wire/core/ProcessWire.php | 3 +- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/wire/core/DatabaseQuerySelectFulltext.php b/wire/core/DatabaseQuerySelectFulltext.php index 5d3b86bf..840ba8b0 100644 --- a/wire/core/DatabaseQuerySelectFulltext.php +++ b/wire/core/DatabaseQuerySelectFulltext.php @@ -24,6 +24,7 @@ * https://processwire.com * * @property-read $tableField + * @method array getWordAlternates($word) * * * @@ -516,11 +517,11 @@ class DatabaseQuerySelectFulltext extends Wire { // **+= Contains match + expand $tableField = $this->tableField(); - $not = strpos($this->operator, '!') === 0; $scoreField = $this->getScoreFieldName(); + $expand = strpos($this->operator, '+') !== false; // standard MATCH/AGAINST with optional query expansion - $words = $this->words($value, array('indexable' => true)); + $words = $this->words($value, array('indexable' => true, 'alternates' => $expand)); $againstValue = $this->escapeAGAINST(implode(' ', $words)); if(!count($words) || !strlen(trim($againstValue))) { @@ -529,9 +530,9 @@ class DatabaseQuerySelectFulltext extends Wire { return; } - $match = $not ? 'NOT MATCH' : 'MATCH'; + $match = $this->not ? 'NOT MATCH' : 'MATCH'; $bindKey = $this->query->bindValueGetKey($againstValue); - $againstType = strpos($this->operator, '+') ? 'WITH QUERY EXPANSION' : ''; + $againstType = $expand ? 'WITH QUERY EXPANSION' : ''; $where = "$match($tableField) AGAINST($bindKey $againstType)"; $this->query->select("$where AS $scoreField"); $this->query->where($where); @@ -740,11 +741,21 @@ class DatabaseQuerySelectFulltext extends Wire { 'minWordLength' => 1, // minimum allowed length or true for ft_min_word_len 'stopwords' => true, // allow stopwords 'indexable' => false, // include only indexable words? + 'alternates' => false, // include alternate versions of words? ); $options = count($options) ? array_merge($defaults, $options) : $defaults; if($options['minWordLength'] === true) $options['minWordLength'] = (int) $this->database->getVariable('ft_min_word_len'); $words = $this->wire()->sanitizer->wordsArray($value, $options); + + if($options['alternates']) { + foreach($words as $word) { + $alts = $this->getWordAlternates($word); + foreach($alts as $alt) { + if(!in_array($alt, $words)) $words[] = $alt; + } + } + } if($options['indexable']) { foreach($words as $key => $word) { @@ -815,4 +826,23 @@ class DatabaseQuerySelectFulltext extends Wire { self::$scoreFields[$scoreField] = 1; return $scoreField; } + + /** + * Get other variations of given word to search (such as plural, singular, etc.) + * + * Method is currently used by the **+= operator but will be also added + * to ~~= and ~+= operators shortly. + * + * This method is for hooks to implement. + * + * #pw-hooker + * + * @param string $word + * @return array + * + */ + public function ___getWordAlternates($word) { + if($word) {} + return array(); + } } diff --git a/wire/core/Field.php b/wire/core/Field.php index 2ca0b554..0bccd020 100644 --- a/wire/core/Field.php +++ b/wire/core/Field.php @@ -567,7 +567,7 @@ class Field extends WireData implements Saveable, Exportable { // populate import data foreach($changes as $key => $change) { $this->errors('clear all'); - $this->set($key, $data[$key]); + if(isset($data[$key])) $this->set($key, $data[$key]); if(!empty($data['errors'][$key])) { $error = $data['errors'][$key]; // just in case they switched it to an array of multiple errors, convert back to string diff --git a/wire/core/ProcessWire.php b/wire/core/ProcessWire.php index df8c8a7b..57c90bb7 100644 --- a/wire/core/ProcessWire.php +++ b/wire/core/ProcessWire.php @@ -77,7 +77,7 @@ class ProcessWire extends Wire { * Reversion revision number * */ - const versionRevision = 160; + const versionRevision = 161; /** * Version suffix string (when applicable) @@ -358,6 +358,7 @@ class ProcessWire extends Wire { $version = self::versionMajor . "." . self::versionMinor . "." . self::versionRevision; $config->version = $version; $config->versionName = trim($version . " " . self::versionSuffix); + $config->moduleServiceKey .= str_replace('.', '', $version); // $config->debugIf: optional setting to determine if debug mode should be on or off if($config->debugIf && is_string($config->debugIf)) {