1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 00:32:42 +01:00

Add Ferret support to Paste

Summary:
Ref PHI1292. Enable fulltext searchs in paste. Maybe this should only index a snippet instead of the entire content?

Also updates table names in `PhabricatorPasteQuery`.

Test Plan: Created some pastes, indexed them, searched for them.

Reviewers: amckinley

Subscribers: codeblock, Korvin, PHID-OPKG-gm6ozazyms6q6i22gyam

Differential Revision: https://secure.phabricator.com/D20650
This commit is contained in:
Austin McKinley 2020-04-16 13:57:12 -07:00 committed by epriestley
parent 2748f83e12
commit ef1340bd32
10 changed files with 124 additions and 9 deletions

View file

@ -0,0 +1,9 @@
CREATE TABLE {$NAMESPACE}_paste.paste_paste_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}_paste.paste_paste_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}_paste.paste_paste_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

@ -0,0 +1,7 @@
CREATE TABLE {$NAMESPACE}_paste.paste_paste_fngrams_common (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT},
needsCollection BOOL NOT NULL,
UNIQUE KEY `key_ngram` (ngram),
KEY `key_collect` (needsCollection)
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};

View file

@ -4072,7 +4072,9 @@ phutil_register_library_map(array(
'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php', 'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php',
'PhabricatorPasteEditEngine' => 'applications/paste/editor/PhabricatorPasteEditEngine.php', 'PhabricatorPasteEditEngine' => 'applications/paste/editor/PhabricatorPasteEditEngine.php',
'PhabricatorPasteEditor' => 'applications/paste/editor/PhabricatorPasteEditor.php', 'PhabricatorPasteEditor' => 'applications/paste/editor/PhabricatorPasteEditor.php',
'PhabricatorPasteFerretEngine' => 'applications/paste/engine/PhabricatorPasteFerretEngine.php',
'PhabricatorPasteFilenameContextFreeGrammar' => 'applications/paste/lipsum/PhabricatorPasteFilenameContextFreeGrammar.php', 'PhabricatorPasteFilenameContextFreeGrammar' => 'applications/paste/lipsum/PhabricatorPasteFilenameContextFreeGrammar.php',
'PhabricatorPasteFulltextEngine' => 'applications/paste/engine/PhabricatorPasteFulltextEngine.php',
'PhabricatorPasteLanguageTransaction' => 'applications/paste/xaction/PhabricatorPasteLanguageTransaction.php', 'PhabricatorPasteLanguageTransaction' => 'applications/paste/xaction/PhabricatorPasteLanguageTransaction.php',
'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php', 'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php',
'PhabricatorPastePastePHIDType' => 'applications/paste/phid/PhabricatorPastePastePHIDType.php', 'PhabricatorPastePastePHIDType' => 'applications/paste/phid/PhabricatorPastePastePHIDType.php',
@ -10652,6 +10654,8 @@ phutil_register_library_map(array(
'PhabricatorApplicationTransactionInterface', 'PhabricatorApplicationTransactionInterface',
'PhabricatorSpacesInterface', 'PhabricatorSpacesInterface',
'PhabricatorConduitResultInterface', 'PhabricatorConduitResultInterface',
'PhabricatorFerretInterface',
'PhabricatorFulltextInterface',
), ),
'PhabricatorPasteApplication' => 'PhabricatorApplication', 'PhabricatorPasteApplication' => 'PhabricatorApplication',
'PhabricatorPasteArchiveController' => 'PhabricatorPasteController', 'PhabricatorPasteArchiveController' => 'PhabricatorPasteController',
@ -10662,7 +10666,9 @@ phutil_register_library_map(array(
'PhabricatorPasteEditController' => 'PhabricatorPasteController', 'PhabricatorPasteEditController' => 'PhabricatorPasteController',
'PhabricatorPasteEditEngine' => 'PhabricatorEditEngine', 'PhabricatorPasteEditEngine' => 'PhabricatorEditEngine',
'PhabricatorPasteEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorPasteEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorPasteFerretEngine' => 'PhabricatorFerretEngine',
'PhabricatorPasteFilenameContextFreeGrammar' => 'PhutilContextFreeGrammar', 'PhabricatorPasteFilenameContextFreeGrammar' => 'PhutilContextFreeGrammar',
'PhabricatorPasteFulltextEngine' => 'PhabricatorFulltextEngine',
'PhabricatorPasteLanguageTransaction' => 'PhabricatorPasteTransactionType', 'PhabricatorPasteLanguageTransaction' => 'PhabricatorPasteTransactionType',
'PhabricatorPasteListController' => 'PhabricatorPasteController', 'PhabricatorPasteListController' => 'PhabricatorPasteController',
'PhabricatorPastePastePHIDType' => 'PhabricatorPHIDType', 'PhabricatorPastePastePHIDType' => 'PhabricatorPHIDType',

View file

@ -94,4 +94,8 @@ final class PhabricatorPasteEditor
return true; return true;
} }
protected function supportsSearch() {
return true;
}
} }

