@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class DiffusionDatasourceEngineExtension
4 extends PhabricatorDatasourceEngineExtension {
5
6 public function newQuickSearchDatasources() {
7 return array(
8 new DiffusionRepositoryDatasource(),
9 new DiffusionSymbolDatasource(),
10 );
11 }
12
13 public function newJumpURI($query) {
14 $viewer = $this->getViewer();
15
16 // Send "r" to Diffusion.
17 if (preg_match('/^r\z/i', $query)) {
18 return '/diffusion/';
19 }
20
21 // Send "a" to the commit list ("Audit").
22 if (preg_match('/^a\z/i', $query)) {
23 return '/diffusion/commit/';
24 }
25
26 // Send "r <string>" to a search for a matching repository.
27 $matches = null;
28 if (preg_match('/^r\s+(.+)\z/i', $query, $matches)) {
29 $raw_query = $matches[1];
30
31 $engine = id(new PhabricatorRepository())
32 ->newFerretEngine();
33
34 $compiler = id(new PhutilSearchQueryCompiler())
35 ->setEnableFunctions(true);
36
37 $raw_tokens = $compiler->newTokens($raw_query);
38
39 $fulltext_tokens = array();
40 foreach ($raw_tokens as $raw_token) {
41 $fulltext_token = id(new PhabricatorFulltextToken())
42 ->setToken($raw_token);
43 $fulltext_tokens[] = $fulltext_token;
44 }
45
46 $repositories = id(new PhabricatorRepositoryQuery())
47 ->setViewer($viewer)
48 ->withFerretConstraint($engine, $fulltext_tokens)
49 ->execute();
50 if (count($repositories) == 1) {
51 // Just one match, jump to repository.
52 return head($repositories)->getURI();
53 } else {
54 // More than one match, jump to search.
55 return urisprintf(
56 '/diffusion/?order=relevance&query=%s#R',
57 $raw_query);
58 }
59 }
60
61 // Send "s <string>" to a symbol search.
62 $matches = null;
63 if (preg_match('/^s\s+(.+)\z/i', $query, $matches)) {
64 $symbol = $matches[1];
65
66 $parts = null;
67 if (preg_match('/(.*)(?:\\.|::|->)(.*)/', $symbol, $parts)) {
68 return urisprintf(
69 '/diffusion/symbol/%p/?jump=true&context=%s',
70 $parts[2],
71 $parts[1]);
72 } else {
73 return urisprintf(
74 '/diffusion/symbol/%p/?jump=true',
75 $symbol);
76 }
77 }
78
79 return null;
80 }
81
82}