Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
<?php
|
|
|
|
|
2011-09-14 17:02:31 +02:00
|
|
|
/**
|
|
|
|
* @group search
|
|
|
|
*/
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
final class PhabricatorSearchResultView extends AphrontView {
|
|
|
|
|
|
|
|
private $handle;
|
|
|
|
private $query;
|
|
|
|
private $object;
|
|
|
|
|
|
|
|
public function setHandle(PhabricatorObjectHandle $handle) {
|
|
|
|
$this->handle = $handle;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setQuery(PhabricatorSearchQuery $query) {
|
|
|
|
$this->query = $query;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setObject($object) {
|
|
|
|
$this->object = $object;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
$handle = $this->handle;
|
2012-11-07 00:35:26 +01:00
|
|
|
if (!$handle->isComplete()) {
|
|
|
|
return;
|
|
|
|
}
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
|
|
|
|
$type_name = nonempty($handle->getTypeName(), 'Document');
|
|
|
|
|
|
|
|
require_celerity_resource('phabricator-search-results-css');
|
|
|
|
|
2013-01-18 09:32:58 +01:00
|
|
|
$link = phutil_tag(
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $handle->getURI(),
|
|
|
|
),
|
|
|
|
PhabricatorEnv::getProductionURI($handle->getURI()));
|
|
|
|
|
2012-01-10 23:48:55 +01:00
|
|
|
$img = $handle->getImageURI();
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
|
|
|
|
if ($img) {
|
2013-01-18 03:57:09 +01:00
|
|
|
$img = phutil_tag(
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'result-image',
|
|
|
|
'style' => "background-image: url('{$img}');",
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
}
|
|
|
|
|
2013-11-26 05:05:36 +01:00
|
|
|
$title = $this->emboldenQuery($handle->getFullName());
|
|
|
|
if ($handle->getStatus() == PhabricatorObjectHandleStatus::STATUS_CLOSED) {
|
|
|
|
$title = phutil_tag('del', array(), $title);
|
|
|
|
}
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
return hsprintf(
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
'<div class="phabricator-search-result">'.
|
2013-02-13 23:50:15 +01:00
|
|
|
'%s'.
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
'<div class="result-desc">'.
|
2013-02-13 23:50:15 +01:00
|
|
|
'%s'.
|
|
|
|
'<div class="result-type">%s · %s</div>'.
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
'</div>'.
|
|
|
|
'<div style="clear: both;"></div>'.
|
2013-02-13 23:50:15 +01:00
|
|
|
'</div>',
|
|
|
|
$img,
|
|
|
|
phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'class' => 'result-name',
|
|
|
|
'href' => $handle->getURI(),
|
|
|
|
),
|
2013-11-26 05:05:36 +01:00
|
|
|
$title),
|
2013-02-13 23:50:15 +01:00
|
|
|
$type_name,
|
|
|
|
$link);
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function emboldenQuery($str) {
|
|
|
|
if (!$this->query) {
|
2013-02-13 23:48:19 +01:00
|
|
|
return $str;
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$query = $this->query->getQuery();
|
|
|
|
|
2012-04-02 22:33:36 +02:00
|
|
|
$quoted_regexp = '/"([^"]*)"/';
|
|
|
|
$matches = array(1 => array());
|
|
|
|
preg_match_all($quoted_regexp, $query, $matches);
|
|
|
|
$quoted_queries = $matches[1];
|
|
|
|
$query = preg_replace($quoted_regexp, '', $query);
|
|
|
|
|
|
|
|
$query = preg_split('/\s+[+|]?/', $query);
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
$query = array_filter($query);
|
2012-04-02 22:33:36 +02:00
|
|
|
$query = array_merge($query, $quoted_queries);
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
$str = phutil_escape_html($str);
|
|
|
|
foreach ($query as $word) {
|
|
|
|
$word = phutil_escape_html($word);
|
2012-04-02 22:33:36 +02:00
|
|
|
$word = preg_quote($word, '/');
|
|
|
|
$word = preg_replace('/\\\\\*$/', '\w*', $word);
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
$str = preg_replace(
|
2012-04-02 22:33:36 +02:00
|
|
|
'/(?:^|\b)('.$word.')(?:\b|$)/i',
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
'<strong>\1</strong>',
|
|
|
|
$str);
|
|
|
|
}
|
2013-01-18 09:32:58 +01:00
|
|
|
return phutil_safe_html($str);
|
Improve search result listing
Summary:
Make it prettier, paginate, add user pictures, show document types, clean some
stuff up a little. Plenty of room for improvement but this should make it a lot
more useful.
Test Plan:
Here's what the new one looks like:
https://secure.phabricator.com/file/view/PHID-FILE-edce2b83c2e3a121c2b7/
Reviewed By: jungejason
Reviewers: tomo, jungejason, aran, tuomaspelkonen, mroch
Commenters: tomo
CC: aran, tomo, jungejason, epriestley
Differential Revision: 545
2011-06-28 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|