Skip to content

Commit b2880ec

Browse files
committed
use updated fuzzy_name match
1 parent 69fb8e9 commit b2880ec

2 files changed

Lines changed: 5 additions & 10 deletions

File tree

tom_targets/base_models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,13 @@ def match_exact_name(self, name):
160160
queryset = super().get_queryset().filter(name=name)
161161
return queryset
162162

163-
def match_fuzzy_name(self, name):
163+
def match_fuzzy_name(self, name, input_queryset=None):
164164
"""
165165
Returns a queryset of targets with a name OR ALIAS that, when processed by ``simplify_name``, match a similarly
166166
processed version of the name that is received.
167167
168168
:param name: The string against which target names and aliases will be matched.
169+
:param input_queryset: Optional queryset to filter the results. If not provided, all targets will be considered.
169170
170171
:return: queryset containing matching Targets. Will return targets even when matched value is an alias.
171172
"""
@@ -175,7 +176,8 @@ def match_fuzzy_name(self, name):
175176
for alias in target.names:
176177
if self.simplify_name(alias) == simple_name:
177178
matching_names.append(target.name)
178-
queryset = self.get_queryset().filter(name__in=matching_names)
179+
initial_queryset = input_queryset or self.get_queryset()
180+
queryset = initial_queryset.filter(name__in=matching_names)
179181
return queryset
180182

181183
def simplify_name(self, name):

tom_targets/filters.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,7 @@ def filter_name_fuzzy(self, queryset, name, value):
7171
Return a queryset for targets with names or aliases fuzzy matching the given coma-separated list of terms.
7272
A fuzzy match is determined by the `make_simple_name` method of the `TargetMatchManager` class.
7373
"""
74-
matching_names = []
75-
for term in value.split(','):
76-
simple_name = TargetMatchManager.make_simple_name(self, term)
77-
for target in Target.objects.all().prefetch_related('aliases'):
78-
for alias in target.names:
79-
if TargetMatchManager.make_simple_name(self, alias) == simple_name:
80-
matching_names.append(target.name)
81-
return queryset.filter(name__in=matching_names).distinct()
74+
return Target.matches.match_fuzzy_name(value, queryset).distinct()
8275

8376
cone_search = django_filters.CharFilter(method='filter_cone_search', label='Cone Search',
8477
help_text='RA, Dec, Search Radius (degrees)')

0 commit comments

Comments
 (0)