Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14015593
D17702.id42610.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D17702.id42610.diff
View Options
diff --git a/resources/sql/autopatches/20170417.files.ngrams.sql b/resources/sql/autopatches/20170417.files.ngrams.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20170417.files.ngrams.sql
@@ -0,0 +1,7 @@
+CREATE TABLE {$NAMESPACE}_file.file_filename_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};
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2781,6 +2781,7 @@
'PhabricatorFileLightboxController' => 'applications/files/controller/PhabricatorFileLightboxController.php',
'PhabricatorFileLinkView' => 'view/layout/PhabricatorFileLinkView.php',
'PhabricatorFileListController' => 'applications/files/controller/PhabricatorFileListController.php',
+ 'PhabricatorFileNameNgrams' => 'applications/files/storage/PhabricatorFileNameNgrams.php',
'PhabricatorFileNameTransaction' => 'applications/files/xaction/PhabricatorFileNameTransaction.php',
'PhabricatorFileQuery' => 'applications/files/query/PhabricatorFileQuery.php',
'PhabricatorFileROT13StorageFormat' => 'applications/files/format/PhabricatorFileROT13StorageFormat.php',
@@ -7908,6 +7909,8 @@
'PhabricatorPolicyInterface',
'PhabricatorDestructibleInterface',
'PhabricatorConduitResultInterface',
+ 'PhabricatorIndexableInterface',
+ 'PhabricatorNgramsInterface',
),
'PhabricatorFileAES256StorageFormat' => 'PhabricatorFileStorageFormat',
'PhabricatorFileBundleLoader' => 'Phobject',
@@ -7954,6 +7957,7 @@
'PhabricatorFileLightboxController' => 'PhabricatorFileController',
'PhabricatorFileLinkView' => 'AphrontTagView',
'PhabricatorFileListController' => 'PhabricatorFileController',
+ 'PhabricatorFileNameNgrams' => 'PhabricatorSearchNgrams',
'PhabricatorFileNameTransaction' => 'PhabricatorFileTransactionType',
'PhabricatorFileQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorFileROT13StorageFormat' => 'PhabricatorFileStorageFormat',
diff --git a/src/applications/files/controller/PhabricatorFileDeleteController.php b/src/applications/files/controller/PhabricatorFileDeleteController.php
--- a/src/applications/files/controller/PhabricatorFileDeleteController.php
+++ b/src/applications/files/controller/PhabricatorFileDeleteController.php
@@ -25,7 +25,8 @@
}
if ($request->isFormPost()) {
- $file->delete();
+ $engine = new PhabricatorDestructionEngine();
+ $engine->destroyObject($file);
return id(new AphrontRedirectResponse())->setURI('/file/');
}
diff --git a/src/applications/files/editor/PhabricatorFileEditor.php b/src/applications/files/editor/PhabricatorFileEditor.php
--- a/src/applications/files/editor/PhabricatorFileEditor.php
+++ b/src/applications/files/editor/PhabricatorFileEditor.php
@@ -71,7 +71,7 @@
}
protected function supportsSearch() {
- return false;
+ return true;
}
}
diff --git a/src/applications/files/garbagecollector/PhabricatorFileTemporaryGarbageCollector.php b/src/applications/files/garbagecollector/PhabricatorFileTemporaryGarbageCollector.php
--- a/src/applications/files/garbagecollector/PhabricatorFileTemporaryGarbageCollector.php
+++ b/src/applications/files/garbagecollector/PhabricatorFileTemporaryGarbageCollector.php
@@ -18,8 +18,10 @@
'ttl < %d LIMIT 100',
PhabricatorTime::getNow());
+ $engine = new PhabricatorDestructionEngine();
+
foreach ($files as $file) {
- $file->delete();
+ $engine->destroyObject($file);
}
return (count($files) == 100);
diff --git a/src/applications/files/query/PhabricatorFileQuery.php b/src/applications/files/query/PhabricatorFileQuery.php
--- a/src/applications/files/query/PhabricatorFileQuery.php
+++ b/src/applications/files/query/PhabricatorFileQuery.php
@@ -119,6 +119,12 @@
return $this;
}
+ public function withNameNgrams($ngrams) {
+ return $this->withNgramsConstraint(
+ id(new PhabricatorFileNameNgrams()),
+ $ngrams);
+ }
+
public function showOnlyExplicitUploads($explicit_uploads) {
$this->explicitUploads = $explicit_uploads;
return $this;
diff --git a/src/applications/files/query/PhabricatorFileSearchEngine.php b/src/applications/files/query/PhabricatorFileSearchEngine.php
--- a/src/applications/files/query/PhabricatorFileSearchEngine.php
+++ b/src/applications/files/query/PhabricatorFileSearchEngine.php
@@ -38,6 +38,10 @@
id(new PhabricatorSearchDateField())
->setKey('createdEnd')
->setLabel(pht('Created Before')),
+ id(new PhabricatorSearchTextField())
+ ->setLabel(pht('Name Contains'))
+ ->setKey('name')
+ ->setDescription(pht('Search for files by name substring.')),
);
}
@@ -68,6 +72,10 @@
$query->withDateCreatedBefore($map['createdEnd']);
}
+ if ($map['name'] !== null) {
+ $query->withNameNgrams($map['name']);
+ }
+
return $query;
}
diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php
--- a/src/applications/files/storage/PhabricatorFile.php
+++ b/src/applications/files/storage/PhabricatorFile.php
@@ -28,7 +28,9 @@
PhabricatorFlaggableInterface,
PhabricatorPolicyInterface,
PhabricatorDestructibleInterface,
- PhabricatorConduitResultInterface {
+ PhabricatorConduitResultInterface,
+ PhabricatorIndexableInterface,
+ PhabricatorNgramsInterface {
const METADATA_IMAGE_WIDTH = 'width';
const METADATA_IMAGE_HEIGHT = 'height';
@@ -87,7 +89,7 @@
'metadata' => self::SERIALIZATION_JSON,
),
self::CONFIG_COLUMN_SCHEMA => array(
- 'name' => 'text255?',
+ 'name' => 'sort255?',
'mimeType' => 'text255?',
'byteSize' => 'uint64',
'storageEngine' => 'text32',
@@ -1585,4 +1587,14 @@
return array();
}
+/* -( PhabricatorNgramInterface )------------------------------------------ */
+
+
+ public function newNgrams() {
+ return array(
+ id(new PhabricatorFileNameNgrams())
+ ->setValue($this->getName()),
+ );
+ }
+
}
diff --git a/src/applications/files/storage/PhabricatorFileNameNgrams.php b/src/applications/files/storage/PhabricatorFileNameNgrams.php
new file mode 100644
--- /dev/null
+++ b/src/applications/files/storage/PhabricatorFileNameNgrams.php
@@ -0,0 +1,18 @@
+<?php
+
+final class PhabricatorFileNameNgrams
+ extends PhabricatorSearchNgrams {
+
+ public function getNgramKey() {
+ return 'filename';
+ }
+
+ public function getColumnName() {
+ return 'name';
+ }
+
+ public function getApplicationName() {
+ return 'file';
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 4, 9:51 PM (1 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6730979
Default Alt Text
D17702.id42610.diff (6 KB)
Attached To
Mode
D17702: Implement ngram search for File objects
Attached
Detach File
Event Timeline
Log In to Comment