1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 03:20:59 +01:00

Add basic search capabilities to Packages

Summary: Ref T8116. Add search-by-name and per-package / per-publisher search to Packages.

Test Plan: Searched publishers, packages, versions by name. Searched packages by publisher. Searched versions by package.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T8116

Differential Revision: https://secure.phabricator.com/D16320
This commit is contained in:
epriestley 2016-07-22 06:20:44 -07:00
parent f5d2f8e07a
commit 08a19f35f0
22 changed files with 212 additions and 32 deletions

View file

@ -0,0 +1,7 @@
CREATE TABLE {$NAMESPACE}_packages.packages_publishername_ngrams (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
objectID INT UNSIGNED NOT NULL,
ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT},
KEY `key_object` (objectID),
KEY `key_ngram` (ngram, objectID)
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};

View file

@ -0,0 +1,7 @@
CREATE TABLE {$NAMESPACE}_packages.packages_packagename_ngrams (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
objectID INT UNSIGNED NOT NULL,
ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT},
KEY `key_object` (objectID),
KEY `key_ngram` (ngram, objectID)
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};

View file

@ -0,0 +1,7 @@
CREATE TABLE {$NAMESPACE}_packages.packages_versionname_ngrams (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
objectID INT UNSIGNED NOT NULL,
ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT},
KEY `key_object` (objectID),
KEY `key_ngram` (ngram, objectID)
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};

View file

