LiveLink – Search Facility

This is quite strangely. I can see the power of it though, so semi understand why its been done this way. But it does mean jumping through hops in order to retrieve results.

Heres the magic code to get it to work. Explanation of my understanding follows.

SearchWebService.SearchServiceClient client = null;
try
{
    SearchWebService.OTAuthentication auth = new SearchWebService.OTAuthentication();
    auth.AuthenticationToken = getToken();

    client = new SearchWebService.SearchServiceClient();
    client.Open();

    SearchWebService.SingleSearchRequest req = new SearchWebService.SingleSearchRequest();
    req.DataCollectionSpec = "\"LES Enterprise\", \"LES Enterprise [All Versions]\"";
    req.FirstResultToRetrieve = 1;
    req.NumResultsToRetrieve = 10;
    req.QueryLanguage = "Livelink Search API V1";
    req.ResultSetSpec = "where1=(Attr_1861819_4:" + searchTerm + ")";
    req.ResultTransformationSpec = new string[] { "Name", "OTName", "OTObject", "MIMEType", "Attr_1861819_4" };

    SearchWebService.SingleSearchResponse resp = client.Search(auth, req, "");
    if (resp != null)
    {
        for (int i = 0; i < resp.Results.Item.Length; i++)
        {
            ERDMSImage img = new ERDMSImage();

            if (resp.Results.Item[i] != null)
            {
                for (int n = 0; n < resp.Results.Item[i].N.Length; n++)
                {
                    for (int s = 0; s < resp.Results.Item[i].N[n].S.Length; s++)
                    {
                        string value = resp.Results.Item[i].N[n].S[s];
                        string field = resp.ResultAnalysis[0].N[n].S[s];

                        if (field.Equals("Created By"))
                        {
                            img.CreatedBy = value;
                        }
                        else if (field.Equals("Location"))
                        {
                            img.Location = value;
                        }
                        else if (field.Equals("MIMEType"))
                        {
                            img.MIMEType = value;
                        }
                        else if (field.Equals("Name"))
                        {
                            img.Name = value;
                        }
                        else if (field.Equals("OTObject"))
                        {
                            img.OTObject = value;
                            string[] values = value.Split('&');
                            img.DataId = values[0].Split('=')[1];
                            img.Version = values[1].Split('=')[1];
                        }
                    }
                    img.CreateUrlField();
                    foundImages.Add(img);
                }
            }
        }
    }
}
finally
{
    if (client != null)
    {
        client.Close();
    }
}

private static string getToken()
{
    AuthWebService.AuthenticationClient client = new AuthWebService.AuthenticationClient();
    return client.AuthenticateUser("<username>", "<password>");
}

So how this appears to work is:

  1. Create the search request object. This allows you to specify the fields you would like to return.
  2. The where clause can take a default field or a custom attribute (via id number as per the example).
  3. There are then 2 arrays returned. The first contains one row which is the definition of the array fields contained. In the example above this is retrieved by resp.ResultAnalysis[0].
  4. The 2nd array (resp.Results.Item[i]) actually contains the data, married up to the Result Analysis.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s