Differential D18672 Diff 44838 src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
| Show First 20 Lines • Show All 1,694 Lines • ▼ Show 20 Lines | foreach ($this->ferretTokens as $fulltext_token) { | ||||
| foreach ($ngrams as $ngram) { | foreach ($ngrams as $ngram) { | ||||
| $flat[] = array( | $flat[] = array( | ||||
| 'table' => $ngram_table, | 'table' => $ngram_table, | ||||
| 'ngram' => $ngram, | 'ngram' => $ngram, | ||||
| ); | ); | ||||
| } | } | ||||
| } | } | ||||
| // Remove common ngrams, like "the", which occur too frequently in | |||||
| // documents to be useful in constraining the query. The best ngrams | |||||
| // are obscure sequences which occur in very few documents. | |||||
| if ($flat) { | |||||
| $common_ngrams = queryfx_all( | |||||
| $conn, | |||||
| 'SELECT ngram FROM %T WHERE ngram IN (%Ls)', | |||||
| $engine->getCommonNgramsTableName(), | |||||
| ipull($flat, 'ngram')); | |||||
| $common_ngrams = ipull($common_ngrams, 'ngram', 'ngram'); | |||||
| foreach ($flat as $key => $spec) { | |||||
| $ngram = $spec['ngram']; | |||||
| if (isset($common_ngrams[$ngram])) { | |||||
| unset($flat[$key]); | |||||
| continue; | |||||
| } | |||||
| // NOTE: MySQL discards trailing whitespace in CHAR(X) columns. | |||||
| $trim_ngram = rtrim($ngram, ' '); | |||||
| if (isset($common_ngrams[$trim_ngram])) { | |||||
| unset($flat[$key]); | |||||
| continue; | |||||
| } | |||||
| } | |||||
| } | |||||
| // MySQL only allows us to join a maximum of 61 tables per query. Each | // MySQL only allows us to join a maximum of 61 tables per query. Each | ||||
| // ngram is going to cost us a join toward that limit, so if the user | // ngram is going to cost us a join toward that limit, so if the user | ||||
| // specified a very long query string, just pick 16 of the ngrams | // specified a very long query string, just pick 16 of the ngrams | ||||
| // at random. | // at random. | ||||
| if (count($flat) > 16) { | if (count($flat) > 16) { | ||||
| shuffle($flat); | shuffle($flat); | ||||
| $flat = array_slice($flat, 0, 16); | $flat = array_slice($flat, 0, 16); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,063 Lines • Show Last 20 Lines | |||||