@ -2978,6 +2978,7 @@ phutil_register_library_map(array(
'PhabricatorPackagesDAO' => 'applications/packages/storage/PhabricatorPackagesDAO.php',
'PhabricatorPackagesEditEngine' => 'applications/packages/editor/PhabricatorPackagesEditEngine.php',
'PhabricatorPackagesEditor' => 'applications/packages/editor/PhabricatorPackagesEditor.php',
'PhabricatorPackagesNgrams' => 'applications/packages/storage/PhabricatorPackagesNgrams.php',
'PhabricatorPackagesPackage' => 'applications/packages/storage/PhabricatorPackagesPackage.php',
'PhabricatorPackagesPackageController' => 'applications/packages/controller/PhabricatorPackagesPackageController.php',
'PhabricatorPackagesPackageDatasource' => 'applications/packages/typeahead/PhabricatorPackagesPackageDatasource.php',
@ -2989,6 +2990,7 @@ phutil_register_library_map(array(
'PhabricatorPackagesPackageEditor' => 'applications/packages/editor/PhabricatorPackagesPackageEditor.php',
'PhabricatorPackagesPackageKeyTransaction' => 'applications/packages/xaction/package/PhabricatorPackagesPackageKeyTransaction.php',
'PhabricatorPackagesPackageListController' => 'applications/packages/controller/PhabricatorPackagesPackageListController.php',
'PhabricatorPackagesPackageNameNgrams' => 'applications/packages/storage/PhabricatorPackagesPackageNameNgrams.php',
'PhabricatorPackagesPackageNameTransaction' => 'applications/packages/xaction/package/PhabricatorPackagesPackageNameTransaction.php',
'PhabricatorPackagesPackagePHIDType' => 'applications/packages/phid/PhabricatorPackagesPackagePHIDType.php',
'PhabricatorPackagesPackagePublisherTransaction' => 'applications/packages/xaction/package/PhabricatorPackagesPackagePublisherTransaction.php',
@ -3009,6 +3011,7 @@ phutil_register_library_map(array(
'PhabricatorPackagesPublisherEditor' => 'applications/packages/editor/PhabricatorPackagesPublisherEditor.php',
'PhabricatorPackagesPublisherKeyTransaction' => 'applications/packages/xaction/publisher/PhabricatorPackagesPublisherKeyTransaction.php',
'PhabricatorPackagesPublisherListController' => 'applications/packages/controller/PhabricatorPackagesPublisherListController.php',
'PhabricatorPackagesPublisherNameNgrams' => 'applications/packages/storage/PhabricatorPackagesPublisherNameNgrams.php',
'PhabricatorPackagesPublisherNameTransaction' => 'applications/packages/xaction/publisher/PhabricatorPackagesPublisherNameTransaction.php',
'PhabricatorPackagesPublisherPHIDType' => 'applications/packages/phid/PhabricatorPackagesPublisherPHIDType.php',
'PhabricatorPackagesPublisherQuery' => 'applications/packages/query/PhabricatorPackagesPublisherQuery.php',
@ -3028,6 +3031,7 @@ phutil_register_library_map(array(
'PhabricatorPackagesVersionEditEngine' => 'applications/packages/editor/PhabricatorPackagesVersionEditEngine.php',
'PhabricatorPackagesVersionEditor' => 'applications/packages/editor/PhabricatorPackagesVersionEditor.php',
'PhabricatorPackagesVersionListController' => 'applications/packages/controller/PhabricatorPackagesVersionListController.php',
'PhabricatorPackagesVersionNameNgrams' => 'applications/packages/storage/PhabricatorPackagesVersionNameNgrams.php',
'PhabricatorPackagesVersionNameTransaction' => 'applications/packages/xaction/version/PhabricatorPackagesVersionNameTransaction.php',
'PhabricatorPackagesVersionPHIDType' => 'applications/packages/phid/PhabricatorPackagesVersionPHIDType.php',
'PhabricatorPackagesVersionPackageTransaction' => 'applications/packages/xaction/version/PhabricatorPackagesVersionPackageTransaction.php',
@ -7797,6 +7801,7 @@ phutil_register_library_map(array(
'PhabricatorPackagesDAO' => 'PhabricatorLiskDAO',
'PhabricatorPackagesEditEngine' => 'PhabricatorEditEngine',
'PhabricatorPackagesEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorPackagesNgrams' => 'PhabricatorSearchNgrams',
'PhabricatorPackagesPackage' => array(
'PhabricatorPackagesDAO',
'PhabricatorPolicyInterface',
@ -7805,6 +7810,7 @@ phutil_register_library_map(array(
'PhabricatorSubscribableInterface',
'PhabricatorProjectInterface',
'PhabricatorConduitResultInterface',
'PhabricatorNgramsInterface',
),
'PhabricatorPackagesPackageController' => 'PhabricatorPackagesController',
'PhabricatorPackagesPackageDatasource' => 'PhabricatorTypeaheadDatasource',
@ -7816,6 +7822,7 @@ phutil_register_library_map(array(
'PhabricatorPackagesPackageEditor' => 'PhabricatorPackagesEditor',
'PhabricatorPackagesPackageKeyTransaction' => 'PhabricatorPackagesPackageTransactionType',
'PhabricatorPackagesPackageListController' => 'PhabricatorPackagesPackageController',
'PhabricatorPackagesPackageNameNgrams' => 'PhabricatorPackagesNgrams',
'PhabricatorPackagesPackageNameTransaction' => 'PhabricatorPackagesPackageTransactionType',
'PhabricatorPackagesPackagePHIDType' => 'PhabricatorPHIDType',
'PhabricatorPackagesPackagePublisherTransaction' => 'PhabricatorPackagesPackageTransactionType',
@ -7834,6 +7841,7 @@ phutil_register_library_map(array(
'PhabricatorSubscribableInterface',
'PhabricatorProjectInterface',
'PhabricatorConduitResultInterface',
'PhabricatorNgramsInterface',
),
'PhabricatorPackagesPublisherController' => 'PhabricatorPackagesController',
'PhabricatorPackagesPublisherDatasource' => 'PhabricatorTypeaheadDatasource',
@ -7844,6 +7852,7 @@ phutil_register_library_map(array(
'PhabricatorPackagesPublisherEditor' => 'PhabricatorPackagesEditor',
'PhabricatorPackagesPublisherKeyTransaction' => 'PhabricatorPackagesPublisherTransactionType',
'PhabricatorPackagesPublisherListController' => 'PhabricatorPackagesPublisherController',
'PhabricatorPackagesPublisherNameNgrams' => 'PhabricatorPackagesNgrams',
'PhabricatorPackagesPublisherNameTransaction' => 'PhabricatorPackagesPublisherTransactionType',
'PhabricatorPackagesPublisherPHIDType' => 'PhabricatorPHIDType',
'PhabricatorPackagesPublisherQuery' => 'PhabricatorPackagesQuery',
@ -7865,6 +7874,7 @@ phutil_register_library_map(array(
'PhabricatorSubscribableInterface',
'PhabricatorProjectInterface',
'PhabricatorConduitResultInterface',
'PhabricatorNgramsInterface',
),
'PhabricatorPackagesVersionController' => 'PhabricatorPackagesController',
'PhabricatorPackagesVersionEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
@ -7872,6 +7882,7 @@ phutil_register_library_map(array(
'PhabricatorPackagesVersionEditEngine' => 'PhabricatorPackagesEditEngine',
'PhabricatorPackagesVersionEditor' => 'PhabricatorPackagesEditor',
'PhabricatorPackagesVersionListController' => 'PhabricatorPackagesVersionController',
'PhabricatorPackagesVersionNameNgrams' => 'PhabricatorPackagesNgrams',
'PhabricatorPackagesVersionNameTransaction' => 'PhabricatorPackagesVersionTransactionType',
'PhabricatorPackagesVersionPHIDType' => 'PhabricatorPHIDType',
'PhabricatorPackagesVersionPackageTransaction' => 'PhabricatorPackagesVersionTransactionType',

View file

@ -7,4 +7,14 @@ abstract class PhabricatorPackagesEditor
return 'PhabricatorPasteApplication';
}
protected function supportsSearch() {
return true;
}
protected function shouldPublishFeedStory(
PhabricatorLiskDAO $object,
array $xactions) {
return true;
}
}

View file

@ -24,12 +24,6 @@ final class PhabricatorPackagesPackageEditor
return $types;
}
protected function shouldPublishFeedStory(
PhabricatorLiskDAO $object,
array $xactions) {
return true;
}
protected function getMailTo(PhabricatorLiskDAO $object) {
return array();
}

View file

@ -21,12 +21,6 @@ final class PhabricatorPackagesPublisherEditor
return $types;
}
protected function shouldPublishFeedStory(
PhabricatorLiskDAO $object,
array $xactions) {
return true;
}
protected function getMailTo(PhabricatorLiskDAO $object) {
return array();
}

View file

@ -15,12 +15,6 @@ final class PhabricatorPackagesVersionEditor
return pht('%s created %s.', $author, $object);
}
protected function shouldPublishFeedStory(
PhabricatorLiskDAO $object,
array $xactions) {
return true;
}
protected function getMailTo(PhabricatorLiskDAO $object) {
return array();
}

View file

@ -34,6 +34,12 @@ final class PhabricatorPackagesPackageQuery
return $this;
}
public function withNameNgrams($ngrams) {
return $this->withNgramsConstraint(
new PhabricatorPackagesPackageNameNgrams(),
$ngrams);
}
public function newResultObject() {
return new PhabricatorPackagesPackage();
}
@ -62,7 +68,7 @@ final class PhabricatorPackagesPackageQuery
if ($this->publisherPHIDs !== null) {
$where[] = qsprintf(
$conn,
'p.phid IN (%Ls)',
'p.publisherPHID IN (%Ls)',
$this->publisherPHIDs);
}

View file

@ -18,11 +18,30 @@ final class PhabricatorPackagesPackageSearchEngine
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['match'] !== null) {
$query->withNameNgrams($map['match']);
}
if ($map['publisherPHIDs']) {
$query->withPublisherPHIDs($map['publisherPHIDs']);
}
return $query;
}
protected function buildCustomSearchFields() {
return array();
return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('match')
->setDescription(pht('Search for packages by name substring.')),
id(new PhabricatorSearchDatasourceField())
->setLabel(pht('Publishers'))
->setKey('publisherPHIDs')
->setAliases(array('publisherPHID', 'publisher', 'publishers'))
->setDatasource(new PhabricatorPackagesPublisherDatasource())
->setDescription(pht('Search for packages by publisher.')),
);
}
protected function getURI($path) {

View file

@ -22,6 +22,12 @@ final class PhabricatorPackagesPublisherQuery
return $this;
}
public function withNameNgrams($ngrams) {
return $this->withNgramsConstraint(
new PhabricatorPackagesPublisherNameNgrams(),
$ngrams);
}
public function newResultObject() {
return new PhabricatorPackagesPublisher();
}
@ -36,25 +42,29 @@ final class PhabricatorPackagesPublisherQuery
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'id IN (%Ld)',
'u.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'phid IN (%Ls)',
'u.phid IN (%Ls)',
$this->phids);
}
if ($this->publisherKeys !== null) {
$where[] = qsprintf(
$conn,
'publisherKey IN (%Ls)',
'u.publisherKey IN (%Ls)',
$this->publisherKeys);
}
return $where;
}
protected function getPrimaryTableAlias() {
return 'u';
}
}

View file

@ -18,11 +18,20 @@ final class PhabricatorPackagesPublisherSearchEngine
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['match'] !== null) {
$query->withNameNgrams($map['match']);
}
return $query;
}
protected function buildCustomSearchFields() {
return array();
return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('match')
->setDescription(pht('Search for publishers by name substring.')),
);
}
protected function getURI($path) {

View file

@ -34,6 +34,12 @@ final class PhabricatorPackagesVersionQuery
return $this;
}
public function withNameNgrams($ngrams) {
return $this->withNgramsConstraint(
new PhabricatorPackagesVersionNameNgrams(),
$ngrams);
}
public function newResultObject() {
return new PhabricatorPackagesVersion();
}

View file

@ -18,13 +18,31 @@ final class PhabricatorPackagesVersionSearchEngine
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['match'] !== null) {
$query->withNameNgrams($map['match']);
}
if ($map['packagePHIDs']) {
$query->withPackagePHIDs($map['packagePHIDs']);
}
return $query;
}
protected function buildCustomSearchFields() {
return array();
return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('match')
->setDescription(pht('Search for versions by name substring.')),
id(new PhabricatorSearchDatasourceField())
->setLabel(pht('Packages'))
->setKey('packagePHIDs')
->setAliases(array('packagePHID', 'package', 'packages'))
->setDatasource(new PhabricatorPackagesPackageDatasource())
->setDescription(pht('Search for versions by package.')),
);
}
protected function getURI($path) {
return '/packages/version/'.$path;
}

View file

@ -0,0 +1,10 @@
<?php
abstract class PhabricatorPackagesNgrams
extends PhabricatorSearchNgrams {
public function getApplicationName() {
return 'packages';
}
}

View file

@ -8,7 +8,8 @@ final class PhabricatorPackagesPackage
PhabricatorDestructibleInterface,
PhabricatorSubscribableInterface,
PhabricatorProjectInterface,
PhabricatorConduitResultInterface {
PhabricatorConduitResultInterface,
PhabricatorNgramsInterface {
protected $name;
protected $publisherPHID;
@ -39,7 +40,7 @@ final class PhabricatorPackagesPackage
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text64',
'name' => 'sort64',
'packageKey' => 'sort64',
),
self::CONFIG_KEY_SCHEMA => array(
@ -207,6 +208,17 @@ final class PhabricatorPackagesPackage
}
/* -( PhabricatorNgramsInterface )----------------------------------------- */
public function newNgrams() {
return array(
id(new PhabricatorPackagesPackageNameNgrams())
->setValue($this->getName()),
);
}
/* -( PhabricatorConduitResultInterface )---------------------------------- */

View file

@ -0,0 +1,14 @@
<?php
final class PhabricatorPackagesPackageNameNgrams
extends PhabricatorPackagesNgrams {
public function getNgramKey() {
return 'packagename';
}
public function getColumnName() {
return 'name';
}
}

View file

@ -8,7 +8,8 @@ final class PhabricatorPackagesPublisher
PhabricatorDestructibleInterface,
PhabricatorSubscribableInterface,
PhabricatorProjectInterface,
PhabricatorConduitResultInterface {
PhabricatorConduitResultInterface,
PhabricatorNgramsInterface {
protected $name;
protected $publisherKey;
@ -31,7 +32,7 @@ final class PhabricatorPackagesPublisher
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text64',
'name' => 'sort64',
'publisherKey' => 'sort64',
),
self::CONFIG_KEY_SCHEMA => array(
@ -183,6 +184,17 @@ final class PhabricatorPackagesPublisher
}
/* -( PhabricatorNgramsInterface )----------------------------------------- */
public function newNgrams() {
return array(
id(new PhabricatorPackagesPublisherNameNgrams())
->setValue($this->getName()),
);
}
/* -( PhabricatorConduitResultInterface )---------------------------------- */

View file

@ -0,0 +1,14 @@
<?php
final class PhabricatorPackagesPublisherNameNgrams
extends PhabricatorPackagesNgrams {
public function getNgramKey() {
return 'publishername';
}
public function getColumnName() {
return 'name';
}
}

View file

@ -9,7 +9,8 @@ final class PhabricatorPackagesVersion
PhabricatorDestructibleInterface,
PhabricatorSubscribableInterface,
PhabricatorProjectInterface,
PhabricatorConduitResultInterface {
PhabricatorConduitResultInterface,
PhabricatorNgramsInterface {
protected $name;
protected $packagePHID;
@ -174,6 +175,17 @@ final class PhabricatorPackagesVersion
}
/* -( PhabricatorNgramsInterface )----------------------------------------- */
public function newNgrams() {
return array(
id(new PhabricatorPackagesVersionNameNgrams())
->setValue($this->getName()),
);
}
/* -( PhabricatorConduitResultInterface )---------------------------------- */

View file

@ -0,0 +1,14 @@
<?php
final class PhabricatorPackagesVersionNameNgrams
extends PhabricatorPackagesNgrams {
public function getNgramKey() {
return 'versionname';
}
public function getColumnName() {
return 'name';
}
}

View file

@ -4,7 +4,7 @@ final class PhabricatorPackagesPackageDatasource
extends PhabricatorTypeaheadDatasource {
public function getBrowseTitle() {
return pht('Browse Packagess');
return pht('Browse Packages');
}
public function getPlaceholderText() {