diff --git a/src/applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php b/src/applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php index bd67f3132c..04d2fad608 100644 --- a/src/applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php +++ b/src/applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php @@ -55,6 +55,8 @@ final class PhabricatorFerretFulltextEngineExtension ->getNgramsFromString($ngrams_source, 'index'); $ferret_document->openTransaction(); + + try { $this->deleteOldDocument($engine, $object, $document); $ferret_document->save(); @@ -85,6 +87,11 @@ final class PhabricatorFerretFulltextEngineExtension $ferret_ngrams->getTableName(), $chunk); } + } catch (Exception $ex) { + $ferret_document->killTransaction(); + throw $ex; + } + $ferret_document->saveTransaction(); } diff --git a/src/applications/search/ngrams/PhabricatorNgramEngine.php b/src/applications/search/ngrams/PhabricatorNgramEngine.php index e168a86127..87abdfc446 100644 --- a/src/applications/search/ngrams/PhabricatorNgramEngine.php +++ b/src/applications/search/ngrams/PhabricatorNgramEngine.php @@ -26,9 +26,11 @@ final class PhabricatorNgramEngine extends Phobject { break; } - $len = (strlen($token) - 2); + $token_v = phutil_utf8v($token); + $len = (count($token_v) - 2); for ($ii = 0; $ii < $len; $ii++) { - $ngram = substr($token, $ii, 3); + $ngram = array_slice($token_v, $ii, 3); + $ngram = implode('', $ngram); $ngrams[$ngram] = $ngram; } }