mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-15 11:22:40 +01:00
1b6ddae6b2
Summary: Ref T10205. Ref T10246. This is general modernization, but also supports fixing the interface datasource in T10205. - Update Query. - Update SearchEngine. - Use an ngrams index for searching names efficiently. Test Plan: - Ran migrations. - Searched Almanac devices by name. - Created a new device, searched for it by name. {F1121303} Reviewers: chad Reviewed By: chad Maniphest Tasks: T10205, T10246 Differential Revision: https://secure.phabricator.com/D15319
133 lines
2.8 KiB
PHP
133 lines
2.8 KiB
PHP
<?php
|
|
|
|
final class AlmanacDeviceQuery
|
|
extends AlmanacQuery {
|
|
|
|
private $ids;
|
|
private $phids;
|
|
private $names;
|
|
private $namePrefix;
|
|
private $nameSuffix;
|
|
|
|
public function withIDs(array $ids) {
|
|
$this->ids = $ids;
|
|
return $this;
|
|
}
|
|
|
|
public function withPHIDs(array $phids) {
|
|
$this->phids = $phids;
|
|
return $this;
|
|
}
|
|
|
|
public function withNames(array $names) {
|
|
$this->names = $names;
|
|
return $this;
|
|
}
|
|
|
|
public function withNamePrefix($prefix) {
|
|
$this->namePrefix = $prefix;
|
|
return $this;
|
|
}
|
|
|
|
public function withNameSuffix($suffix) {
|
|
$this->nameSuffix = $suffix;
|
|
return $this;
|
|
}
|
|
|
|
public function withNameNgrams($ngrams) {
|
|
return $this->withNgramsConstraint(
|
|
new AlmanacDeviceNameNgrams(),
|
|
$ngrams);
|
|
}
|
|
|
|
public function newResultObject() {
|
|
return new AlmanacDevice();
|
|
}
|
|
|
|
protected function loadPage() {
|
|
return $this->loadStandardPage($this->newResultObject());
|
|
}
|
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
$where = parent::buildWhereClauseParts($conn);
|
|
|
|
if ($this->ids !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'device.id IN (%Ld)',
|
|
$this->ids);
|
|
}
|
|
|
|
if ($this->phids !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'device.phid IN (%Ls)',
|
|
$this->phids);
|
|
}
|
|
|
|
if ($this->names !== null) {
|
|
$hashes = array();
|
|
foreach ($this->names as $name) {
|
|
$hashes[] = PhabricatorHash::digestForIndex($name);
|
|
}
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'device.nameIndex IN (%Ls)',
|
|
$hashes);
|
|
}
|
|
|
|
if ($this->namePrefix !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'device.name LIKE %>',
|
|
$this->namePrefix);
|
|
}
|
|
|
|
if ($this->nameSuffix !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'device.name LIKE %<',
|
|
$this->nameSuffix);
|
|
}
|
|
|
|
return $where;
|
|
}
|
|
|
|
protected function getPrimaryTableAlias() {
|
|
return 'device';
|
|
}
|
|
|
|
public function getOrderableColumns() {
|
|
return parent::getOrderableColumns() + array(
|
|
'name' => array(
|
|
'table' => $this->getPrimaryTableAlias(),
|
|
'column' => 'name',
|
|
'type' => 'string',
|
|
'unique' => true,
|
|
'reverse' => true,
|
|
),
|
|
);
|
|
}
|
|
|
|
protected function getPagingValueMap($cursor, array $keys) {
|
|
$device = $this->loadCursorObject($cursor);
|
|
return array(
|
|
'id' => $device->getID(),
|
|
'name' => $device->getName(),
|
|
);
|
|
}
|
|
|
|
public function getBuiltinOrders() {
|
|
return array(
|
|
'name' => array(
|
|
'vector' => array('name'),
|
|
'name' => pht('Device Name'),
|
|
),
|
|
) + parent::getBuiltinOrders();
|
|
}
|
|
|
|
public function getQueryApplicationClass() {
|
|
return 'PhabricatorAlmanacApplication';
|
|
}
|
|
|
|
}
|