Skip to content

Commit ef1340b

Browse files
phacility-botepriestley
authored and
epriestley
committedApr 16, 2020
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
1 parent 2748f83 commit ef1340b

10 files changed

+124
-9
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CREATE TABLE {$NAMESPACE}_paste.paste_paste_fdocument (
2+
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
3+
objectPHID VARBINARY(64) NOT NULL,
4+
isClosed BOOL NOT NULL,
5+
authorPHID VARBINARY(64),
6+
ownerPHID VARBINARY(64),
7+
epochCreated INT UNSIGNED NOT NULL,
8+
epochModified INT UNSIGNED NOT NULL
9+
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE TABLE {$NAMESPACE}_paste.paste_paste_ffield (
2+
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
3+
documentID INT UNSIGNED NOT NULL,
4+
fieldKey VARCHAR(4) NOT NULL COLLATE {$COLLATE_TEXT},
5+
rawCorpus LONGTEXT NOT NULL COLLATE {$COLLATE_SORT},
6+
termCorpus LONGTEXT NOT NULL COLLATE {$COLLATE_SORT},
7+
normalCorpus LONGTEXT NOT NULL COLLATE {$COLLATE_SORT}
8+
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE {$NAMESPACE}_paste.paste_paste_fngrams (
2+
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
3+
documentID INT UNSIGNED NOT NULL,
4+
ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT}
5+
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE {$NAMESPACE}_paste.paste_paste_fngrams_common (
2+
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
3+
ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT},
4+
needsCollection BOOL NOT NULL,
5+
UNIQUE KEY `key_ngram` (ngram),
6+
KEY `key_collect` (needsCollection)
7+
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};

‎src/__phutil_library_map__.php

+6
Original file line numberDiff line numberDiff line change
@@ -4072,7 +4072,9 @@
40724072
'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php',
40734073
'PhabricatorPasteEditEngine' => 'applications/paste/editor/PhabricatorPasteEditEngine.php',
40744074
'PhabricatorPasteEditor' => 'applications/paste/editor/PhabricatorPasteEditor.php',
4075+
'PhabricatorPasteFerretEngine' => 'applications/paste/engine/PhabricatorPasteFerretEngine.php',
40754076
'PhabricatorPasteFilenameContextFreeGrammar' => 'applications/paste/lipsum/PhabricatorPasteFilenameContextFreeGrammar.php',
4077+
'PhabricatorPasteFulltextEngine' => 'applications/paste/engine/PhabricatorPasteFulltextEngine.php',
40764078
'PhabricatorPasteLanguageTransaction' => 'applications/paste/xaction/PhabricatorPasteLanguageTransaction.php',
40774079
'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php',
40784080
'PhabricatorPastePastePHIDType' => 'applications/paste/phid/PhabricatorPastePastePHIDType.php',
@@ -10652,6 +10654,8 @@
1065210654
'PhabricatorApplicationTransactionInterface',
1065310655
'PhabricatorSpacesInterface',
1065410656
'PhabricatorConduitResultInterface',
10657+
'PhabricatorFerretInterface',
10658+
'PhabricatorFulltextInterface',
1065510659
),
1065610660
'PhabricatorPasteApplication' => 'PhabricatorApplication',
1065710661
'PhabricatorPasteArchiveController' => 'PhabricatorPasteController',
@@ -10662,7 +10666,9 @@
1066210666
'PhabricatorPasteEditController' => 'PhabricatorPasteController',
1066310667
'PhabricatorPasteEditEngine' => 'PhabricatorEditEngine',
1066410668
'PhabricatorPasteEditor' => 'PhabricatorApplicationTransactionEditor',
10669+
'PhabricatorPasteFerretEngine' => 'PhabricatorFerretEngine',
1066510670
'PhabricatorPasteFilenameContextFreeGrammar' => 'PhutilContextFreeGrammar',
10671+
'PhabricatorPasteFulltextEngine' => 'PhabricatorFulltextEngine',
1066610672
'PhabricatorPasteLanguageTransaction' => 'PhabricatorPasteTransactionType',
1066710673
'PhabricatorPasteListController' => 'PhabricatorPasteController',
1066810674
'PhabricatorPastePastePHIDType' => 'PhabricatorPHIDType',

‎src/applications/paste/editor/PhabricatorPasteEditor.php

+4
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,8 @@ protected function shouldPublishFeedStory(
9494
return true;
9595
}
9696

