Btw, I’ve learned now that it is not necessary to use a DynamicOptionsProvider for sections. It’s also possible to return an ItemCollection for the regular EntityQuery.
When doing so, you need to return item collections for all returning functions except the entities(for identifiers: [UUID]) function.
struct MyIntentQuery: EntityStringQuery {
func entities(for identifiers: [UUID]) async throws -> [MyIntentEntity] {
// Return fetched entities by ID
}
func suggestedEntities() async throws -> ItemCollection<MyIntentEntity> {
// Get All Data
let allData = try IntentsDataHandler.shared.getEntities()
// Create Arrays for Sections
let fooEntities = allData.filter { $0.type == .foo }
let barEntities = allData.filter { $0.type == .bar }
return ItemCollection(sections: [
ItemSection("Foo",
items: fooEntities),
ItemSection("Bar",
items: barEntities)
])
}
func entities(matching string: String) async throws -> ItemCollection<MyIntentEntity> {
// Get All Data
let allData = try IntentsDataHandler.shared.getEntities()
// Create Arrays for Sections
let fooEntities = allData.filter {
$0.type == .foo &&
$0.title.localizedCaseInsensitiveContains(string))
}
let barEntities = allData.filter {
$0.type == .bar &&
$0.title.localizedCaseInsensitiveContains(string))
}
return ItemCollection(sections: [
ItemSection("Foo",
items: fooEntities),
ItemSection("Bar",
items: barEntities)
])
}
}
Topic:
Machine Learning & AI
SubTopic:
General
Tags: