Friday, 6 March 2015

Using a Search object in an TACTIC Expression

Another interesting feature added to 4.4 is the ability to add use a Search object as starting point for the expression language.  At present this only makes sense for server side code, so this code needs to be used on the "Python" tab on custom widgets or in server side triggers.  On server side code, TACTIC uses the Search object for all searches.  It packages up all search functionality possible in a single object.

The expression language is very convenient for doing relatively complex queries very simply.  Previous, the expression language could use a list of sobjects as a starting point.

For example:

expression = "@SUM(vfx/shot.cost)"
results = Search.eval( expression, sobjects=sobjects)

The sobjects passed in will be used as a "starting" point for the expression and evaluate the expression relative to those starting sobjects.   In this case, it will calculate the total sum of all the "cost" values for all the sobjects.

SObjects are usually built by an Search object such as:

search = Search("vfx/shot")
search.add_filter("sequence_code", "XYZ")
sobjects = search.get_sobjects()

Now if we wanted to use the resultant sobjects in an expression, we would have to do:

results = Search.eval(expression, sobjects=sobjects)

This was inefficient because it would do a search on the database, build all the sobjects and then extract information from those sobjects to operate on.  This made it impossible or inefficient to do further filters on the passed in list.

Passing in a Search object delays the search until the expression language has had a change to add extra filters.  So the above example would change to:

search = Search("vfx/shot")
search.add_filter("sequence_code", "XYZ")
results = Search.eval(expression, search=search)

If the expression contained filters, this would be much more efficient:

expression = "@SUM(vfx/shot['date_due','>','$TODAY']['date_due','<','$TOMORROW'])"

These date filters would be applied at the same time as the sequence code filters.

Since the search object is often accessible from a command or widget, this becomes a very convenient way to further operate on a search.  This is especially useful when calculate aggregate data starting from some previously selected search criteria.  More on that later.


  1. Hey! There you are! Looking for a research paper assistant? Connect with a free research paper writer for advice on this platform We have hundreds of pros to choose from, making it easy for you to get matched fast. You can view the profiles of various researchers to ensure that you find one right for your paper.

  2. Such a nice article. I was looking for this kind of unique information. I encourage you to publish more information about this article so I can gain more knowledge. Now it's time to get taxi Manchester Airport for more information.

  3. Thanks for sharing an informative blog. It was written in an simple and elegant way. The blog was really awesome and was easy to learn. So continue sharing the beautiful blogs with us.
    dui con resultado de muerte

  4. This source code is useful for tactic expression.This code is really helpful and informative for me.If you are looking to buy an online Research Proposal Help Uk service turnout to the dissertation writing help for all the academic work.

  5. Very good news is shared in this article. It is very intresting article. I suggest you to keep publishing article like these.