The following suggest function would do what you're asking for - matching either on exact country id or on country name. As a bonus, a user would be able to type multiple parts of a country's name separated by a space and get results that have some match for all typed parts. Thanks to the flexibility of the a!queryLogicalExpression() construct (with the ability to nest and loop to basically any extent you could possibly want), we have a lot of flexibility with what search results are achievable, this being just one of a multitude of different possibilities.
a!localVariables(
local!searchTextParts: a!forEach(
split(ri!searchText, " "),
if(rule!PROJECT_RULE_isBlank(fv!item), {}, fv!item)
),
local!query: a!queryEntity(
entity: cons!PROJECT_ENTITY_VIEW_COUNTRY_PICKER, /* DSE constant pointing to your countries table or view */
query: a!query(
logicalExpression: a!queryLogicalExpression(
operator: "AND",
filters: {
a!queryFilter(
field: "countryId",
operator: "not null"
)
},
logicalExpressions: {
a!queryLogicalExpression(
operator: "AND",
logicalExpressions: a!forEach(
local!searchTextParts,
a!queryLogicalExpression(
operator: "OR",
filters: {
a!queryFilter(
field: "countryId",
operator: "=",
value: fv!item,
applyWhen: not(rule!PROJECT_RULE_isBlank(tointeger(fv!item)))
),
a!queryFilter(
field: "countryName",
/* OPERATOR can be either "starts with" or "includes" depending on your preference and/or project requirements */
operator: "includes",
value: tostring(fv!item)
)
}
)
)
)
}
),
pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: 20,
sort: a!sortInfo(
field: "countryId",
ascending: true()
)
)
)
),
a!dataSubset(
data: a!forEach(
local!query.data,
rule!PROJECT_Format_countryPickerLabel(country: fv!item) /* this rule would accept the Country CDT and return a single line of text representing how the Country name (and other details if desired) will appear in suggestion results as well as in the selected items list in the parent rule */
),
identifiers: property(local!query.data, "countryId", {})
)
)