Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
PleatherStarfish committed Dec 11, 2024
1 parent fac27f8 commit f6d96d6
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions backend/components/views.py
Original file line number Diff line number Diff line change
@@ -109,11 +109,22 @@ def get(self, request):
| Q(type__name__icontains=search_query)
).annotate(similarity=Value(0.0, output_field=FloatField()))

components = (
(trigram_components | ilike_components)
.order_by("-similarity", "id")
.distinct("id")
)
# Combine the QuerySets
components = (trigram_components | ilike_components).distinct()

# Sort components by similarity in descending order
components = components.order_by("-similarity")

# Deduplicate components in Python, keeping only the highest similarity for each ID
unique_components = {}
for component in components:
if component.id not in unique_components:
unique_components[component.id] = component

# Convert the deduplicated dictionary back into a list
deduplicated_components = list(unique_components.values())

component = deduplicated_components

# Dynamically apply filters
try:

0 comments on commit f6d96d6

Please sign in to comment.