add tag hierarchy search

This commit is contained in:
Stefan Hojer 2024-07-13 21:23:52 +00:00
parent fbc97a3841
commit 5b516152f2
No known key found for this signature in database
6 changed files with 41 additions and 3 deletions

View file

@ -125,6 +125,7 @@ class UserProfileSerializer(serializers.ModelSerializer):
"bookmark_link_target",
"web_archive_integration",
"tag_search",
"tag_hierarchy",
"enable_sharing",
"enable_public_sharing",
"enable_favicons",

View file

@ -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),
),
]

View file

@ -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)
@ -433,6 +434,7 @@ class UserProfileForm(forms.ModelForm):
"web_archive_integration",
"tag_search",
"tag_grouping",
"tag_hierarchy",
"enable_sharing",
"enable_public_sharing",
"enable_favicons",

View file

@ -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"]:

View file

@ -118,6 +118,16 @@
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>

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "linkding",
"version": "1.30.0",
"version": "1.31.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "linkding",
"version": "1.30.0",
"version": "1.31.0",
"license": "MIT",
"dependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",