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;
|
|
|
|
|
|
|
|
$type_name = nonempty($handle->getTypeName(), 'Document');
|
|
|
|
|
|
|
|
require_celerity_resource('phabricator-search-results-css');
|
|
|
|
|
|
|
|
$link = phutil_render_tag(
|
|
|
|
'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) {
|
|
|
|
$img = phutil_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'result-image',
|
|
|
|
'style' => "background-image: url('{$img}');",
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($handle->getType()) {
|
|
|
|
case PhabricatorPHIDConstants::PHID_TYPE_CMIT:
|
|
|
|
$object_name = $handle->getName();
|
|
|
|
if ($this->object) {
|
|
|
|
$data = $this->object->getCommitData();
|
|
|
|
$summary = $data->getSummary();
|
|
|
|
if (strlen($summary)) {
|
|
|
|
$object_name = $handle->getName().': '.$data->getSummary();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$object_name = $handle->getFullName();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
[NO CLUE WHAT I'M DOING] Add an Elasticsearch engine
Summary:
I have no idea what I'm doing, but here's part of an elasticsearch engine. These things work:
- Indexing stuff (??)
- Searching for text/type?
- Reconstructing things??
All the complicated stuff doesn't work. I'm having a hard time figuring out the best way to model things because elasticsearch's documentation is not exactly the most complete or illuminating.
@amckinley, does this look sane-ish so far? Particularly, the /phabricator/<type>/<phid>/ URI scheme and how I've set up the relationships and fields in the documents?
How should I model the relationship and field queries? I want, like, an "equal" query but it seems like I've got "text" or "term" to work with and neither are exact match? And "term" doesn't consider PHIDs to be terms since they have hyphens in them?
I'll keep kind of slogging my way forward here but if you have valuable wisdom to share it would probably get me to a better end state much faster. The whole query construction phase is pretty much black magic to me.
Test Plan: nyancat
Reviewers: amckinley, vrana
Reviewed By: vrana
CC: jungejason, tuomaspelkonen, aran, 20after4, vrana
Differential Revision: https://secure.phabricator.com/D790
2012-04-21 00:33:09 +02:00
|
|
|
$index_link = phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/search/index/'.$handle->getPHID().'/',
|
|
|
|
'style' => 'float: right',
|
|
|
|
),
|
|
|
|
'Examine Index');
|
|
|
|
|
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
|
|
|
return
|
|
|
|
'<div class="phabricator-search-result">'.
|
|
|
|
$img.
|
|
|
|
'<div class="result-desc">'.
|
[NO CLUE WHAT I'M DOING] Add an Elasticsearch engine
Summary:
I have no idea what I'm doing, but here's part of an elasticsearch engine. These things work:
- Indexing stuff (??)
- Searching for text/type?
- Reconstructing things??
All the complicated stuff doesn't work. I'm having a hard time figuring out the best way to model things because elasticsearch's documentation is not exactly the most complete or illuminating.
@amckinley, does this look sane-ish so far? Particularly, the /phabricator/<type>/<phid>/ URI scheme and how I've set up the relationships and fields in the documents?
How should I model the relationship and field queries? I want, like, an "equal" query but it seems like I've got "text" or "term" to work with and neither are exact match? And "term" doesn't consider PHIDs to be terms since they have hyphens in them?
I'll keep kind of slogging my way forward here but if you have valuable wisdom to share it would probably get me to a better end state much faster. The whole query construction phase is pretty much black magic to me.
Test Plan: nyancat
Reviewers: amckinley, vrana
Reviewed By: vrana
CC: jungejason, tuomaspelkonen, aran, 20after4, vrana
Differential Revision: https://secure.phabricator.com/D790
2012-04-21 00:33:09 +02:00
|
|
|
$index_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
|
|
|
phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'class' => 'result-name',
|
|
|
|
'href' => $handle->getURI(),
|
|
|
|
),
|
|
|
|
$this->emboldenQuery($object_name)).
|
|
|
|
'<div class="result-type">'.$type_name.' · '.$link.'</div>'.
|
|
|
|
'</div>'.
|
|
|
|
'<div style="clear: both;"></div>'.
|
|
|
|
'</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function emboldenQuery($str) {
|
|
|
|
if (!$this->query) {
|
|
|
|
return phutil_escape_html($str);
|
|
|
|
}
|
|
|
|
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|