mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 16:22:43 +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:
parent
2748f83e12
commit
ef1340bd32
10 changed files with 124 additions and 9 deletions
|
@ -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};
|
|
@ -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};
|
|
@ -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};
|
|
@ -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};
|
|
@ -4072,7 +4072,9 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php',
|
||||
'PhabricatorPasteEditEngine' => 'applications/paste/editor/PhabricatorPasteEditEngine.php',
|
||||
'PhabricatorPasteEditor' => 'applications/paste/editor/PhabricatorPasteEditor.php',
|
||||
'PhabricatorPasteFerretEngine' => 'applications/paste/engine/PhabricatorPasteFerretEngine.php',
|
||||
'PhabricatorPasteFilenameContextFreeGrammar' => 'applications/paste/lipsum/PhabricatorPasteFilenameContextFreeGrammar.php',
|
||||
'PhabricatorPasteFulltextEngine' => 'applications/paste/engine/PhabricatorPasteFulltextEngine.php',
|
||||
'PhabricatorPasteLanguageTransaction' => 'applications/paste/xaction/PhabricatorPasteLanguageTransaction.php',
|
||||
'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php',
|
||||
'PhabricatorPastePastePHIDType' => 'applications/paste/phid/PhabricatorPastePastePHIDType.php',
|
||||
|
@ -10652,6 +10654,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorApplicationTransactionInterface',
|
||||
'PhabricatorSpacesInterface',
|
||||
'PhabricatorConduitResultInterface',
|
||||
'PhabricatorFerretInterface',
|
||||
'PhabricatorFulltextInterface',
|
||||
),
|
||||
'PhabricatorPasteApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorPasteArchiveController' => 'PhabricatorPasteController',
|
||||
|
@ -10662,7 +10666,9 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPasteEditController' => 'PhabricatorPasteController',
|
||||
'PhabricatorPasteEditEngine' => 'PhabricatorEditEngine',
|
||||
'PhabricatorPasteEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'PhabricatorPasteFerretEngine' => 'PhabricatorFerretEngine',
|
||||
'PhabricatorPasteFilenameContextFreeGrammar' => 'PhutilContextFreeGrammar',
|
||||
'PhabricatorPasteFulltextEngine' => 'PhabricatorFulltextEngine',
|
||||
'PhabricatorPasteLanguageTransaction' => 'PhabricatorPasteTransactionType',
|
||||
'PhabricatorPasteListController' => 'PhabricatorPasteController',
|
||||
'PhabricatorPastePastePHIDType' => 'PhabricatorPHIDType',
|
||||
|
|
|
@ -94,4 +94,8 @@ final class PhabricatorPasteEditor
|
|||
return true;
|
||||
}
|
||||
|
||||
protected function supportsSearch() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
|
@ -110,62 +110,66 @@ final class PhabricatorPasteQuery
|
|||
if ($this->ids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'id IN (%Ld)',
|
||||
'paste.id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->phids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'phid IN (%Ls)',
|
||||
'paste.phid IN (%Ls)',
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
if ($this->authorPHIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'authorPHID IN (%Ls)',
|
||||
'paste.authorPHID IN (%Ls)',
|
||||
$this->authorPHIDs);
|
||||
}
|
||||
|
||||
if ($this->parentPHIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'parentPHID IN (%Ls)',
|
||||
'paste.parentPHID IN (%Ls)',
|
||||
$this->parentPHIDs);
|
||||
}
|
||||
|
||||
if ($this->languages !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'language IN (%Ls)',
|
||||
'paste.language IN (%Ls)',
|
||||
$this->languages);
|
||||
}
|
||||
|
||||
if ($this->dateCreatedAfter !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'dateCreated >= %d',
|
||||
'paste.dateCreated >= %d',
|
||||
$this->dateCreatedAfter);
|
||||
}
|
||||
|
||||
if ($this->dateCreatedBefore !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'dateCreated <= %d',
|
||||
'paste.dateCreated <= %d',
|
||||
$this->dateCreatedBefore);
|
||||
}
|
||||
|
||||
if ($this->statuses !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'status IN (%Ls)',
|
||||
'paste.status IN (%Ls)',
|
||||
$this->statuses);
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
protected function getPrimaryTableAlias() {
|
||||
return 'paste';
|
||||
}
|
||||
|
||||
private function getContentCacheKey(PhabricatorPaste $paste) {
|
||||
return implode(
|
||||
':',
|
||||
|
|
|
@ -11,7 +11,9 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
|
|||
PhabricatorDestructibleInterface,
|
||||
PhabricatorApplicationTransactionInterface,
|
||||
PhabricatorSpacesInterface,
|
||||
PhabricatorConduitResultInterface {
|
||||
PhabricatorConduitResultInterface,
|
||||
PhabricatorFerretInterface,
|
||||
PhabricatorFulltextInterface {
|
||||
|
||||
protected $title;
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue