Skip to content

Commit ceec162

Browse files
committed
Improve completion text search and ordering
This is an attempt to improve the quality of completion results. - Change text query from `title:~term` to `core:~term` to search both titles and bodies. - Order results first by rank and then by primary result field.
1 parent e02cb8b commit ceec162

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

autoload/phabricator.vim

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function! s:api_root() abort
6161
return api_root
6262
endfunction
6363

64-
function! s:request(method, order, query) abort
64+
function! s:request(method, params) abort
6565
if !executable('curl')
6666
call s:throw('cURL is required')
6767
endif
@@ -80,10 +80,9 @@ function! s:request(method, order, query) abort
8080
call extend(args, ['-A', 'vim-phabricator'])
8181
call extend(args, ['-d', 'api.token=' . token])
8282
call extend(args, ['-d', 'queryKey=active'])
83-
call extend(args, ['-d', 'order[0]=' . a:order])
84-
if !empty(a:query)
85-
call extend(args, ['-d', 'constraints[query]=title%3A~' . a:query])
86-
endif
83+
for [key, value] in items(a:params)
84+
call extend(args, ['-d', key . '=' . value])
85+
endfor
8786
call add(args, s:api_root() . a:method)
8887

8988
let data = system('curl ' . join(args))
@@ -100,13 +99,19 @@ function! s:request(method, order, query) abort
10099
endfunction
101100

102101
function! phabricator#query_projects(query) abort
103-
let items = s:request('project.search', 'name', a:query)
104-
return filter(items, 'v:val.slug =~# "^' . a:query . '"')
102+
return s:request('project.search', {
103+
\ 'order[0]': 'rank',
104+
\ 'order[1]': 'name',
105+
\ 'constraints[query]': 'core%3A~' . a:query,
106+
\ })
105107
endfunction
106108

107109
function! phabricator#query_users(query) abort
108-
let items = s:request('user.search', 'username', a:query)
109-
return filter(items, 'v:val.username =~# "^' . a:query . '"')
110+
return s:request('user.search', {
111+
\ 'order[0]': 'rank',
112+
\ 'order[1]': 'username',
113+
\ 'constraints[query]': 'core%3A~' . a:query,
114+
\ })
110115
endfunction
111116

112117
function! phabricator#complete(findstart, base) abort

0 commit comments

Comments
 (0)