13.2.3. Searching the EKM Repository

The DataManager interface provides a number of ways for searching the EKM repository for data. These are:

Each of these operations returns one or more instances of a ModelObject. The ModelObject is a representation of the object stored in the EKM repository.

Searching for an Object by its Path

The simplest search provided is to search for an object by its path. The examples below show this operation.

Java
DataManager dm = conn.getDataManager()
ModelObject object = dm.findByPath("/Data/Shared Data");
Python (Jython)
dm = conn.getDataManager()
object = dm.findByPath("/Data/Shared Data")
Python (IronPython)
dm = conn.GetDataManager()
object = dm.FindByPath("/Data/My Data/My Projects")
C#
DataManager dm = conn.GetDataManager()
ModelObject obj = dm.FindByPath("/Data/Shared Data");

Searching for an Object by its Unique Identifier

Each object stored in the EKM repository has a unique identifier that can also be used when searching for an object. The following shows this operation:

Java
ModelObject object = dm.findById("d23ae05b-3a07-446c-a052-1eae22ce06ec");
Python (Jython)
object = dm.findById("d23ae05b-3a07-446c-a052-1eae22ce06ec");
Python (IronPython)
object = dm.FindById("d23ae05b-3a07-446c-a052-1eae22ce06ec");
C#
ModelObject obj = dm.FindById("d23ae05b-3a07-446c-a052-1eae22ce06ec");

Searching for Objects by Keyword

Multiple objects can be located by searching the repository for objects containing specific keywords. When using this type of search, every property of every object in both the /Data/Shared Data folder and the user’s /Data/My Data folder is searched to see if they contain the keyword. For example, if searching for the keyword “test”, any object that has the keyword in its name, description, or any other property would be returned. The following code snippets show this operation and how to iterate over the results.

Java
Set<ModelObject> objects = dm.findByKeyword("test");
if (objects.size() == 0)
    System.out.println(">>>>> No objects found with keyword \"test\"");
else
    for (ModelObject obj : objects)
        System.out.println(">>>>> Object with keyword \"test\" found at " +
            obj.getPath());
Python (Jython)
objects = dm.findByKeyword("test")
if objects.size() == 0:
    print ">>>>> No objects found with keyword \"test\""
else:
    for obj in objects:
        print ">>>>> Object with keyword \"test\" found at " + obj.getPath()
Python (IronPython)
objects = dm.FindByKeyword("test")
if objects.Count == 0:
    print ">>>>> No objects found with keyword \"test\""
else:
    for obj in objects:
        print ">>>>> Object with keyword \"test\" found at " + obj.Path
C#
HashSet<ModelObject> results = dm.FindByKeyword("test");
if (results.Count == 0)
    Console.WriteLine(">>>>> No objects found with keyword \"test\"");
else
    foreach (ModelObject result in results)
        Console.WriteLine(">>>>> Object with keyword \"test\" found at " + result.Path);

Searching for Objects Using a Saved Query

EKM provides a powerful search user interface that enables users to execute very complex queries. Once complete, the user can save a query so it can be executed again at a later time. Queries are saved on the user’s Home/My Queries page or on the Administration/Shared Queries page for those queries that should be available to all users. The library provides a way to execute these saved queries. When executing one of these queries from an application, the application must specify the name of the query to execute, and whether or not the query is shared. The results of the query are processed exactly like those returned when searching using a keyword.

The following examples show this operation:

Java
// Execute a saved query in the user's "My Queries" folder.
Set<ModelObject> objects = dm.executeSavedQuery("my-query", false);
// Execute a saved query in the "Shared Queries" folder.
Set<ModelObject> objects = dm.executeSavedQuery("shared-query", true);
Python (Jython)
# Execute a saved query in the user's "My Queries" folder.
objects = dm.executeSavedQuery("my-query", False)
# Execute a saved query in the "Shared Queries" folder.
objects = dm.executeSavedQuery("shared-query", True)
Python (IronPython)
# Execute a saved query in the user's "My Queries" folder.
objects = dm.ExecuteSavedQuery("my-query", False)
# Execute a saved query in the "Shared Queries" folder.
objects = dm.ExecuteSavedQuery("my-query", True)
C#
// Execute a saved query in the user's "My Queries" folder.
HashSet<ModelObject> objects = dm.ExecuteSavedQuery("my-query", false);
// Execute a saved query in the "Shared Queries" folder.
HashSet<ModelObject> objects = dm.ExecuteSavedQuery("shared-query", true);

Searching for Objects Using a Client Created Query

You can also generate complex queries using the API. You do this by first creating a Query object and then adding QueryRow instances to the query. When creating a query object, you can specify specific object types that you want to limit the query to. For example, in Java:

Query myQuery = new Query(“WorkbenchProjectArchiveFile”);

This executes a query that searches only Workbench project archive objects. In addition, you must specify the query operation to perform. This is one of match all rows or match any rows:

QueryOperation queryOp = new QueryOperation();
queryOp.setMatch(QueryMatch.ALL);

Next, you need to add rows to the query operation. This is where you specify the actual properties and values to search:

List<QueryRow> rows = new ArrayList<QueryRow>();
QueryRow row = myQuery.createRow(“property”, Condition.EQUAL, “value”);
queryOp.setRows(rows);

You can also limit the query to a specific location in the EKM server. This is done by setting the path of the query. This path must be an actual EKM path. To do this, make sure to fix up the path prior to setting it in the query:

String path = PathUtils.fixUpPath(“/Data/My Data”, “AnEkmUsername”);
myQuery.setPath(path);

Finally, apply the operation to the query and execute it:

myQuery.setOp(queryOp);
Set<ModelObject> results = dm.findByQuery(myQuery);

Release 18.2 - © ANSYS, Inc. All rights reserved.