Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15402805
D8407.id19963.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D8407.id19963.diff
View Options
diff --git a/resources/sql/autopatches/20140305.diviner.1.slugcol.sql b/resources/sql/autopatches/20140305.diviner.1.slugcol.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20140305.diviner.1.slugcol.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_diviner.diviner_livesymbol
+ ADD titleSlugHash CHAR(12) COLLATE latin1_bin AFTER title;
diff --git a/resources/sql/autopatches/20140305.diviner.2.slugkey.sql b/resources/sql/autopatches/20140305.diviner.2.slugkey.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20140305.diviner.2.slugkey.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_diviner.diviner_livesymbol
+ ADD KEY `key_slug` (titleSlugHash);
diff --git a/src/applications/diviner/atom/DivinerAtomRef.php b/src/applications/diviner/atom/DivinerAtomRef.php
--- a/src/applications/diviner/atom/DivinerAtomRef.php
+++ b/src/applications/diviner/atom/DivinerAtomRef.php
@@ -109,6 +109,10 @@
return $this->title;
}
+ public function getTitleSlug() {
+ return self::normalizeTitleString($this->getTitle());
+ }
+
public function toDictionary() {
return array(
'book' => $this->getBook(),
@@ -144,6 +148,7 @@
$obj->index = idx($dict, 'index');
$obj->summary = idx($dict, 'summary');
$obj->title = idx($dict, 'title');
+
return $obj;
}
@@ -193,4 +198,9 @@
return idx($alternates, $str, $str);
}
+ public static function normalizeTitleString($str) {
+ $str = self::normalizeString($str);
+ return phutil_utf8_strtolower($str);
+ }
+
}
diff --git a/src/applications/diviner/controller/DivinerFindController.php b/src/applications/diviner/controller/DivinerFindController.php
--- a/src/applications/diviner/controller/DivinerFindController.php
+++ b/src/applications/diviner/controller/DivinerFindController.php
@@ -24,14 +24,7 @@
}
$query = id(new DivinerAtomQuery())
- ->setViewer($viewer)
- ->withNames(
- array(
- $request->getStr('name'),
- // TODO: This could probably be more smartly normalized in the DB,
- // but just fake it for now.
- phutil_utf8_strtolower($request->getStr('name')),
- ));
+ ->setViewer($viewer);
if ($book) {
$query->withBookPHIDs(array($book->getPHID()));
@@ -47,7 +40,23 @@
$query->withTypes(array($type));
}
- $atoms = $query->execute();
+ $name_query = clone $query;
+
+ $name_query->withNames(
+ array(
+ $request->getStr('name'),
+ // TODO: This could probably be more smartly normalized in the DB,
+ // but just fake it for now.
+ phutil_utf8_strtolower($request->getStr('name')),
+ ));
+
+ $atoms = $name_query->execute();
+
+ if (!$atoms) {
+ $title_query = clone $query;
+ $title_query->withTitles(array($request->getStr('name')));
+ $atoms = $title_query->execute();
+ }
if (!$atoms) {
return new Aphront404Response();
diff --git a/src/applications/diviner/query/DivinerAtomQuery.php b/src/applications/diviner/query/DivinerAtomQuery.php
--- a/src/applications/diviner/query/DivinerAtomQuery.php
+++ b/src/applications/diviner/query/DivinerAtomQuery.php
@@ -13,6 +13,7 @@
private $includeUndocumentable;
private $includeGhosts;
private $nodeHashes;
+ private $titles;
private $needAtoms;
private $needExtends;
@@ -58,6 +59,11 @@
return $this;
}
+ public function withTitles($titles) {
+ $this->titles = $titles;
+ return $this;
+ }
+
public function needAtoms($need) {
$this->needAtoms = $need;
return $this;
@@ -287,6 +293,20 @@
$this->names);
}
+ if ($this->titles) {
+ $hashes = array();
+ foreach ($this->titles as $title) {
+ $slug = DivinerAtomRef::normalizeTitleString($title);
+ $hash = PhabricatorHash::digestForIndex($slug);
+ $hashes[] = $hash;
+ }
+
+ $where[] = qsprintf(
+ $conn_r,
+ 'titleSlugHash in (%Ls)',
+ $hashes);
+ }
+
if ($this->contexts) {
$with_null = false;
$contexts = $this->contexts;
diff --git a/src/applications/diviner/storage/DivinerLiveSymbol.php b/src/applications/diviner/storage/DivinerLiveSymbol.php
--- a/src/applications/diviner/storage/DivinerLiveSymbol.php
+++ b/src/applications/diviner/storage/DivinerLiveSymbol.php
@@ -13,6 +13,7 @@
protected $nodeHash;
protected $title;
+ protected $titleSlugHash;
protected $groupName;
protected $summary;
protected $isDocumentable = 0;
@@ -105,6 +106,18 @@
return $title;
}
+ public function setTitle($value) {
+ $this->writeField('title', $value);
+ if (strlen($value)) {
+ $slug = DivinerAtomRef::normalizeTitleString($value);
+ $hash = PhabricatorHash::digestForIndex($slug);
+ $this->titleSlugHash = $hash;
+ } else {
+ $this->titleSlugHash = null;
+ }
+ return $this;
+ }
+
public function attachExtends(array $extends) {
assert_instances_of($extends, 'DivinerLiveSymbol');
$this->extends = $extends;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 19, 12:26 AM (4 d, 8 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7710576
Default Alt Text
D8407.id19963.diff (4 KB)
Attached To
Mode
D8407: Fix Diviner links to articles by title
Attached
Detach File
Event Timeline
Log In to Comment