mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-07 02:48:27 +02:00
Implement basic search
This commit is contained in:
33
bookmarks/queries.py
Normal file
33
bookmarks/queries.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models import Q
|
||||
|
||||
from bookmarks.models import Bookmark
|
||||
|
||||
|
||||
def query_bookmarks(user: User, query_string: str):
|
||||
query_set = Bookmark.objects
|
||||
|
||||
# Sanitize query params
|
||||
if not query_string:
|
||||
query_string = ''
|
||||
|
||||
# Filter for user
|
||||
query_set = query_set.filter(owner=user)
|
||||
|
||||
# Split query into keywords
|
||||
keywords = query_string.strip().split(' ')
|
||||
keywords = [word for word in keywords if word]
|
||||
|
||||
# Filter for each keyword
|
||||
for word in keywords:
|
||||
query_set = query_set.filter(
|
||||
Q(title__contains=word)
|
||||
| Q(description__contains=word)
|
||||
| Q(website_title__contains=word)
|
||||
| Q(website_description__contains=word)
|
||||
)
|
||||
|
||||
# Sort by modification date
|
||||
query_set = query_set.order_by('-date_modified')
|
||||
|
||||
return query_set
|
Reference in New Issue
Block a user