Page MenuHomec4science

PhabricatorNgramsIndexEngineExtension.php
No OneTemporary

File Metadata

Created
Tue, Nov 26, 18:17

PhabricatorNgramsIndexEngineExtension.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());
}
}
}

Event Timeline