Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1191046
PhrictionDatasourceEngineExtension.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
PhrictionDatasourceEngineExtension.php
View Options
<?php
final
class
PhrictionDatasourceEngineExtension
extends
PhabricatorDatasourceEngineExtension
{
public
function
newQuickSearchDatasources
()
{
return
array
(
new
PhrictionDocumentDatasource
(),
);
}
public
function
newJumpURI
(
$query
)
{
$viewer
=
$this
->
getViewer
();
// Send "w" to Phriction.
if
(
preg_match
(
'/^w
\z
/i'
,
$query
))
{
return
'/w/'
;
}
// Send "w <string>" to a search for similar wiki documents.
$matches
=
null
;
if
(
preg_match
(
'/^w
\s
+(.+)
\z
/i'
,
$query
,
$matches
))
{
$raw_query
=
$matches
[
1
];
$engine
=
id
(
new
PhrictionDocument
())
->
newFerretEngine
();
$compiler
=
id
(
new
PhutilSearchQueryCompiler
())
->
setEnableFunctions
(
true
);
$raw_tokens
=
$compiler
->
newTokens
(
$raw_query
);
$fulltext_tokens
=
array
();
foreach
(
$raw_tokens
as
$raw_token
)
{
$fulltext_token
=
id
(
new
PhabricatorFulltextToken
())
->
setToken
(
$raw_token
);
$fulltext_tokens
[]
=
$fulltext_token
;
}
$documents
=
id
(
new
PhrictionDocumentQuery
())
->
setViewer
(
$viewer
)
->
withFerretConstraint
(
$engine
,
$fulltext_tokens
)
->
execute
();
if
(
count
(
$documents
)
==
1
)
{
return
head
(
$documents
)->
getURI
();
}
else
{
// More than one match, jump to search.
return
urisprintf
(
'/phriction/?order=relevance&query=%s#R'
,
$raw_query
);
}
}
return
null
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Jul 2, 4:42 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
264998
Default Alt Text
PhrictionDatasourceEngineExtension.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment