Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F107938356
PhrictionDatasourceEngineExtension.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Apr 12, 04:50
Size
1 KB
Mime Type
text/x-php
Expires
Mon, Apr 14, 04:50 (2 d)
Engine
blob
Format
Raw Data
Handle
25502560
Attached To
rPH Phabricator
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
;
}
}
Event Timeline
Log In to Comment