1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-25 23:10:57 +01:00

PhamePostSearchEngine

Summary: A very basic search engine for Phame Posts

Test Plan: Built a dashboard to test various queries. Saw posts.

Reviewers: btrahan, epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T6269

Differential Revision: https://secure.phabricator.com/D13671
This commit is contained in:
Chad Little 2015-07-22 07:30:52 -07:00
parent d415641b02
commit 602bc4e2fd
3 changed files with 122 additions and 12 deletions

View file

@ -3034,6 +3034,7 @@ phutil_register_library_map(array(
'PhamePostPreviewController' => 'applications/phame/controller/post/PhamePostPreviewController.php', 'PhamePostPreviewController' => 'applications/phame/controller/post/PhamePostPreviewController.php',
'PhamePostPublishController' => 'applications/phame/controller/post/PhamePostPublishController.php', 'PhamePostPublishController' => 'applications/phame/controller/post/PhamePostPublishController.php',
'PhamePostQuery' => 'applications/phame/query/PhamePostQuery.php', 'PhamePostQuery' => 'applications/phame/query/PhamePostQuery.php',
'PhamePostSearchEngine' => 'applications/phame/query/PhamePostSearchEngine.php',
'PhamePostTransaction' => 'applications/phame/storage/PhamePostTransaction.php', 'PhamePostTransaction' => 'applications/phame/storage/PhamePostTransaction.php',
'PhamePostTransactionQuery' => 'applications/phame/query/PhamePostTransactionQuery.php', 'PhamePostTransactionQuery' => 'applications/phame/query/PhamePostTransactionQuery.php',
'PhamePostUnpublishController' => 'applications/phame/controller/post/PhamePostUnpublishController.php', 'PhamePostUnpublishController' => 'applications/phame/controller/post/PhamePostUnpublishController.php',
@ -7007,6 +7008,7 @@ phutil_register_library_map(array(
'PhamePostPreviewController' => 'PhameController', 'PhamePostPreviewController' => 'PhameController',
'PhamePostPublishController' => 'PhameController', 'PhamePostPublishController' => 'PhameController',
'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhamePostSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhamePostTransaction' => 'PhabricatorApplicationTransaction', 'PhamePostTransaction' => 'PhabricatorApplicationTransaction',
'PhamePostTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'PhamePostTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhamePostUnpublishController' => 'PhameController', 'PhamePostUnpublishController' => 'PhameController',

View file

@ -81,61 +81,59 @@ final class PhamePostQuery extends PhabricatorCursorPagedPolicyAwareQuery {
return $posts; return $posts;
} }
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = array(); $where = parent::buildWhereClauseParts($conn);
if ($this->ids) { if ($this->ids) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'p.id IN (%Ld)', 'p.id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids) { if ($this->phids) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'p.phid IN (%Ls)', 'p.phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->bloggerPHIDs) { if ($this->bloggerPHIDs) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'p.bloggerPHID IN (%Ls)', 'p.bloggerPHID IN (%Ls)',
$this->bloggerPHIDs); $this->bloggerPHIDs);
} }
if ($this->phameTitles) { if ($this->phameTitles) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'p.phameTitle IN (%Ls)', 'p.phameTitle IN (%Ls)',
$this->phameTitles); $this->phameTitles);
} }
if ($this->visibility !== null) { if ($this->visibility !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'p.visibility = %d', 'p.visibility = %d',
$this->visibility); $this->visibility);
} }
if ($this->publishedAfter !== null) { if ($this->publishedAfter !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'p.datePublished > %d', 'p.datePublished > %d',
$this->publishedAfter); $this->publishedAfter);
} }
if ($this->blogPHIDs) { if ($this->blogPHIDs) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'p.blogPHID in (%Ls)', 'p.blogPHID in (%Ls)',
$this->blogPHIDs); $this->blogPHIDs);
} }
$where[] = $this->buildPagingClause($conn_r); return $where;
return $this->formatWhereClause($where);
} }
public function getQueryApplicationClass() { public function getQueryApplicationClass() {

View file

@ -0,0 +1,110 @@
<?php
final class PhamePostSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Phame Posts');
}
public function getApplicationClassName() {
return 'PhabricatorPhameApplication';
}
public function newQuery() {
return new PhamePostQuery();
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if (strlen($map['visibility'])) {
$query->withVisibility($map['visibility']);
}
return $query;
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchSelectField())
->setKey('visibility')
->setOptions(array(
'' => pht('All'),
PhamePost::VISIBILITY_PUBLISHED => pht('Live'),
PhamePost::VISIBILITY_DRAFT => pht('Draft'),
)),
);
}
protected function getURI($path) {
return '/phame/post/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'all' => pht('All'),
'live' => pht('Live'),
'draft' => pht('Draft'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
case 'live':
return $query->setParameter(
'visibility', PhamePost::VISIBILITY_PUBLISHED);
case 'draft':
return $query->setParameter(
'visibility', PhamePost::VISIBILITY_DRAFT);
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $posts,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($posts, 'PhamePost');
$viewer = $this->requireViewer();
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($posts as $post) {
$id = $post->getID();
$blog = $viewer->renderHandle($post->getBlogPHID())->render();
$item = id(new PHUIObjectItemView())
->setUser($viewer)
->setObject($post)
->setHeader($post->getTitle())
->setStatusIcon('fa-star')
->setHref($this->getApplicationURI("/post/view/{$id}/"))
->addAttribute(
pht('Blog: %s', $blog));
if ($post->isDraft()) {
$item->setStatusIcon('fa-star-o grey');
$item->setDisabled(true);
$item->addIcon('none', pht('Draft Post'));
} else {
$date = $post->getDatePublished();
$item->setEpoch($date);
}
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No blogs found.'));
return $result;
}
}