I came across the transform property for the Term object when creating an index from this topic.
I used it and it works as expected. But I noticed that this property is not documented anywhere for the Term object.
I raise this here just in case this omission in the docs is intentional because there is a better/alternative way to go about applying transformations on a term field when querying an index.
For my particular use case, as an example, I want matches for terms to be case-insensitive.
Is this something I should be doing purely in my index query as apposed to defining this on the index when creating it?
The transform field is deprecated. It was the precursor to Index Bindings, which is what you should use, now. The transform parameter allowed you to apply a single function a single field, but bindings let you calculate an arbitrarily complex, pure calculation on a whole Document.
In the shared example post, the OP uses transform: casefold. You can accomplish that using a binding like this:
CreateIndex({
name: "MyIndex",
// source object
source: {
collection: Collection("things"),
// define bindings:
fields: {
case_insensitive: Query(Lambda(
"doc", // each binding receives the Document as an argument
Let(
{
// pick out the value you want to search by
value: Select(["data", "value"], Var("doc"))
},
Casefold(Var("value")) // and normalize it
)
))
}
},
terms: [
// call out the binding as a term
{ binding: "case_insensitive" }
],
values: [
// whatever you need values to be
]
})
Just wanted to ask one more thing regarding this: if I need to normalise multiple terms, then my understanding is that I have to define a new binding for each, like so:
No. What you’ve done there is the right way to have multiple bindings.
This is an excellent example and great feedback, though! I’ve brought it up with our Product team to see if there’s anything we can consider doing about it.