Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
normandy
pleroma
Commits
ed8a2935
Commit
ed8a2935
authored
6 years ago
by
Maxim Filippov
Browse files
Options
Downloads
Patches
Plain Diff
Use ILIKE to search users
parent
9b80203e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/pleroma/user.ex
+7
-15
7 additions, 15 deletions
lib/pleroma/user.ex
test/user_test.exs
+17
-0
17 additions, 0 deletions
test/user_test.exs
with
24 additions
and
15 deletions
lib/pleroma/user.ex
+
7
−
15
View file @
ed8a2935
...
...
@@ -788,34 +788,26 @@ defmodule Pleroma.User do
@spec
search_for_admin
(%{
query:
binary
(),
admin:
Pleroma
.
User
.
t
(),
local:
boolean
(),
page:
number
(),
page_size:
number
()
})
::
{
:ok
,
[
Pleroma
.
User
.
t
()],
number
()}
def
search_for_admin
(%{
query:
term
,
admin:
admin
,
local:
local
,
page:
page
,
page_size:
page_size
})
do
t
er
m
=
String
.
trim_leading
(
term
,
"@"
)
maybe_local_qu
er
y
=
User
|>
maybe_local_user_query
(
local
)
local_paginated_query
=
User
|>
maybe_local_user_query
(
local
)
search_query
=
from
(
u
in
maybe_local_query
,
where:
ilike
(
u
.
nickname
,
^
"%
#{
term
}
%"
))
count
=
search_query
|>
Repo
.
aggregate
(
:count
,
:id
)
results
=
search_query
|>
paginate
(
page
,
page_size
)
|>
Repo
.
all
()
search_query
=
fts_search_subquery
(
term
,
local_paginated_query
)
count
=
term
|>
fts_search_subquery
()
|>
maybe_local_user_query
(
local
)
|>
Repo
.
aggregate
(
:count
,
:id
)
{
:ok
,
do_search
(
search_query
,
admin
),
count
}
{
:ok
,
results
,
count
}
end
def
search
(
query
,
resolve
\\
false
,
for_user
\\
nil
)
do
...
...
This diff is collapsed.
Click to expand it.
test/user_test.exs
+
17
−
0
View file @
ed8a2935
...
...
@@ -1098,4 +1098,21 @@ defmodule Pleroma.UserTest do
assert
{
:ok
,
user_state3
}
=
User
.
bookmark
(
user
,
id2
)
assert
user_state3
.
bookmarks
==
[
id2
]
end
describe
"search for admin"
do
test
"it ignores case"
do
insert
(
:user
,
nickname:
"papercoach"
)
insert
(
:user
,
nickname:
"CanadaPaperCoach"
)
{
:ok
,
_results
,
count
}
=
User
.
search_for_admin
(%{
query:
"paper"
,
local:
false
,
page:
1
,
page_size:
50
})
assert
count
==
2
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment