@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 PhrictionDatasourceEngineExtension
4 extends PhabricatorDatasourceEngineExtension {
5
6 public function newQuickSearchDatasources() {
7 return array(
8 new PhrictionDocumentDatasource(),
9 );
10 }
11
12 public function newJumpURI($query) {
13 $viewer = $this->getViewer();
14
15 // Send "w" to Phriction.
16 if (preg_match('/^w\z/i', $query)) {
17 return '/w/';
18 }
19
20 // Send "w <string>" to a search for similar wiki documents.
21 $matches = null;
22 if (preg_match('/^w\s+(.+)\z/i', $query, $matches)) {
23 $raw_query = $matches[1];
24
25 $engine = id(new PhrictionDocument())
26 ->newFerretEngine();
27
28 $compiler = id(new PhutilSearchQueryCompiler())
29 ->setEnableFunctions(true);
30
31 $raw_tokens = $compiler->newTokens($raw_query);
32
33 $fulltext_tokens = array();
34 foreach ($raw_tokens as $raw_token) {
35 $fulltext_token = id(new PhabricatorFulltextToken())
36 ->setToken($raw_token);
37 $fulltext_tokens[] = $fulltext_token;
38 }
39
40 $documents = id(new PhrictionDocumentQuery())
41 ->setViewer($viewer)
42 ->withFerretConstraint($engine, $fulltext_tokens)
43 ->execute();
44 if (count($documents) == 1) {
45 return head($documents)->getURI();
46 } else {
47 // More than one match, jump to search.
48 return urisprintf(
49 '/phriction/?order=relevance&query=%s#R',
50 $raw_query);
51 }
52 }
53
54 return null;
55 }
56}