Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add hierarchical tag search #780

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bookmarks/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class Meta:
"bookmark_link_target",
"web_archive_integration",
"tag_search",
"tag_hierarchy",
"enable_sharing",
"enable_public_sharing",
"enable_favicons",
Expand Down
18 changes: 18 additions & 0 deletions bookmarks/migrations/0037_userprofile_tag_hierarchy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.3 on 2024-05-17 07:09

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("bookmarks", "0036_userprofile_auto_tagging_rules"),
]

operations = [
migrations.AddField(
model_name="userprofile",
name="tag_hierarchy",
field=models.BooleanField(default=False),
),
]
2 changes: 2 additions & 0 deletions bookmarks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ class UserProfile(models.Model):
blank=False,
default=TAG_GROUPING_ALPHABETICAL,
)
tag_hierarchy = models.BooleanField(default=False, null=False)
enable_sharing = models.BooleanField(default=False, null=False)
enable_public_sharing = models.BooleanField(default=False, null=False)
enable_favicons = models.BooleanField(default=False, null=False)
Expand Down Expand Up @@ -433,6 +434,7 @@ class Meta:
"web_archive_integration",
"tag_search",
"tag_grouping",
"tag_hierarchy",
"enable_sharing",
"enable_public_sharing",
"enable_favicons",
Expand Down
9 changes: 8 additions & 1 deletion bookmarks/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ def _base_bookmarks_query(
query_set = query_set.filter(conditions)

for tag_name in query["tag_names"]:
query_set = query_set.filter(tags__name__iexact=tag_name)
if profile.tag_hierarchy:
# Filter for tags with the exact name or a parent tag
query_set = query_set.filter(
Q(tags__name__iexact=tag_name) | Q(tags__name__istartswith=f"{tag_name}/")
)
else:
# Filter for tags with the exact name
query_set = query_set.filter(tags__name__iexact=tag_name)

# Untagged bookmarks
if query["untagged"]:
Expand Down
10 changes: 10 additions & 0 deletions bookmarks/templates/settings/general.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ <h2>Profile</h2>
If disabled, tags will not be grouped.
</div>
</div>
<div class="form-group">
<label for="{{ form.tag_hierarchy.id_for_label }}" class="form-checkbox">
{{ form.tag_hierarchy }}
<i class="form-icon"></i> Tag hierarchy
</label>
<div class="form-input-hint">
Allow to create tags with a hierarchical structure.
When enabled, tags can be organized in a tree-like structure, where each tag can have one or more parent tags separated by a slash character (/). Searching for a parent tag will also include bookmarks with child tags.
</div>
</div>
<div class="form-group">
<details {% if form.auto_tagging_rules.value %}open{% endif %}>
<summary>Auto Tagging</summary>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.