Search api - combine "in" and "contains" predicates

Ran into an interesting problem today - I would like to search for partial matches of a list of items. This would be a combination of the predicates “in” and “contains”.

For instance find_one("PublishedFile", [["created_by.HumanUser.login", "in", ["schwartz", "term"]]])

I understand I can achieve this with compound filters like

{ "filter_operator": "any",
  "filters": [
    ["created_by.HumanUser.login", "contains", "schwartz"],
    ["created_by.HumanUser.login", "contains", "term"]]}

just wondering if there is a shortcut for this.

Any ideas?

1 Like

As mentioned - I think the best way to handle this case is with the compound filters.

From my experience it’s best to limit the use of contains as much as possible due to inefficiencies of that operator.

First getting a list of find("PublishedFile", filters, ["created_by.HumanUser.login"])
Then relying on your scripting language to perform the fuzzy logic on the return fields to identify the first item / sub-set matching your needs may help save SG from itself.

Hm, is this indeed the case? I would expect server-side filtering to be faster in general. You may be greatly limiting the amount of data that needs to flow.
But then again, you cannot say these things without profiling them :slightly_smiling_face:
I’ll try to put together a test. This would also depend a lot on the data, so it would be nice to test out different data profiles.