-
Re: Event Fame search using AFSearch for a template over a subset of elements
Rick DavinFeb 7, 2018 4:28 PM (in response to Lonnie Bowling)
1 of 1 people found this helpfulHi Lonnie,
Glad to see you back in the forums. I'm in meetings most of this week, but wanted to start a dialog with you about this topic. What version of AF SDK are you using? When you say elements, let's clarify that you mean referenced elements on an event frame, right? Are the elements based on a template as well?
In AF SDK 2.9.5 released in December 2017, there is new support for nested queries, so you can specify a template (or other filters) for a nested element query, and then a template yet again (plus other filters) on AFEventFrameSearch query.
-
Re: Event Fame search using AFSearch for a template over a subset of elements
Lonnie BowlingFeb 7, 2018 11:51 PM (in response to Rick Davin)
Hi Rick,
Thanks for the response. I'm using 1 version back from that; 2.9.2. I'll load up 2.9.5 and check it out, that would be so nice if it works for me. Yes, by elements, I mean referenced elements, and everything is based on templates. I will post again after I look at the new SDK. Don't know how I missed that release, guess I have been hiding under a rock for too long!
Thanks,
Lonnie
-
Re: Event Fame search using AFSearch for a template over a subset of elements
Rick DavinFeb 9, 2018 1:48 PM (in response to Lonnie Bowling)
3 of 3 people found this helpfulHi Lonnie,
I don't have an example to match exactly what you want to do, but I do have an example illustrating nested tokens using the new AFAttributeSearch. I am sure you will be able to apply to your situation. Instead of searching on 2 templates (1 for EF and 1 for elements), I will be searching on 2 names (1 for attribute and 1 for element). The main thing is notice the syntax. All 3 examples do the same thing but do it differently. The first uses AFSearchToken, the second uses a plain query string, and the third uses an Interpolated string.
// Goal is to find attributes named "Feed Rate" on any elements named "Boiler*" // Finds 1 attribute per element, using nested query tokens. // New to AF 2.9.5: AFSearchToken.Tokens property. public static void FindAttributeDemo21(AFElement root) { // Set up the nested element search tokens var nestedTokens = new List<AFSearchToken>(); nestedTokens.Add(new AFSearchToken(AFSearchFilter.Name, "Boiler*")); // Set up the outer attribute search tokens, which use the nested tokens var tokens = new List<AFSearchToken>(); // The Element uses the nested token(s) tokens.Add(new AFSearchToken(AFSearchFilter.Element, AFSearchOperator.Equal, null, nestedTokens)); // The Attribute uses a simple Name search // NOTE 'Feed Rate' is the attribute name, whereas '|Feed Rate' is the path (relative to the element). tokens.Add(new AFSearchToken(AFSearchFilter.Name, "Feed Rate")); using (var search = new AFAttributeSearch(root.Database, "attr demo 2.1", tokens)) { search.CacheTimeout = TimeSpan.FromMinutes(10); foreach (var item in search.FindAttributes()) { // do something } } } // Same as above but using nested { } in query strings. public static void FindAttributeDemo22(AFElement root) { // NOTE how element has nested { }. var query = "Element:{Name:'Boiler*'} Name:'Feed Rate'"; using (var search = new AFAttributeSearch(root.Database, "attr demo 2.2", query)) { search.CacheTimeout = TimeSpan.FromMinutes(10); foreach (var item in search.FindAttributes()) { // do something } } } // Same as above but using nested { } in Interpolated query strings. public static void FindAttributeDemo23(AFElement root) { string elemName = "Boiler*"; string attrName = "Feed Rate"; // This gives a compile error with an Interpolated string //var query = $"Element:{Name:'{elemName}'} Name:'{attrName}'"; // Escape the { and } around literal braces with {{ and }} var query = $"Element:{{Name:'{elemName}'}} Name:'{attrName}'"; using (var search = new AFAttributeSearch(root.Database, "attr demo 2.3", query)) { search.CacheTimeout = TimeSpan.FromMinutes(10); foreach (var item in search.FindAttributes()) { // do something } } }
To help round out the discussion, here are some links:
What's New AF 2017 R2 (AF SDK 2.9.5)
Search Overview - strongly suggest you BOOKMARK this link
-
Re: Event Fame search using AFSearch for a template over a subset of elements
DLopezNov 26, 2018 5:15 PM (in response to Rick Davin)
Thanks, Rick! Building on top of this example, how would you modify the query string in your 2.2 example above in order to only return results where the attribute's Element is beneath a parent Element whose name matches a particular search mask? I believe that "Parent" is a search parameter, but I haven't seen many examples that reference it, and I haven't had much success in my own tests.
-
Re: Event Fame search using AFSearch for a template over a subset of elements
Rick DavinNov 26, 2018 6:22 PM (in response to DLopez)
Hi Daniel,
Interesting question. So Parent has been an acceptable filter since AF 2.9.5 and it accepts a nested query of its own. I haven't tried this so it will be interesting to see if a nested query can have it's own nest query!
The original string above is: string query = "Element:{Name:'Boiler*'} Name:'Feed Rate'";
Let's say you are interested in boilers under a Parent element named "Unit 01". Offhand the first thing I would try is:
string query = "Element:{ Name:'Boiler*' Parent:{Name:'Unit 01'} } Name:'Feed Rate'";
But I need to go test that to see if it works. I'll get back to you.
-
Re: Event Fame search using AFSearch for a template over a subset of elements
Rick DavinNov 26, 2018 6:39 PM (in response to Rick Davin)
Hey Dan,
Bad news. Looks like a nested query cannot contain its own nested query. So the syntax above would not work. Keep in mind the example there was to perform an AFAttributeSearch, which requires a nested element (or event frame) query. If you were performing an AFElementSearch, you would be able to use the nested query for Parent.
I will check with the dev team to confirm this.
-
Re: Event Fame search using AFSearch for a template over a subset of elements
Rick DavinNov 26, 2018 7:15 PM (in response to Rick Davin)
Hello again Dan,
I confirmed with the dev team that doubly nested queries are currently not allowed for performance reasons. If this is a feature you feel you can't live without, you are invited to create an enhancement request at User Feedback for OSIsoft Products and Services .
-
-
-
-
-
Re: Event Fame search using AFSearch for a template over a subset of elements
Rick DavinFeb 9, 2018 8:54 PM (in response to Lonnie Bowling)
It was easy to miss since it was released on December 27 during busy holiday season.
-
-
-
Re: Event Fame search using AFSearch for a template over a subset of elements
Rick DavinFeb 13, 2018 4:46 PM (in response to Lonnie Bowling)
1 of 1 people found this helpfulHi Lonnie,
One very important detail about nested queries that I left out earlier, you will need to upgrade both the AF Client and AF Server. Specifically, your AF Server must support the PISystemFeatures.QuerySearchAttribute feature. That particular enumeration indicates that your AF Server supports new search features added to AF 2.9.5:
- AFAttributeSearch
- AFNotificationContactTemplateSearch
- Nested queries
- New search tokens for EventFrame, IsInternal, Parent, PlugIn, and PlugInName.
I know in a private conversation that you are interested in the Parent filter.
-
Re: Event Fame search using AFSearch for a template over a subset of elements
Lonnie BowlingFeb 16, 2018 12:41 AM (in response to Rick Davin)
Thanks for all the help Rick, once I am able to get my system updated, I'll give it a shot!
Lonnie
-
Re: Event Fame search using AFSearch for a template over a subset of elements
Rick DavinFeb 16, 2018 4:06 PM (in response to Lonnie Bowling)
Cool, Lonnie. I'd love to know the results later. You can shoot me a private message or post here. If you don't, I will HUNT YOU DOWN AT PI WORLD.
-