MCPcopy
hub / github.com/beetbox/beets / parse_query_parts

Function parse_query_parts

beets/library/queries.py:14–43  ·  view source on GitHub ↗

Given a beets query string as a list of components, return the `Query` and `Sort` they represent. Like `dbcore.parse_sorted_query`, with beets query prefixes and ensuring that implicit path queries are made explicit with 'path:: '

(parts, model_cls)

Source from the content-addressed store, hash-verified

12
13
14def parse_query_parts(parts, model_cls):
15 """Given a beets query string as a list of components, return the
16 `Query` and `Sort` they represent.
17
18 Like `dbcore.parse_sorted_query`, with beets query prefixes and
19 ensuring that implicit path queries are made explicit with 'path::<query>'
20 """
21 # Get query types and their prefix characters.
22 prefixes = {
23 ":": dbcore.query.RegexpQuery,
24 "=~": dbcore.query.StringQuery,
25 "=": dbcore.query.MatchQuery,
26 }
27 prefixes.update(plugins.queries())
28
29 # Special-case path-like queries, which are non-field queries
30 # containing path separators (/).
31 parts = [
32 f"path:{s}" if dbcore.query.PathQuery.is_path_query(s) else s
33 for s in parts
34 ]
35
36 case_insensitive = beets.config["sort_case_insensitive"].get(bool)
37
38 query, sort = dbcore.parse_sorted_query(
39 model_cls, parts, prefixes, case_insensitive
40 )
41 log.debug("Parsed query: {!r}", query)
42 log.debug("Parsed sort: {!r}", sort)
43 return query, sort
44
45
46def parse_query_string(s, model_cls):

Callers 2

parse_query_stringFunction · 0.85
_fetchMethod · 0.85

Calls 5

is_path_queryMethod · 0.80
updateMethod · 0.45
queriesMethod · 0.45
getMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected