Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/typeahead/PhrictionDocumentDatasource.php
Show All 12 Lines | final class PhrictionDocumentDatasource | ||||
public function getDatasourceApplicationClass() { | public function getDatasourceApplicationClass() { | ||||
return 'PhabricatorPhrictionApplication'; | return 'PhabricatorPhrictionApplication'; | ||||
} | } | ||||
public function loadResults() { | public function loadResults() { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$raw_query = $this->getRawQuery(); | $query = id(new PhrictionDocumentQuery()) | ||||
->setViewer($viewer) | |||||
$engine = id(new PhrictionDocument()) | ->needContent(true); | ||||
->newFerretEngine(); | |||||
$compiler = id(new PhutilSearchQueryCompiler()) | |||||
->setEnableFunctions(true); | |||||
$raw_tokens = $compiler->newTokens($raw_query); | |||||
$fulltext_tokens = array(); | |||||
foreach ($raw_tokens as $raw_token) { | |||||
// This is a little hacky and could maybe be cleaner. We're treating | |||||
// every search term as though the user had entered "title:dog" insead | |||||
// of "dog". | |||||
$alternate_token = PhutilSearchQueryToken::newFromDictionary( | |||||
array( | |||||
'quoted' => $raw_token->isQuoted(), | |||||
'value' => $raw_token->getValue(), | |||||
'operator' => PhutilSearchQueryCompiler::OPERATOR_SUBSTRING, | |||||
'function' => 'title', | |||||
)); | |||||
$fulltext_token = id(new PhabricatorFulltextToken()) | $this->applyFerretConstraints( | ||||
->setToken($alternate_token); | $query, | ||||
$fulltext_tokens[] = $fulltext_token; | id(new PhrictionDocument())->newFerretEngine(), | ||||
} | 'title', | ||||
$this->getRawQuery()); | |||||
$documents = id(new PhrictionDocumentQuery()) | $documents = $query->execute(); | ||||
->setViewer($viewer) | |||||
->withFerretConstraint($engine, $fulltext_tokens) | |||||
->needContent(true) | |||||
->execute(); | |||||
$results = array(); | $results = array(); | ||||
foreach ($documents as $document) { | foreach ($documents as $document) { | ||||
$content = $document->getContent(); | $content = $document->getContent(); | ||||
if (!$document->isActive()) { | if (!$document->isActive()) { | ||||
$closed = $document->getStatusDisplayName(); | $closed = $document->getStatusDisplayName(); | ||||
} else { | } else { | ||||
Show All 27 Lines |