Skip to content

Commit

Permalink
Merge pull request #325 from jwjacobson/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jwjacobson authored Sep 27, 2024
2 parents 509a5db + 6cf985c commit 58b3ceb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 34 deletions.
12 changes: 1 addition & 11 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.contrib.messages.storage.fallback import FallbackStorage
from django.http import HttpRequest

from tune.search import query_tunes, return_search_results, exclude_term, search_field
from tune.search import query_tunes, return_search_results, search_field


@pytest.fixture
Expand Down Expand Up @@ -407,16 +407,6 @@ def test_return_search_results_too_many(request_fixture, tune_set, search_form_f
)


def test_exclude_term(tune_set):
excluded_term = "-kern"
result = exclude_term(tune_set["tunes"], excluded_term)

assert result.count() == 7
for tune in result:
assert tune.tune.composer != "Kern"
assert "kern" not in tune.tune.title.lower()


def test_search_field_title(tune_set):
field = "title"
term = "you"
Expand Down
24 changes: 1 addition & 23 deletions tune/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,6 @@ def search_field(tune_set, field, term):
return Q(**{f"tune__{field}__icontains": term})


def exclude_term(tune_set, search_term):
"""
Exclude a term from a search.
"""
excluded_term = search_term[1:]

term_query = tune_set.exclude(
Q(tune__title__icontains=excluded_term)
| Q(tune__composer__icontains=excluded_term)
| Q(tune__key__icontains=excluded_term)
| Q(tune__other_keys__icontains=excluded_term)
| Q(tune__song_form__icontains=excluded_term)
| Q(tune__style__icontains=excluded_term)
| Q(tune__meter__icontains=excluded_term)
| Q(tune__year__icontains=excluded_term)
| Q(knowledge__icontains=excluded_term)
| Q(tags__name__icontains=excluded_term)
)

return term_query


def nickname_search(tune_set, search_term):
"""
Search for a composer by their nickname.
Expand Down Expand Up @@ -112,7 +90,7 @@ def query_tunes(tune_set, search_terms, timespan=None):
if timespan is not None:
tune_set = tune_set.exclude(last_played__gte=timespan)

return tune_set
return tune_set.distinct()


def return_search_results(request, search_terms, tunes, search_form, timespan=None):
Expand Down

0 comments on commit 58b3ceb

Please sign in to comment.