Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AE UTBM
Sith
Commits
e66b274f
Commit
e66b274f
authored
Dec 19, 2016
by
Skia
🤘
Browse files
Add index to search function
parent
5b95299b
Pipeline
#556
passed with stage
in 2 minutes and 25 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
core/models.py
View file @
e66b274f
...
...
@@ -613,7 +613,6 @@ class SithFile(models.Model):
self
.
copy_rights
()
def
apply_rights_recursively
(
self
,
only_folders
=
False
):
print
(
self
)
children
=
self
.
children
.
all
()
if
only_folders
:
children
=
children
.
filter
(
is_folder
=
True
)
...
...
core/search_indexes.py
View file @
e66b274f
...
...
@@ -13,7 +13,3 @@ class UserIndex(indexes.SearchIndex, indexes.Indexable):
"""Used when the entire index for model is updated."""
return
self
.
get_model
().
objects
.
all
()
def
prepare
(
self
,
obj
):
ret
=
super
(
UserIndex
,
self
).
prepare
(
obj
)
print
(
ret
)
return
ret
core/views/site.py
View file @
e66b274f
...
...
@@ -10,6 +10,8 @@ import os
import
json
from
itertools
import
chain
from
haystack.query
import
SearchQuerySet
from
core.models
import
User
,
Notification
from
club.models
import
Club
...
...
@@ -34,24 +36,8 @@ def notification(request, notif_id):
return
redirect
(
"/"
)
def
search_user
(
query
,
as_json
=
False
):
users
=
[]
if
query
:
exact_nick
=
User
.
objects
.
filter
(
nick_name__iexact
=
query
).
all
()
nicks
=
User
.
objects
.
filter
(
nick_name__icontains
=
query
).
exclude
(
id__in
=
exact_nick
).
all
()
users
=
User
.
objects
.
filter
(
Q
(
first_name__icontains
=
query
)
|
Q
(
last_name__icontains
=
query
)).
exclude
(
id__in
=
exact_nick
).
exclude
(
id__in
=
nicks
).
all
()
nicks
=
nicks
[:
5
]
users
=
users
[:
50
]
if
as_json
:
# Re-loads json to avoid double encoding by JsonResponse, but still benefit from serializers
exact_nick
=
json
.
loads
(
serializers
.
serialize
(
'json'
,
exact_nick
,
fields
=
(
'nick_name'
,
'last_name'
,
'first_name'
,
'profile_pict'
)))
nicks
=
json
.
loads
(
serializers
.
serialize
(
'json'
,
nicks
,
fields
=
(
'nick_name'
,
'last_name'
,
'first_name'
,
'profile_pict'
)))
users
=
json
.
loads
(
serializers
.
serialize
(
'json'
,
users
,
fields
=
(
'nick_name'
,
'last_name'
,
'first_name'
,
'profile_pict'
)))
else
:
exact_nick
=
list
(
exact_nick
)
nicks
=
list
(
nicks
)
users
=
list
(
users
)
users
=
exact_nick
+
nicks
+
users
return
users
res
=
SearchQuerySet
().
models
(
User
).
filter
(
text
=
query
).
filter_or
(
text__contains
=
query
)[:
20
]
return
[
r
.
object
for
r
in
res
]
def
search_club
(
query
,
as_json
=
False
):
clubs
=
[]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment