Skip to content

Commit

Permalink
Change the prefix for exact match queries
Browse files Browse the repository at this point in the history
PR beetbox#4251 added exact match queries, which are great, but it was
subsequently pointed out that the `~` query prefix was already in use:
beetbox#4251 (comment)

So this changes the prefix from `~` to `=~`. A little longer, but
hopefully it makes the relationship to the similarly-new `=` prefix obvious.

# Conflicts:
#	docs/changelog.rst
  • Loading branch information
JOJ0 committed Oct 15, 2022
1 parent 0a2b8b4 commit ed72653
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ def parse_query_parts(parts, model_cls):
# Get query types and their prefix characters.
prefixes = {
':': dbcore.query.RegexpQuery,
'~': dbcore.query.StringQuery,
'=~': dbcore.query.StringQuery,
'=': dbcore.query.MatchQuery,
}
prefixes.update(plugins.queries())
Expand Down
14 changes: 8 additions & 6 deletions docs/reference/query.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,17 @@ backslashes are not part of beets' syntax; I'm just using the escaping
functionality of my shell (bash or zsh, for instance) to pass ``the rebel`` as a
single argument instead of two.

.. _exact-match:

Exact Matches
-------------

While ordinary queries perform *substring* matches, beets can also match whole
strings by adding either ``=`` (case-sensitive) or ``~`` (ignore case) after the
field name's colon and before the expression::
strings by adding either ``=`` (case-sensitive) or ``=~`` (ignore case) after
the field name's colon and before the expression::

$ beet list artist:air
$ beet list artist:~air
$ beet list artist:=~air
$ beet list artist:=AIR

The first query is a simple substring one that returns tracks by Air, AIR, and
Expand All @@ -112,16 +114,16 @@ returns tracks by AIR only.

Exact matches may be performed on phrases as well::

$ beet list artist:~"dave matthews"
$ beet list artist:=~"dave matthews"
$ beet list artist:="Dave Matthews"

Both of these queries return tracks by Dave Matthews, but not by Dave Matthews
Band.

To search for exact matches across *all* fields, just prefix the expression with
a single ``=`` or ``~``::
a single ``=`` or ``=~``::

$ beet list ~crash
$ beet list =~crash
$ beet list ="American Football"

.. _regex:
Expand Down

0 comments on commit ed72653

Please sign in to comment.