Skip to content

Commit

Permalink
Improve kv-search, when non-kv terms present
Browse files Browse the repository at this point in the history
- Just simple terms: Join them with sql wildcard (%) and apply on
  "title" field
- Just kv, keep as-is
- Both:
  - title present already: append non-kv terms to title (if spaces in
    original this could be a problem. FIXME replace them?)
  - title not present already: simply add non-kv terms %-joined to title
    field
  • Loading branch information
JOJ0 committed Jan 25, 2025
1 parent 45db6b0 commit 35f5b0b
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions discodos/ctrl/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,10 +1217,25 @@ def remove_and_delete_sales_listing(self, listing_id):

def prepare_key_value_search(self, query):
"""Returns a dictionary from space-delimited key=value pairs."""
return dict([
item.split("=") if "=" in item else ["title", item]
for item in query
])
kv = {}
non_kv = []
for item in query:
if "=" in item:
key, value = item.split("=")
kv[key] = value
else:
non_kv.append(item)

if non_kv:
if not kv:
kv = {"title": "%".join(non_kv)}
elif "title" in kv:
kv_title = kv["title"].replace(" ", "%")
non_kv_terms = "%".join(non_kv)
kv["title"] = f"{kv_title}%{non_kv_terms}"
else:
kv["title"] = "%".join(non_kv)
return kv

def tui_ls_releases(
self, search_terms, orderby=None, reverse_order=False, sales_extra=False
Expand Down

0 comments on commit 35f5b0b

Please sign in to comment.