97+
protected function supportsSearch() {
98+
return true;
99+
}
100+
97101
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
final class PhabricatorPasteFerretEngine
4+
extends PhabricatorFerretEngine {
5+
6+
public function getApplicationName() {
7+
return 'paste';
8+
}
9+
10+
public function getScopeName() {
11+
return 'paste';
12+
}
13+
14+
public function newSearchEngine() {
15+
return new PhabricatorPasteSearchEngine();
16+
}
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
final class PhabricatorPasteFulltextEngine
4+
extends PhabricatorFulltextEngine {
5+
6+
protected function buildAbstractDocument(
7+
PhabricatorSearchAbstractDocument $document,
8+
$object) {
9+
10+
$paste = id(new PhabricatorPasteQuery())
11+
->setViewer($this->getViewer())
12+
->withPHIDs(array($object->getPHID()))
13+
->needContent(true)
14+
->executeOne();
15+
16+
$document->setDocumentTitle($paste->getTitle());
17+
18+
$document->addRelationship(
19+
$paste->isArchived()
20+
? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED
21+
: PhabricatorSearchRelationship::RELATIONSHIP_OPEN,
22+
$paste->getPHID(),
23+
PhabricatorPastePastePHIDType::TYPECONST,
24+
PhabricatorTime::getNow());
25+
26+
$document->addField(
27+
PhabricatorSearchDocumentFieldType::FIELD_BODY,
28+
$paste->getContent());
29+
30+
$document->addRelationship(
31+
PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR,
32+
$paste->getAuthorPHID(),
33+
PhabricatorPeopleUserPHIDType::TYPECONST,
34+
$paste->getDateCreated());
35+
}
36+
37+
}

‎src/applications/paste/query/PhabricatorPasteQuery.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -110,62 +110,66 @@ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
110110
if ($this->ids !== null) {
111111
$where[] = qsprintf(
112112
$conn,
113-
'id IN (%Ld)',
113+
'paste.id IN (%Ld)',
114114
$this->ids);
115115
}
116116

117117
if ($this->phids !== null) {
118118
$where[] = qsprintf(
119119
$conn,
120-
'phid IN (%Ls)',
120+
'paste.phid IN (%Ls)',
121121
$this->phids);
122122
}
123123

124124
if ($this->authorPHIDs !== null) {
125125
$where[] = qsprintf(
126126
$conn,
127-
'authorPHID IN (%Ls)',
127+
'paste.authorPHID IN (%Ls)',
128128
$this->authorPHIDs);
129129
}
130130

131131
if ($this->parentPHIDs !== null) {
132132
$where[] = qsprintf(
133133
$conn,
134-
'parentPHID IN (%Ls)',
134+
'paste.parentPHID IN (%Ls)',
135135
$this->parentPHIDs);
136136
}
137137

138138
if ($this->languages !== null) {
139139
$where[] = qsprintf(
140140
$conn,
141-
'language IN (%Ls)',
141+
'paste.language IN (%Ls)',
142142
$this->languages);
143143
}
144144

145145
if ($this->dateCreatedAfter !== null) {
146146
$where[] = qsprintf(
147147
$conn,
148-
'dateCreated >= %d',
148+
'paste.dateCreated >= %d',
149149
$this->dateCreatedAfter);
150150
}
151151

152152
if ($this->dateCreatedBefore !== null) {
153153
$where[] = qsprintf(
154154
$conn,
155-
'dateCreated <= %d',
155+
'paste.dateCreated <= %d',
156156
$this->dateCreatedBefore);
157157
}
158158

159159
if ($this->statuses !== null) {
160160
$where[] = qsprintf(
161161
$conn,
162-
'status IN (%Ls)',
162+
'paste.status IN (%Ls)',
163163
$this->statuses);
164164
}
165165

166166
return $where;
167167
}
168168

169+
protected function getPrimaryTableAlias() {
170+
return 'paste';
171+
}
172+
169173
private function getContentCacheKey(PhabricatorPaste $paste) {
170174
return implode(
171175
':',

‎src/applications/paste/storage/PhabricatorPaste.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
1111
PhabricatorDestructibleInterface,
1212
PhabricatorApplicationTransactionInterface,
1313
PhabricatorSpacesInterface,
14-
PhabricatorConduitResultInterface {
14+
PhabricatorConduitResultInterface,
15+
PhabricatorFerretInterface,
16+
PhabricatorFulltextInterface {
1517

1618
protected $title;
1719
protected $authorPHID;
@@ -277,4 +279,19 @@ public function getConduitSearchAttachments() {
277279
);
278280
}
279281

282+
283+
/* -( PhabricatorFerretInterface )----------------------------------------- */
284+
285+
286+
public function newFerretEngine() {
287+
return new PhabricatorPasteFerretEngine();
288+
}
289+
290+
291+
/* -( PhabricatorFulltextInterface )--------------------------------------- */
292+
293+
public function newFulltextEngine() {
294+
return new PhabricatorPasteFulltextEngine();
295+
}
296+
280297
}

0 commit comments

Comments
 (0)
Failed to load comments.