Differential D18710 Diff 44920 src/applications/search/management/PhabricatorSearchManagementNgramsWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/management/PhabricatorSearchManagementNgramsWorkflow.php
| Show All 10 Lines | $this | ||||
| 'Recompute common ngrams. This is an advanced workflow that '. | 'Recompute common ngrams. This is an advanced workflow that '. | ||||
| 'can harm search quality if used improperly.')) | 'can harm search quality if used improperly.')) | ||||
| ->setArguments( | ->setArguments( | ||||
| array( | array( | ||||
| array( | array( | ||||
| 'name' => 'reset', | 'name' => 'reset', | ||||
| 'help' => pht('Reset all common ngram records.'), | 'help' => pht('Reset all common ngram records.'), | ||||
| ), | ), | ||||
| array( | |||||
| 'name' => 'threshold', | |||||
| 'param' => 'threshold', | |||||
| 'help' => pht( | |||||
| 'Prune ngrams present in more than this fraction of '. | |||||
| 'documents.'), | |||||
amckinley: I see we validate this below, but maybe add a note in the help text indicating that we expect a… | |||||
| ), | |||||
| )); | )); | ||||
| } | } | ||||
| public function execute(PhutilArgumentParser $args) { | public function execute(PhutilArgumentParser $args) { | ||||
| $min_documents = 4096; | |||||
| $is_reset = $args->getArg('reset'); | $is_reset = $args->getArg('reset'); | ||||
| $threshold = $args->getArg('threshold'); | |||||
| if ($is_reset && $threshold !== null) { | |||||
| throw new PhutilArgumentUsageException( | |||||
| pht('Specify either --reset or --threshold, not both.')); | |||||
| } | |||||
| if (!$is_reset && $threshold === null) { | |||||
| throw new PhutilArgumentUsageException( | |||||
| pht('Specify either --reset or --threshold.')); | |||||
| } | |||||
| if (!$is_reset) { | |||||
| if (!is_numeric($threshold)) { | |||||
| throw new PhutilArgumentUsageException( | |||||
| pht('Specify a numeric threshold between 0 and 1.')); | |||||
| } | |||||
| $threshold = (double)$threshold; | |||||
| if ($threshold <= 0 || $threshold >= 1) { | |||||
| throw new PhutilArgumentUsageException( | |||||
| pht('Threshold must be greater than 0.0 and less than 1.0.')); | |||||
| } | |||||
| } | |||||
| $all_objects = id(new PhutilClassMapQuery()) | $all_objects = id(new PhutilClassMapQuery()) | ||||
| ->setAncestorClass('PhabricatorFerretInterface') | ->setAncestorClass('PhabricatorFerretInterface') | ||||
| ->execute(); | ->execute(); | ||||
| $min_documents = 4096; | |||||
| $threshold = 0.15; | |||||
| foreach ($all_objects as $object) { | foreach ($all_objects as $object) { | ||||
| $engine = $object->newFerretEngine(); | $engine = $object->newFerretEngine(); | ||||
| $conn = $object->establishConnection('w'); | $conn = $object->establishConnection('w'); | ||||
| $display_name = get_class($object); | $display_name = get_class($object); | ||||
| if ($is_reset) { | if ($is_reset) { | ||||
| echo tsprintf( | echo tsprintf( | ||||
| "%s\n", | "%s\n", | ||||
| ▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines | |||||
I see we validate this below, but maybe add a note in the help text indicating that we expect a float between 0.0 and 1.0?