API ReferenceGE Extensionseditorutil
Search Utility
Fuzzy text search utility with scoring, frecency-based result ranking, and a searchable ImGui combo box widget.
Fuzzy text search utility with scoring, frecency-based result ranking, and a searchable ImGui combo box widget.
Class: C (returned by factory function)
| Method | Signature | Description |
|---|---|---|
C:init() | - | Sets default scoring and tie-breaking functions; frecency weight = 0.5 |
C:setScoringFunction(fun) | fun(element, match) → score | Overrides the scoring function |
C:setSameScoreResolvingFunction(fun) | fun(a, b) → bool | Overrides tie-breaking (default: alphabetical) |
C:startSearch(matchString) | matchString: string | Begins a new search pass |
C:queryElement(elem, scoringFunction) | elem: {name, ...} | Scores and potentially adds element to results |
C:finishSearch() | - | Sorts results by finalScore (score × frecency blend); returns results |
C:setFrecencyData(data) | data: {[fId] = timestamp} | Sets frecency timestamps |
C:getFrecencyData() | - | Returns current frecency data |
C:updateFrecencyEntry(fId) | fId: string | Records a selection event; supports 10s undo window |
C:getFrecencyScore(fId) | - | Returns decay score (half-life: 24h, exponent: 1.25) |
C:beginSearchableSimpleCombo(im, label, preview, elements, flags) | - | Renders a searchable combo widget; returns selected id or nil |
Static Functions
| Function | Description |
|---|---|
C.matchStringScore(name, match, ignoreEarly) | Multi-match fuzzy scorer with early-match bonus (0–1) |
Usage Example
local searchUtil = require('/lua/ge/extensions/editor/util/searchUtil')
-- Create a search instance
local search = searchUtil()
-- Simple searchable combo box in ImGui
local items = {"apple", "banana", "cherry", "date", "elderberry"}
local selected = search:beginSearchableSimpleCombo(
ui_imgui, "##fruitSearch", currentSelection, items
)
if selected then
currentSelection = selected
search:updateFrecencyEntry(selected) -- boost recently-picked items
end
-- Manual search with custom scoring
search:startSearch("ban")
for _, item in ipairs(items) do
search:queryElement({
id = item,
name = item,
frecencyId = item,
})
end
local results = search:finishSearch()
for _, r in ipairs(results) do
log("I", "", r.name .. " score=" .. r.finalScore)
end
-- matchStringScore scores multi-occurrence substring matches
-- with bonus for matches appearing early in the string
local score = searchUtil.matchStringScore("banana", "ban")
-- score ≈ 0.75 (3/6 chars matched, early match bonus)
-- Frecency: recently and frequently used items rank higher
-- Half-life is 24 hours; items decay exponentially
search:setFrecencyData({apple = os.time() - 3600}) -- 1 hour ago
local s = search:getFrecencyScore("apple") -- ~0.97See Also
- Editor Element Helper - Related reference
- Plot Helper Utility - Related reference
- Transform Utility - Related reference
- World Editor Guide - Guide
Plot Helper Utility
Interactive 2D graph/plot widget for ImGui - supports multi-series data, Catmull-Rom spline interpolation, auto-scaling, dragging, zooming, annotations, and tooltip hover.
Transform Utility
Reusable position/rotation/scale editor widget with axis gizmo integration, helper buttons (down-to-terrain, focus, move-to-camera, align-with-terrain), and shift+click quick placement.