rocksky/filter

Pipe-friendly builder for RSQL filter expressions, accepted by the filter parameter of the catalog and scrobble-feed queries (app.rocksky.song.getSongs, app.rocksky.artist.getArtists, app.rocksky.album.getAlbums, app.rocksky.scrobble.getScrobbles).

Fields are typed (Fieldfilter.Artist, filter.Duration, dotted scrobble selectors like filter.TrackArtist, and a CustomField("…") escape hatch), and the filter value is always the first argument of the combinators, so expressions chain with |>:

filter.eq(filter.Artist, “Daft Punk”) |> filter.and(filter.gt(filter.Duration, 200_000)) |> filter.or(filter.in_list(filter.Genre, [“house”, “electro”])) |> filter.build // artist==“Daft Punk”;duration=gt=200000,genre=in=(house,electro)

String values are quoted and escaped automatically when they contain characters RSQL reserves; * wildcards pass through unquoted so filter.eq(filter.Artist, "Daft*") performs a case-insensitive match.

Types

A filterable field — the union of the known fields of the four RSQL-filterable queries (songs, artists, albums, scrobbles). The dotted Track* / User* / Artist* variants are the scrobble feed’s joined selectors. Any selector not covered here can be reached with CustomField.

pub type Field {
  Title
  Artist
  Album
  AlbumArtist
  Genre
  Genres
  Composer
  Label
  Duration
  TrackNumber
  DiscNumber
  MbId
  Isrc
  Sha256
  Uri
  AlbumUri
  ArtistUri
  CreatedAt
  Name
  BornIn
  Born
  Died
  Year
  ReleaseDate
  Date
  Timestamp
  TrackTitle
  TrackArtist
  TrackAlbum
  TrackAlbumArtist
  TrackGenre
  TrackDuration
  TrackIsrc
  TrackMbId
  UserDid
  UserHandle
  UserDisplayName
  ArtistName
  ArtistGenres
  CustomField(String)
}

Constructors

  • Title

    title

  • Artist

    artist

  • Album

    album

  • AlbumArtist

    albumArtist

  • Genre

    genre

  • Genres

    genres (artists)

  • Composer

    composer

  • Label

    label

  • Duration

    duration

  • TrackNumber

    trackNumber

  • DiscNumber

    discNumber

  • MbId

    mbId

  • Isrc

    isrc

  • Sha256

    sha256

  • Uri

    uri

  • AlbumUri

    albumUri

  • ArtistUri

    artistUri

  • CreatedAt

    createdAt

  • Name

    name (artists)

  • BornIn

    bornIn (artists)

  • Born

    born (artists)

  • Died

    died (artists)

  • Year

    year (albums)

  • ReleaseDate

    releaseDate (albums)

  • Date

    date (scrobbles)

  • Timestamp

    timestamp (scrobbles)

  • TrackTitle

    track.title (scrobbles)

  • TrackArtist

    track.artist (scrobbles)

  • TrackAlbum

    track.album (scrobbles)

  • TrackAlbumArtist

    track.albumArtist (scrobbles)

  • TrackGenre

    track.genre (scrobbles)

  • TrackDuration

    track.duration (scrobbles)

  • TrackIsrc

    track.isrc (scrobbles)

  • TrackMbId

    track.mbId (scrobbles)

  • UserDid

    user.did (scrobbles)

  • UserHandle

    user.handle (scrobbles)

  • UserDisplayName

    user.displayName (scrobbles)

  • ArtistName

    artist.name (scrobbles)

  • ArtistGenres

    artist.genres (scrobbles)

  • CustomField(String)

    Escape hatch: any selector not covered above, passed through verbatim.

One RSQL expression node. Build leaves with the comparison constructors (eq, gt, in_list, …), combine them with and / or, and render with build.

pub opaque type Filter

Values

pub fn and(a: Filter, b: Filter) -> Filter

Both sides must match (;). An or operand is parenthesized to keep RSQL precedence: a |> filter.and(b).

pub fn build(f: Filter) -> String

The RSQL expression string to send as the filter query param.

pub fn eq(field: Field, value: String) -> Filter

field==value — equals; * in the value is a wildcard.

pub fn eq_bool(field: Field, value: Bool) -> Filter

field==true / field==false — equals, boolean value.

pub fn eq_int(field: Field, value: Int) -> Filter

field==value — equals, integer value.

pub fn ge(field: Field, value: Int) -> Filter

field=ge=value — greater than or equal.

pub fn gt(field: Field, value: Int) -> Filter

field=gt=value — greater than.

pub fn in_list(field: Field, values: List(String)) -> Filter

field=in=(a,b) — matches any of the values.

Panics when values is empty — an RSQL in needs at least one value.

pub fn is_not_null(field: Field) -> Filter

field!=null — the field is not NULL.

pub fn is_null(field: Field) -> Filter

field==null — the field is NULL.

pub fn le(field: Field, value: Int) -> Filter

field=le=value — less than or equal.

pub fn lt(field: Field, value: Int) -> Filter

field=lt=value — less than.

pub fn ne(field: Field, value: String) -> Filter

field!=value — not equals.

pub fn ne_bool(field: Field, value: Bool) -> Filter

field!=true / field!=false — not equals, boolean value.

pub fn ne_int(field: Field, value: Int) -> Filter

field!=value — not equals, integer value.

pub fn or(a: Filter, b: Filter) -> Filter

Either side may match (,): a |> filter.or(b).

pub fn out_list(field: Field, values: List(String)) -> Filter

field=out=(a,b) — matches none of the values.

Panics when values is empty — an RSQL out needs at least one value.

Search Document