0

Matching Any and All Filter Operations

I need to make a complex API filter that need to match both "Any" and "All" filter operations.  Lately I have been doing one or the other like this.

shotFilter = []
for shot in shotList :
     shotFilter = shotFilter + [['name', 'contains', shot ]]

shotData = sg.find("shot",
     filters= shotFilter,
     fields=['all' ],
     filter_operator='any',
)

Is it possible to provide multiple Filter operations for specific filters.  The UI supports this by allowing you to match a bunch of filters via "Any" and another group of fields by "All".  Can you guys show me an example of a filter that matches a group via "Any" as well as "All".

-Romey

11件のコメント

  • 0
    Avatar
    Isaac Reuben

    Hey Romey,
    Grouping of filters with different operators is something we're working on for api3.  Coming soon!

    - Isaac

  • 0
    Avatar
    Asi Sudai

    hey Isacc,

     

    I was wondering if this complex-filter-search is available now?

    I'm looking at the API3 3.05 code, but looks like it's still all/any.

    can we code this in the API3 or it's a server side too?

    thanks

  • 0
    Avatar
    Jake Wilson

    It doesn't appear to be documented at all, but I figured out how to get these nested conditionals to work for search filters

     

     

    # Fields to Return
    fields = ['id', 'code', 'sg_status_list']
    # Condition Group 1
    condition_1_1 = { 'path' : 'sg_status_list' , 'relation' : 'is', 'values' : ['hld'] }
    condition_group_1 = { 'logical_operator' : 'and' , 'conditions' : [cond_1_1] }
    # Condition Group 2
    condition_2_1 = { 'path' : "sg_status_list" , 'relation' : "is" , 'values' : ["ip"] }
    condition_2_2 = { 'path' : "code" , 'relation' : 'contains' , 'values' : ["shot"] }
    condition_2_3 = { 'path' : 'code' , 'relation' : 'contains' , 'values' : ['Test'] }
    condition_group_2 = { 'logical_operator' : 'and' , 'conditions' : [ cond_2_1 , cond_2_2, cond_2_3 ] }
    # Adding the Groups together using 'or'
    filters = { 'logical_operator' : 'or' , 'conditions' : [ condition_group_1, condition_group_2 ] }
    # Running the find
    shots = sg.find('Shot',filters,fields)

    # Fields to Returnfields = ['id', 'code', 'sg_status_list']


    # Condition Group 1

    condition_1_1 = { 'path' : 'sg_status_list' , 'relation' : 'is', 'values' : ['hld'] }

    condition_group_1 = { 'logical_operator' : 'and' , 'conditions' : [cond_1_1] }


    # Condition Group 2

    condition_2_1 = { 'path' : "sg_status_list" , 'relation' : "is" , 'values' : ["ip"] }

    condition_2_2 = { 'path' : "code" , 'relation' : 'contains' , 'values' : ["shot"] }

    condition_2_3 = { 'path' : 'code' , 'relation' : 'contains' , 'values' : ['Test'] }

    condition_group_2 = { 'logical_operator' : 'and' , 'conditions' : [ cond_2_1 , cond_2_2, cond_2_3 ] }

    # Adding the Groups together using 'or'

    filters = { 'logical_operator' : 'or' , 'conditions' : [ condition_group_1, condition_group_2 ] }

    # Running the find

    shots = sg.find('Shot',filters,fields)

     

  • 0
    Avatar
    Jake Wilson

    Sorry, the formatting on that last post got messed up and it doesn't appear that I'm able to edit it.  Look here instead:

     

    http://codepad.org/VEC2FBSk

  • 0
    Avatar
    Asi Sudai

    Sweet, thank you very much, Jake.

    works great

  • 0
    Avatar
    Flavio Perez

    Very useful piece of code ! Thanks !

  • 0
    Avatar
    Paul Hudson

    Wow, a little late to the party, but THANK YOU Jake.

    Is this in the official docs anywhere?!  If not, it really, really, really needs to be.  Thinking that filter_operator= "any" or "all" are the only options available is truly crippling!

  • 0
    Avatar
    katisss

    hi,
    after changing line 12 (using api version 3.08)  to
    condition_group_2 = { 'logical_operator' : 'and' , 'conditions' : [ condition_2_1 , condition_2_2, condition_2_3  ] }
    i get

        shots = SGO.find('Shot',filters,fields)
      File "/usr/net/bss/pe/shotgunTools/0.65/python/bssShotgun/framework/__init__.py", line 154, in find
        result  = self._INTERNAL_SHOTGUN_API.find(entity_type=entity_type,filters=filters,fields=fields,*args,**kwargs)
      File "/usr/net/bss/pe/shotgunTools/0.65/python/shotgunTools/api3/shotgun.py", line 412, in find
        result = self._call_rpc("read", params)
      File "/usr/net/bss/pe/shotgunTools/0.65/python/shotgunTools/api3/shotgun.py", line 928, in _call_rpc
        self._response_errors(response)
      File "/usr/net/bss/pe/shotgunTools/0.65/python/shotgunTools/api3/shotgun.py", line 1110, in _response_errors
        "Unknown Error"))
    Fault: API read() Shot.c doesn't exist:
    {"relation"=>"o",
     "values"=>["n", "d", "i", "t", "i", "o", "n", "s"],
     "path"=>"c"}

  • 0
    Avatar
    katisss

    Never mind, the problem is with the custom wrapper here. If i dont use it it is working

  • 0
    Avatar
    KP

    This isn't in our docs because technically we're not supporting it at the moment. The syntax above is pretty nasty. We have been designing a nicer version of it that is closer to the current simple filter syntax which we're hoping to push out sometime soon. We don't have imminent plans to remove the ugly syntax support but since it's undocumented, we can't promise that it won't disappear sometime. Don't break out in cold sweats though... if we do anything like that there will be a lot of fair warning.

  • 0
    Avatar
    katisss

    Querying the database several times for what can be a single query feels a lot worse to me.

ログインしてコメントを残してください。