Source file queryArtist.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(*****************************************************************************)
(*                                                                           *)
(*  Copyright (C) 2026 Yves Ndiaye                                           *)
(*                                                                           *)
(* This Source Code Form is subject to the terms of the Mozilla Public       *)
(* License, v. 2.0. If a copy of the MPL was not distributed with this       *)
(* file, You can obtain one at https://mozilla.org/MPL/2.0/.                 *)
(*                                                                           *)
(*****************************************************************************)

include QueryUtil

(* TODO: Change the query to compute other field. *)
let matches_node _subfields artist node =
  let id = SkhcDb.Artist.id artist in
  let name = SkhcDb.Artist.name artist in
  let sort_name = SkhcDb.Artist.sort_name artist in
  let flag = SkhcDb.Artist.flag artist in
  let artwork = SkhcDb.Artist.artwork artist in
  let rating = SkhcDb.Artist.rating artist in
  match node with
  | Node.Substring s ->
      let insensible = true in
      let regex = false in
      matches ~insensible regex s name || omatches ~insensible regex s sort_name
  | Field (FString s) -> (
      let regex = Field.String.regex s in
      let insensible = Field.String.insensible s in
      let field = Field.String.key s in
      let value = Field.String.value s in
      match field with
      | SortName ->
          omatches ~insensible regex value sort_name
      | Title ->
          matches ~insensible regex value name
      | Artist ->
          matches ~insensible regex value name
      | Path ->
          matches ~insensible regex value name
      | AlbumArtist ->
          matches ~insensible regex value name
      | Composer ->
          matches ~insensible regex value name
      | Album ->
          false
      | Genre ->
          false
      | Arbitrary _ ->
          false
      | FileExtension ->
          false
    )
  | Field (FBool b) -> (
      let field = Field.Bool.key b in
      let b = Field.Bool.value b in
      match field with
      | Flag ->
          flag = b
      | Art ->
          let cover = Option.is_some artwork in
          b = cover
    )
  | Field (FInt64 i64) -> (
      let field = Field.Int64.key i64 in
      let frange = Field.Int64.value i64 in
      match field with Id -> Range.matches frange id | Size -> false
    )
  | Field (FInt i) -> (
      let field = Field.Int.key i in
      let frange = Field.Int.value i in
      match field with
      | Rating ->
          rating
          |> Option.map (Range.matches frange)
          |> Option.value ~default:false
      | Track | Year | Plays | AlbumCount | Disc | Length ->
          false
    )
  | Field (FFloat f) -> (
      let field = Field.Float.key f in
      let _frange = Field.Float.value f in
      match field with AvgDuration | AvgRating | AvgSize -> false
    )