1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 20:10:55 +01:00
phorge-phorge/src/applications/search/engineextension/PhabricatorNgramsIndexEngineExtension.php

35 lines
762 B
PHP
Raw Normal View History

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