A library filter is a search criterion the player adds in the library's + Filter window: "MinaCalc · Stream between 18 and 25". Your mod declares which column of one of its tables the criterion reads, and the game does the search. A script never sends SQL, an expression or a function to run on each chart: it names a column, and the database does the rest on indexed rows.
This page assumes you know tables and ratings, because a filter reads a table of your mod, and only a rating's native calculation fills a table.
A complete example
This mod rates charts with MinaCalc 527 and makes the overall rating and each of the seven skillsets searchable. It also declares a radar and the pattern chips: the rating is what fills the table, and the filters read it.
/// <reference path="../../../mods/sdk/modding.d.ts" />
// MinaCalc's rating and its seven skillsets, searchable in the library. A filter reads a
// column of a table of this mod, and only a rating's native calculation fills a table: the
// rating below is what makes the filters work. Its `overall` column gets the rating, and
// the columns named after a skillset get that skillset (see the guide for the closed list).
const SKILLS = ["stream", "jumpstream", "handstream", "stamina", "jackspeed", "chordjack", "technical"];
const NAMES = ["Stream", "Jumpstream", "Handstream", "Stamina", "Jackspeed", "Chordjack", "Technical"];
const SHORTS = ["str", "js", "hs", "stam", "sj", "cj", "tech"];
export default defineMod({
id: "skillset-filters",
name: "Skillset Filters",
version: "1.0.0",
apiVersion: 2,
author: "You",
description: "MinaCalc 527 ratings and skillsets, with a radar, pattern chips and library filters.",
setup() {
const calculator = metron.catalog().calculators.find((entry) => entry.id === "etterna-515");
if (!calculator) return;
tables.register({
id: "skills_rating",
columns: [
{ name: "overall", kind: "number", indexed: true },
...SKILLS.map((name) => ({ name, kind: "number" as const, indexed: true })),
],
});
ratings.register({
id: "msd",
name: "MinaCalc · MSD",
calculator: calculator.id,
unit: "MSD",
table: "skills_rating",
column: "overall",
version: calculator.version,
// The values are divided by `scale` before the stops are read: 4.5 reads MSD on a
// ramp written in stars (blue at 1 star = 4.5 MSD, red at 5 stars = 22.5 MSD).
colors: {
scale: 4.5,
stops: [
{ at: 1, color: "#4fc0ff" },
{ at: 3, color: "#7cff4f" },
{ at: 5, color: "#ff4e6f" },
],
},
// The chart's main pattern is its highest skillset (and the second one, within 10 %).
patterns: SKILLS.map((column, index) => ({ column, label: NAMES[index], short: SHORTS[index] })),
panels: [
{
kind: "radar",
title: "Skillsets",
max: 40,
fields: SKILLS.map((column, index) => ({
label: NAMES[index],
source: { kind: "column" as const, column },
unit: "MSD",
})),
},
],
});
// One filter on the overall rating and one per skillset: `<mod id>/<filter id>` is the key.
library.filters.register({
id: "msd",
name: "MinaCalc · Overall",
table: "skills_rating",
column: "overall",
version: calculator.version,
unit: "MSD",
});
SKILLS.forEach((column, index) => {
library.filters.register({
id: `msd-${column}`,
name: `MinaCalc · ${NAMES[index]}`,
table: "skills_rating",
column,
version: calculator.version,
unit: "MSD",
});
});
ctx.on("library.ready", () => {
ratings.backfill({ id: "msd" });
});
ctx.on("library.chartsAdded", ({ chartIds, truncated }) => {
ratings.backfill(truncated ? { id: "msd" } : { id: "msd", charts: chartIds });
});
},
});
Copy the folder skillset-filters into your mods folder (Mods page, Open folder). The filter window now lists eight criteria named MinaCalc · Overall, MinaCalc · Stream, and so on; they match charts as the first calculation stores their rows. The rest of this page explains the declaration.
The declaration
library.filters.register({
id: "msd",
name: "MinaCalc · Overall",
table: "skills_rating",
column: "overall",
version: 2,
unit: "MSD",
});
| Field | Rule |
|---|---|
id |
1 to 32 characters among a-z, 0-9 and -, unique in your mod. The filter's key is <modId>/<id>. |
name |
1 to 64 characters, shown in the filter window. |
table, column |
A table already registered by this mod and one of its columns. The column's type decides the kind of filter: number or text. |
version |
An integer of at least 1: the calculation version the rows must carry. For a table fed by a rating, use the calculator's version (read it from metron.catalog()). |
unit |
Optional, at most 16 characters, no control characters. Written after the numbers. |
A mod registers at most 32 filters. library.filters.register is called from setup, after the tables.register of its table; the registry closes once the mods have loaded. Only mods register filters. A mod whose id is host cannot: host/ is the prefix of the game's own criteria.
The library publishes the whole catalogue, the host's criteria and the mods', after the mods have loaded, and withdraws a mod's filters when the mod stops, is disabled or is uninstalled.
What a filter can read
A table is filled only by a rating's native calculation. So a filter is useful on:
- the main column of a rating's table (stars, MSD);
- for
etterna-515andprismcalc-1, the columns named after the seven skillsets in the same table:stream,jumpstream,handstream,stamina,jackspeed,chordjack,technical.
No calculation fills a text column, so a filter on one never matches anything. Use number columns, and set indexed: true on the columns you filter on so the database can use an index.
A row counts only if it is current. The search keeps a chart when its row has the filter's version, was calculated from the chart file as it is now (same stamp and size) and holds no error. A missing value, a failed calculation and a stale row never match, not even a bound of 0.
The host's criteria
The catalogue also holds the game's neutral criteria, keyed host/<id>. They are the same query language as yours.
| Key | Kind | Reads |
|---|---|---|
host/keys |
number | Key count |
host/bpmMin, host/bpmMax |
number | Minimum and maximum BPM |
host/duration |
number | Duration, in seconds |
host/averageNps, host/peakNps |
number | Average and peak density |
host/notes, host/holds |
number | Notes and holds |
host/title, host/artist |
text | Title and artist, original or romanised |
host/creator, host/difficulty |
text | Mapper and difficulty name |
host/tag, host/note |
text | The player's own tags and note on a map |
host/goals, host/goalsReached, host/goalsOpen |
number | Goals on a chart |
The query the library sends
The interface sends a typed LibraryQuery; your filters never see it, but its rules explain what a filter does.
| Part | Rule |
|---|---|
text |
Free words, at most 512 characters. Each word is a literal substring of the title, artist, mapper, difficulty or the player's note. |
filters |
At most 16 clauses { key, value }. A key has at most 256 bytes and no control character. |
| number clause | { kind: "number", min?, max? }: at least one finite bound, both inclusive, min <= max. Signed decimals are accepted, with no rounding. |
| text clause | { kind: "text", value, exact }: 1 to 256 characters once the outer spaces are removed. exact asks for equality (letter case ignored), otherwise for a literal substring. |
The free words and all the clauses combine with AND on the same chart, never across the difficulties of a folder. A page holds at most 80 sets and lists only the difficulties that match; the count, the page and the position of the open folder come from one snapshot. A filter that is not available (an unknown key, a mod that stopped) is an error (unavailable library filter: pvng.ratings/etterna-515), never a condition dropped in silence. Every value is bound as an SQLite parameter.
What you will see
A mistake in the declaration throws in setup:
| Message | Cause |
|---|---|
filter id must be 1 to 32 characters among a-z, 0-9 and -, got "../host" |
An invalid id. |
filter name must have 1 to 64 characters, got " " |
An empty or long name. |
filter unit must have at most 16 characters and no control characters |
A bad unit. |
filter version must be positive |
version: 0. |
filter table is not registered by this mod |
table is not one of your registered tables. |
filter must reference a registered column of its mod |
column is not a column of that table. |
filter id is registered twice |
The same id twice. |
a mod registers at most 32 library filters |
The thirty-third filter. |
host is reserved for neutral library filters |
A mod whose id is host. |
library.filters.register is only available in a mod's setup |
Called later. |
only mods register library filters |
Called by a skin or a map script. |
Pitfalls
- A filter with no rating that fills its table: it registers, and matches nothing.
- A
versionthat differs from the one the rating writes: every row is stale, and nothing matches. - A filter on a column the calculator does not fill (a skillset column on
quaver-2025): the rows hold no value. - Forgetting
indexed: trueon a column you search: it works, more slowly on a large library. - Registering a filter from an event handler: the registry is closed.
See also
library.filters.registerin the SDK reference.- Add a difficulty rating: the tables, calculators and
ratings.backfilla filter depends on.