mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 14:30:56 +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:
parent
d415641b02
commit
602bc4e2fd
3 changed files with 122 additions and 12 deletions
|
@ -3034,6 +3034,7 @@ phutil_register_library_map(array(
|
|||
'PhamePostPreviewController' => 'applications/phame/controller/post/PhamePostPreviewController.php',
|
||||
'PhamePostPublishController' => 'applications/phame/controller/post/PhamePostPublishController.php',
|
||||
'PhamePostQuery' => 'applications/phame/query/PhamePostQuery.php',
|
||||
'PhamePostSearchEngine' => 'applications/phame/query/PhamePostSearchEngine.php',
|
||||
'PhamePostTransaction' => 'applications/phame/storage/PhamePostTransaction.php',
|
||||
'PhamePostTransactionQuery' => 'applications/phame/query/PhamePostTransactionQuery.php',
|
||||
'PhamePostUnpublishController' => 'applications/phame/controller/post/PhamePostUnpublishController.php',
|
||||
|
@ -7007,6 +7008,7 @@ phutil_register_library_map(array(
|
|||
'PhamePostPreviewController' => 'PhameController',
|
||||
'PhamePostPublishController' => 'PhameController',
|
||||
'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhamePostSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhamePostTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'PhamePostTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'PhamePostUnpublishController' => 'PhameController',
|
||||
|
|
|
@ -81,61 +81,59 @@ final class PhamePostQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
|||
return $posts;
|
||||
}
|
||||
|
||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||
$where = parent::buildWhereClauseParts($conn);
|
||||
|
||||
if ($this->ids) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'p.id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->phids) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'p.phid IN (%Ls)',
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
if ($this->bloggerPHIDs) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'p.bloggerPHID IN (%Ls)',
|
||||
$this->bloggerPHIDs);
|
||||
}
|
||||
|
||||
if ($this->phameTitles) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'p.phameTitle IN (%Ls)',
|
||||
$this->phameTitles);
|
||||
}
|
||||
|
||||
if ($this->visibility !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'p.visibility = %d',
|
||||
$this->visibility);
|
||||
}
|
||||
|
||||
if ($this->publishedAfter !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'p.datePublished > %d',
|
||||
$this->publishedAfter);
|
||||
}
|
||||
|
||||
if ($this->blogPHIDs) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'p.blogPHID in (%Ls)',
|
||||
$this->blogPHIDs);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
return $where;
|
||||
}
|
||||
|
||||
public function getQueryApplicationClass() {
|
||||
|
|
110
src/applications/phame/query/PhamePostSearchEngine.php
Normal file
110
src/applications/phame/query/PhamePostSearchEngine.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue