Skip to content

Asset Searching

There are a variety of ways to search for assets in the asset library

Whatever searching method is used, it will always return a list of dictionaries. These dictionaries will be representations of sObjects on the TACTIC server of sType "workflow/asset".

There is a second type of asset which has the sType of "workflow/job_asset". These assets are assets that belong to a job. In TACTIC Project, there is a distinct separation for assets that belong to a job and the asset library. This allows for the asset library to remain a clean library of final assets that can be re-used for other purposes.

Basic searching

The "query" method is the most generic way to search for assets in the asset library.

let server = TACTIC.get()
let search_type = "workflow/asset";
let assets = server.query("workflow/asset")

Warning

This will return the entire asset library and is not recommended for large asset libraries.

Simple Filters

Most of you will want to search using simple filters. The query command has a number of arguments that will allow you to narrow your search results.

let server = TACTIC.get()
let search_type = "workflow/asset";

let filters = [
    ["timestamp", ">=", "2020-01-01"]
    ["timestamp", "<", "2020-02-01"]
];

let assets = server.query("workflow/asset", { filters: filters } );

This will return all assets that were created in the January of the year 2020.

Composite Filters

The filter data structure is a double array with each array specifying a filter. By default each filter will be combined together with "and". In order to switch this to combine using "or", you would do the following:

let filters = [
    ["begin"]
      ["asset_type", "vehicles"],
      ["asset_type", "people"],
      ["asset_type", "plants"],
    ["or"]
];

The operator at the end specifies to take the items from the "begin" item and combine them with an "or".

Note

In this simple case, this particular filter could also be done with an "in" operator.

let filters = [
    ["asset_type", "in", "vehicles|people|plants"],
];

Note

Also, in this simple case, the "begin" is implied, so you could also leave that line out.

let filters = [
    ["asset_type", "vehicles"],
    ["asset_type", "people"],
    ["asset_type", "plants"],
    ["or"]
];

TACTIC can also do more complex composite searches:

let filters = [
    ["begin"]
      ["begin"]
        ["timestamp", ">=", "2020-01-01"]
        ["timestamp", "<", "2020-02-01"]
      ["and"]
      ["begin"]
        ["timestamp", ">=", "2021-01-01"]
        ["timestamp", "<", "2021-02-01"]
      ["and"]
    ["or"]
];

This will produce the following logic

    (timestamp >= "2020-01-01" and timestamp < "2020-02-01") or
    (timestamp >= "2021-01-01" and timestamp < "2021-02-01")

Or in written form: find all the assets created in January in either 2020 or 2021.

By nesting "begin" and "or"/"and" blocks, you can create arbitrary complex filters.

Limits and offset

With large asset libraries, you often do not want to get all of the search results, but want to search them by chunks. This can be done with the limit and offset arguments

let assets = server.query("workflow/asset",
        { filters: filters },
        limit=20,
        offset=20
    );

Keywords Searching

Todo

Need to fill in the Keyword Filter capabilities

Keyword searching searches on tags that have been assigned to a specific document.

To do a keyword search on an asset, you would use the "has" operator on a filter

let filters = [
    ['keywords', 'has', 'fast|car|red']
]

You can use this filter in conjuntion with any other of the filters mentioned previously.

Using REST

To translate any of this functionality into REST calls, you can always just use the "call_tactic" method.

For example, this call:

let assets = server.query(
        "workflow/asset",
        {
            filters: filters,
            limit=20,
            offset=20
        }
    );

would convert to:

let kwargs = {
    search_type: "workflow/asset",
    filters: filters,
    limit: 20,
    offset: 20
}
let assets = call_tactic("query", kwargs);

How to query assets and snapshots

We currently need to make 2 calls to retrieve all the assets, and their associated files (snapshots in TACTIC data structure). We will first search asset using keywords filter. After getting the asset objects, we use the function, query_snapshots, to retrieve the files. See the example below:

    get_asset_info = async () => {
        let search_text = this.state.search_text // search text from the form

        // First, let's retrieve assets using the keywords search.
        let search_type = "workflow/asset"
        let filters = [
            ['keywords', 'contains', search_text]
        ]
        let kwargs = {
            search_type: search_type,
            filters: filters,
        };
        let ticket = await get_ticket()
        let sobjects = await call_tactic("query", kwargs)

        // nothing found
        if (sobjects.length <= 0) {
            this.setState({assets: []})  // set the state variable.
            return;
        }

        // We will retrieve snapshots (files) for the assets. We are going to use
        // query_snapshots function to get the relevant files that are web-accessible.
        const asset_codes = sobjects.map(element => element.code);

        let asset_codes_str = asset_codes.join("|")

        let asset_codes_filter = [
            ['search_code', 'in', asset_codes_str], ['is_latest', 'true']
        ]

        // include_web_paths_dict gives us the web-accessible paths for the files.
        kwargs = {
            include_paths_dict: true,
            include_web_paths_dict: true,
            filters: asset_codes_filter,
            order_bys: "search_code",
        }

        ticket = await get_ticket()
        let snapshots = await call_tactic("query_snapshots", kwargs)
        console.log(snapshots)

        // we will process the assets and snapshots to be returned or set
        // to the state variable.
        var res = sobjects.map(function(o, i) {
            return {
            code: o.code,
            name: o.name,
            status: o.status,
            snapshot: snapshots[i].__web_paths_dict__
            }
        })
        console.log(res)

        this.setState({assets: res}) // set the state variable.
        return;
    }