mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 20:10:55 +01:00
35 lines
762 B
PHP
35 lines
762 B
PHP
|
<?php
|
||
|
|
||
|
final class PhabricatorNgramsIndexEngineExtension
|
||
|
extends PhabricatorIndexEngineExtension {
|
||
|
|
||
|
const EXTENSIONKEY = 'ngrams';
|
||
|
|
||
|
public function getExtensionName() {
|
||
|
return pht('Ngrams Engine');
|
||
|
}
|
||
|
|
||
|
public function getIndexVersion($object) {
|
||
|
$ngrams = $object->newNgrams();
|
||
|
$map = mpull($ngrams, 'getValue', 'getNgramKey');
|
||
|
ksort($map);
|
||
|
$serialized = serialize($map);
|
||
|
|
||
|
return PhabricatorHash::digestForIndex($serialized);
|
||
|
}
|
||
|
|
||
|
public function shouldIndexObject($object) {
|
||
|
return ($object instanceof PhabricatorNgramsInterface);
|
||
|
}
|
||
|
|
||
|
public function indexObject(
|
||
|
PhabricatorIndexEngine $engine,
|
||
|
$object) {
|
||
|
|
||
|
foreach ($object->newNgrams() as $ngram) {
|
||
|
$ngram->writeNgram($object->getID());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|