Hey, was wondering if it is possible to apply a like filter to match any text from a property that is a text array?
For example, here we filter so that the “answer” (text type) must match *inter*.
jeopardy = client.collections.get("JeopardyQuestion")
response = jeopardy.query.fetch_objects(
filters=Filter.by_property("answer").like("\*inter*"),
limit=3
)
But say that each object had multiple answers, stored in in a TEXT ARRAY called “answers”. How could we then filter to only include objects where any of the texts in “answers” match like *inter*?
So what I’m asking, is it possible use a like filter to match any in strings from a TEXT ARRAY property?
hi @ReverseHobo !
I believe this is what you are asking:
collection.data.insert({"text": "this is a test", "array": ["one", "two", "three"]})
collection.data.insert({"text": "this one test", "array": ["four", "five", "six"]})
# now we filter with like, or equal
collection.query.fetch_objects(
filters=wvc.query.Filter.by_property("array").like("*ive")
).objects
collection.query.fetch_objects(
filters=wvc.query.Filter.by_property("array").equal("four")
).objects
This is because everything will become a token. So you are not matching against a field (unless you specify the tokenization to field, more on tokenization here), but against tokens.
Let me know if this clarifies it.
Thanks!