algorithm-dsl-functions
Algorithm DSL Functions
Algorithm DSL functions build the search-and-hydration flow that Console runs and previews.
Setup
import { StudioV1 } from "algo-dsl";
const mbd = new StudioV1({ apiKey });StudioV1 creates a client for the current Studio API surface.
.search()
.search()Starts a search query.
const query = mbd.search();.index(name)
.index(name)Chooses the Console-supported index to search.
mbd.search().index("polymarket-items");.include()
.include()Hydrates search hits with fields from the matched records. Most feed and notification algorithms should call .include() before returning rows.
mbd.search().index("token-items").include();Filter functions
Use filters to narrow candidates before output.
| Function | Meaning | Example |
|---|---|---|
.term(field, value) | Exact field match | .term("status", "active") |
.terms(field, values) | Match any value from a list | .terms("chain", ["ethereum", "base"]) |
.match(field, value) | Text-style match | .match("question", "bitcoin") |
.numeric(field, value) | Numeric lower-bound filter | .numeric("volume_24hr", 1000) |
.date(field, value) | Date/time filter | .date("timestamp", "now-7d") |
.geo(field, value) | Geographic filter | .geo("location", "geo:40.7,-74.0") |
.isNull(field) | Keep rows where a field is missing/null | .isNull("closed_at") |
.notNull(field) | Keep rows where a field exists | .notNull("question") |
.consoleAccount(field, value) | Account-scoped filter | .consoleAccount("account_id", "acct_123") |
.custom(field, value) | Custom field/value filter | .custom("segment", "power_user") |
.sortBy(field, direction)
.sortBy(field, direction)Sorts results before output.
.sortBy("volume_24hr", "desc").size(n)
.size(n)Limits the number of returned rows.
.size(25).execute()
.execute()Runs the query and returns hydrated rows.
const rows = await mbd
.search()
.index("polymarket-items")
.include()
.numeric("volume_24hr", 1000)
.sortBy("volume_24hr", "desc")
.size(25)
.execute();.frequentValues(field, n)
.frequentValues(field, n)Fetches common values for a field so you can choose valid filters.
const tags = await mbd
.search()
.index("polymarket-items")
.frequentValues("tags", 25);Full feed algorithm
import { StudioV1 } from "algo-dsl";
export default async function algo({ apiKey }) {
const mbd = new StudioV1({ apiKey });
return mbd
.search()
.index("polymarket-items")
.include()
.numeric("volume_24hr", 1000)
.notNull("question")
.sortBy("volume_24hr", "desc")
.size(25)
.execute();
}
