You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently when the dsc ls receives search_terms it separates fields and values by looking for =
The CLI handler (Click 8.x framework) is configured to accept any number of arguments and does NOT require them to be surrounded by quotes. It receives any args that are not part of an option already, as a tuple. E.g this is valid:
dsc ls --order-by price --reverse --limit 10 word1 word2 word3
and the tuple will look like this:
("word1", "word2" "word3"). It's passed to the command function in a variable called search_terms
There is one special case handled that grabs all parts of the search_terms that are standalone, for example album name (no =) and creates a title=%album%name% out of that to be successfully be parsed by furhter processing that require a field name to work.
Feature suggestion
There is a caveat with this solution an SQL select containing LIKE album_title = "%album%name" would find an album named "album name" but not one named "name album".
This could be improved by producing an SQL select that looks similar to this: LIKE album_title = "%album%" AND album_title = "%name%"
That way, also a release titled "name album" would be found.
Also, this change would pave the way for handling additional - let,s call them - auto-search fields, for example artist and catalog number
The first step in improving all this as pointed out in Feature suggestion would be to refactor prepare_key_value_search() to produce a dictionary like this::
That way the database query function receiving the dictionary could easily interpret this to handle the titlelist as AND-concatenated SQL select parts.
The text was updated successfully, but these errors were encountered:
JOJ0
changed the title
Improve key-value-searching title field when no field= option is given
Improve key-value-searching title field when no title= argument is given
Feb 21, 2025
- Approaches issue #36 from a different angle
- Three default search fields: artist, title, cat(alog number)
- Combining of standalone keywords and key-value pairs throws a warning
and simply ignores all standalone terms.
Current implementation details
Currently when the
dsc ls
receivessearch_terms
it separates fields and values by looking for=
The CLI handler (Click 8.x framework) is configured to accept any number of arguments and does NOT require them to be surrounded by quotes. It receives any args that are not part of an option already, as a tuple. E.g this is valid:
dsc ls --order-by price --reverse --limit 10 word1 word2 word3
and the tuple will look like this:
("word1", "word2" "word3")
. It's passed to the command function in a variable calledsearch_terms
There is one special case handled that grabs all parts of the
search_terms
that are standalone, for examplealbum name
(no=
) and creates atitle=%album%name%
out of that to be successfully be parsed by furhter processing that require a field name to work.Feature suggestion
There is a caveat with this solution an SQL select containing
LIKE album_title = "%album%name"
would find an album named "album name" but not one named "name album".This could be improved by producing an SQL select that looks similar to this:
LIKE album_title = "%album%" AND album_title = "%name%"
That way, also a release titled "name album" would be found.
Also, this change would pave the way for handling additional - let,s call them - auto-search fields, for example artist and catalog number
Relevant code parts (current implementation)
CLI level
discodos/discodos/cmd23/ls.py
Line 16 in 9740f83
discodos/discodos/cmd23/ls.py
Lines 30 to 31 in 9740f83
discodos/discodos/cmd23/ls.py
Lines 51 to 54 in 9740f83
Happening here is: Separating keys and values by delimiter
=
and enriching standalone arguments with akey
, currently hardcoded totitle
:discodos/discodos/ctrl/collection.py
Lines 1224 to 1244 in 9740f83
The final result for a query like this:
dsc ls word1 status=draft word2 word3
is a dictionary (
kv
) that looks like this:which is then finally passed to the controller level:
discodos/discodos/cmd23/ls.py
Lines 56 to 62 in 9740f83
Controller level
a proper key/value dictionary is expected here:
discodos/discodos/ctrl/collection.py
Lines 1246 to 1249 in 9740f83
Model/Database abstraction level
discodos/discodos/model/collection.py
Lines 840 to 843 in 9740f83
Proposed solution
The first step in improving all this as pointed out in Feature suggestion would be to refactor
prepare_key_value_search()
to produce a dictionary like this::That way the database query function receiving the dictionary could easily interpret this to handle the
title
list asAND
-concatenated SQL select parts.The text was updated successfully, but these errors were encountered: