1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Support Ferret engine for searching users

Summary:
Ref T12819. Adds support for indexing user accounts so they appear in global fulltext results.

Also, always rank users ahead of other results.

Test Plan: Indexed users. Searched for a user, got that user.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12819

Differential Revision: https://secure.phabricator.com/D18552
This commit is contained in:
epriestley 2017-09-07 09:38:19 -07:00
parent a2a2b3f7f4
commit 3ff9d4a4ca
11 changed files with 118 additions and 0 deletions

View file

@ -0,0 +1,9 @@
CREATE TABLE {$NAMESPACE}_user.user_user_fdocument (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
objectPHID VARBINARY(64) NOT NULL,
isClosed BOOL NOT NULL,
authorPHID VARBINARY(64),
ownerPHID VARBINARY(64),
epochCreated INT UNSIGNED NOT NULL,
epochModified INT UNSIGNED NOT NULL
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};

View file

@ -0,0 +1,8 @@
CREATE TABLE {$NAMESPACE}_user.user_user_ffield (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
documentID INT UNSIGNED NOT NULL,
fieldKey VARCHAR(4) NOT NULL COLLATE {$COLLATE_TEXT},
rawCorpus LONGTEXT NOT NULL COLLATE {$COLLATE_SORT},
termCorpus LONGTEXT NOT NULL COLLATE {$COLLATE_SORT},
normalCorpus LONGTEXT NOT NULL COLLATE {$COLLATE_SORT}
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};

View file

@ -0,0 +1,5 @@
CREATE TABLE {$NAMESPACE}_user.user_user_fngrams (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
documentID INT UNSIGNED NOT NULL,
ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT}
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};

View file

@ -4257,6 +4257,10 @@ phutil_register_library_map(array(
'PhabricatorUserEditorTestCase' => 'applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php',
'PhabricatorUserEmail' => 'applications/people/storage/PhabricatorUserEmail.php',
'PhabricatorUserEmailTestCase' => 'applications/people/storage/__tests__/PhabricatorUserEmailTestCase.php',
'PhabricatorUserFerretDocument' => 'applications/people/storage/PhabricatorUserFerretDocument.php',
'PhabricatorUserFerretEngine' => 'applications/people/search/PhabricatorUserFerretEngine.php',
'PhabricatorUserFerretField' => 'applications/people/storage/PhabricatorUserFerretField.php',
'PhabricatorUserFerretNgrams' => 'applications/people/storage/PhabricatorUserFerretNgrams.php',
'PhabricatorUserFulltextEngine' => 'applications/people/search/PhabricatorUserFulltextEngine.php',
'PhabricatorUserIconField' => 'applications/people/customfield/PhabricatorUserIconField.php',
'PhabricatorUserLog' => 'applications/people/storage/PhabricatorUserLog.php',
@ -9840,6 +9844,7 @@ phutil_register_library_map(array(
'PhabricatorFlaggableInterface',
'PhabricatorApplicationTransactionInterface',
'PhabricatorFulltextInterface',
'PhabricatorFerretInterface',
'PhabricatorConduitResultInterface',
),
'PhabricatorUserBadgesCacheType' => 'PhabricatorUserCacheType',
@ -9862,6 +9867,10 @@ phutil_register_library_map(array(
'PhabricatorUserEditorTestCase' => 'PhabricatorTestCase',
'PhabricatorUserEmail' => 'PhabricatorUserDAO',
'PhabricatorUserEmailTestCase' => 'PhabricatorTestCase',
'PhabricatorUserFerretDocument' => 'PhabricatorFerretDocument',
'PhabricatorUserFerretEngine' => 'PhabricatorFerretEngine',
'PhabricatorUserFerretField' => 'PhabricatorFerretField',
'PhabricatorUserFerretNgrams' => 'PhabricatorFerretNgrams',
'PhabricatorUserFulltextEngine' => 'PhabricatorFulltextEngine',
'PhabricatorUserIconField' => 'PhabricatorUserCustomField',
'PhabricatorUserLog' => array(

View file

@ -0,0 +1,29 @@
<?php
final class PhabricatorUserFerretEngine
extends PhabricatorFerretEngine {
public function newNgramsObject() {
return new PhabricatorUserFerretNgrams();
}
public function newDocumentObject() {
return new PhabricatorUserFerretDocument();
}
public function newFieldObject() {
return new PhabricatorUserFerretField();
}
public function newSearchEngine() {
return new PhabricatorPeopleSearchEngine();
}
public function getObjectTypeRelevance() {
// Always sort users above other documents, regardless of relevance
// metrics. A user profile is very likely to be the best hit for a query
// which matches a user.
return 500;
}
}

View file

@ -19,6 +19,7 @@ final class PhabricatorUser
PhabricatorFlaggableInterface,
PhabricatorApplicationTransactionInterface,
PhabricatorFulltextInterface,
PhabricatorFerretInterface,
PhabricatorConduitResultInterface {
const SESSION_TABLE = 'phabricator_session';
@ -1434,6 +1435,14 @@ final class PhabricatorUser
}
/* -( PhabricatorFerretInterface )----------------------------------------- */
public function newFerretEngine() {
return new PhabricatorUserFerretEngine();
}
/* -( PhabricatorConduitResultInterface )---------------------------------- */

View file

@ -0,0 +1,14 @@
<?php
final class PhabricatorUserFerretDocument
extends PhabricatorFerretDocument {
public function getApplicationName() {
return 'user';
}
public function getIndexKey() {
return 'user';
}
}

View file

@ -0,0 +1,14 @@
<?php
final class PhabricatorUserFerretField
extends PhabricatorFerretField {
public function getApplicationName() {
return 'user';
}
public function getIndexKey() {
return 'user';
}
}

View file

@ -0,0 +1,14 @@
<?php
final class PhabricatorUserFerretNgrams
extends PhabricatorFerretNgrams {
public function getApplicationName() {
return 'user';
}
public function getIndexKey() {
return 'user';
}
}

View file

@ -11,6 +11,10 @@ abstract class PhabricatorFerretEngine extends Phobject {
return 'all';
}
public function getObjectTypeRelevance() {
return 1000;
}
public function getFieldForFunction($function) {
$function = phutil_utf8_strtolower($function);

View file

@ -34,7 +34,10 @@ final class PhabricatorFerretMetadata extends Phobject {
}
public function getRelevanceSortVector() {
$engine = $this->getEngine();
return id(new PhutilSortVector())
->addInt($engine->getObjectTypeRelevance())
->addInt(-$this->getRelevance());
}