Differential D18672 Diff 44838 src/applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php
| Show First 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | try { | ||||
| $engine->getFieldTableName(), | $engine->getFieldTableName(), | ||||
| $document_id, | $document_id, | ||||
| $ferret_field['fieldKey'], | $ferret_field['fieldKey'], | ||||
| $ferret_field['rawCorpus'], | $ferret_field['rawCorpus'], | ||||
| $ferret_field['termCorpus'], | $ferret_field['termCorpus'], | ||||
| $ferret_field['normalCorpus']); | $ferret_field['normalCorpus']); | ||||
| } | } | ||||
| if ($ngrams) { | |||||
| $common = queryfx_all( | |||||
| $conn, | |||||
| 'SELECT ngram FROM %T WHERE ngram IN (%Ls)', | |||||
| $engine->getCommonNgramsTableName(), | |||||
| $ngrams); | |||||
| $common = ipull($common, 'ngram', 'ngram'); | |||||
| foreach ($ngrams as $key => $ngram) { | |||||
| if (isset($common[$ngram])) { | |||||
| unset($ngrams[$key]); | |||||
| continue; | |||||
| } | |||||
| // NOTE: MySQL discards trailing whitespace in CHAR(X) columns. | |||||
| $trim_ngram = rtrim($ngram, ' '); | |||||
| if (isset($common[$ngram])) { | |||||
| unset($ngrams[$key]); | |||||
| continue; | |||||
| } | |||||
| } | |||||
| } | |||||
| if ($ngrams) { | |||||
| $sql = array(); | $sql = array(); | ||||
| foreach ($ngrams as $ngram) { | foreach ($ngrams as $ngram) { | ||||
| $sql[] = qsprintf( | $sql[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| '(%d, %s)', | '(%d, %s)', | ||||
| $document_id, | $document_id, | ||||
| $ngram); | $ngram); | ||||
| } | } | ||||
| foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { | foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { | ||||
| queryfx( | queryfx( | ||||
| $conn, | $conn, | ||||
| 'INSERT INTO %T (documentID, ngram) VALUES %Q', | 'INSERT INTO %T (documentID, ngram) VALUES %Q', | ||||
| $engine->getNgramsTableName(), | $engine->getNgramsTableName(), | ||||
| $chunk); | $chunk); | ||||
| } | } | ||||
| } | |||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| $object->killTransaction(); | $object->killTransaction(); | ||||
| throw $ex; | throw $ex; | ||||
| } | } | ||||
| $object->saveTransaction(); | $object->saveTransaction(); | ||||
| } | } | ||||
| Show All 39 Lines | |||||