2025-01-17 17:41:02 +08:00
|
|
|
The `index` API provides functions for interacting with SilverBullet's [[Objects]], allowing you to store and query page-associated data.
|
|
|
|
|
|
|
|
## Object Operations
|
|
|
|
|
2025-01-19 21:32:11 +08:00
|
|
|
## index.tag(name)
|
|
|
|
Returns a given [[Objects#Tags]] as a query collection, to be queried using [[Space Lua/Lua Integrated Query]].
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
${query[[from index.tag("page") limit 1]]}
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## index.indexObjects(page, objects)
|
2025-01-17 17:41:02 +08:00
|
|
|
Indexes an array of objects for a specific page.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
|
|
|
local objects = {
|
|
|
|
{tag = "mytask", ref="task1", content = "Buy groceries"},
|
|
|
|
{tag = "mytask", ref="task2", content = "Write docs"}
|
|
|
|
}
|
2025-02-06 17:04:45 +08:00
|
|
|
index.indexObjects("my page", objects)
|
2025-01-17 17:41:02 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## index.queryLuaObjects(tag, query, scopedVariables?)
|
2025-01-17 17:41:02 +08:00
|
|
|
Queries objects using a Lua-based collection query.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local tasks = index.queryLuaObjects("mytask", {limit=3})
|
2025-01-17 17:41:02 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## index.getObjectByRef(page, tag, ref)
|
2025-01-17 17:41:02 +08:00
|
|
|
Retrieves a specific object by its reference.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local task = index.getObjectByRef("my page", "mytask", "task1")
|
2025-01-17 17:41:02 +08:00
|
|
|
if task then
|
|
|
|
print("Found task: " .. task.content)
|
|
|
|
end
|