View file

@ -0,0 +1,18 @@
<?php
final class PhabricatorPasteFerretEngine
extends PhabricatorFerretEngine {
public function getApplicationName() {
return 'paste';
}
public function getScopeName() {
return 'paste';
}
public function newSearchEngine() {
return new PhabricatorPasteSearchEngine();
}
}

View file

@ -0,0 +1,37 @@
<?php
final class PhabricatorPasteFulltextEngine
extends PhabricatorFulltextEngine {
protected function buildAbstractDocument(
PhabricatorSearchAbstractDocument $document,
$object) {
$paste = id(new PhabricatorPasteQuery())
->setViewer($this->getViewer())
->withPHIDs(array($object->getPHID()))
->needContent(true)
->executeOne();
$document->setDocumentTitle($paste->getTitle());
$document->addRelationship(
$paste->isArchived()
? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED
: PhabricatorSearchRelationship::RELATIONSHIP_OPEN,
$paste->getPHID(),
PhabricatorPastePastePHIDType::TYPECONST,
PhabricatorTime::getNow());
$document->addField(
PhabricatorSearchDocumentFieldType::FIELD_BODY,
$paste->getContent());
$document->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR,
$paste->getAuthorPHID(),
PhabricatorPeopleUserPHIDType::TYPECONST,
$paste->getDateCreated());
}
}

View file

@ -110,62 +110,66 @@ final class PhabricatorPasteQuery
if ($this->ids !== null) { if ($this->ids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'id IN (%Ld)', 'paste.id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids !== null) { if ($this->phids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'phid IN (%Ls)', 'paste.phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->authorPHIDs !== null) { if ($this->authorPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'authorPHID IN (%Ls)', 'paste.authorPHID IN (%Ls)',
$this->authorPHIDs); $this->authorPHIDs);
} }
if ($this->parentPHIDs !== null) { if ($this->parentPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'parentPHID IN (%Ls)', 'paste.parentPHID IN (%Ls)',
$this->parentPHIDs); $this->parentPHIDs);
} }
if ($this->languages !== null) { if ($this->languages !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'language IN (%Ls)', 'paste.language IN (%Ls)',
$this->languages); $this->languages);
} }
if ($this->dateCreatedAfter !== null) { if ($this->dateCreatedAfter !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'dateCreated >= %d', 'paste.dateCreated >= %d',
$this->dateCreatedAfter); $this->dateCreatedAfter);
} }
if ($this->dateCreatedBefore !== null) { if ($this->dateCreatedBefore !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'dateCreated <= %d', 'paste.dateCreated <= %d',
$this->dateCreatedBefore); $this->dateCreatedBefore);
} }
if ($this->statuses !== null) { if ($this->statuses !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'status IN (%Ls)', 'paste.status IN (%Ls)',
$this->statuses); $this->statuses);
} }
return $where; return $where;
} }
protected function getPrimaryTableAlias() {
return 'paste';
}
private function getContentCacheKey(PhabricatorPaste $paste) { private function getContentCacheKey(PhabricatorPaste $paste) {
return implode( return implode(
':', ':',

View file

@ -11,7 +11,9 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
PhabricatorDestructibleInterface, PhabricatorDestructibleInterface,
PhabricatorApplicationTransactionInterface, PhabricatorApplicationTransactionInterface,
PhabricatorSpacesInterface, PhabricatorSpacesInterface,
PhabricatorConduitResultInterface { PhabricatorConduitResultInterface,
PhabricatorFerretInterface,
PhabricatorFulltextInterface {
protected $title; protected $title;
protected $authorPHID; protected $authorPHID;
@ -277,4 +279,19 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
); );
} }
/* -( PhabricatorFerretInterface )----------------------------------------- */
public function newFerretEngine() {
return new PhabricatorPasteFerretEngine();
}
/* -( PhabricatorFulltextInterface )--------------------------------------- */
public function newFulltextEngine() {
return new PhabricatorPasteFulltextEngine();
}
} }