A quicker way for creating multiple classifications

If you have a list of paths for which you want to create corresponding classifications in ADAM, then you can simply foreach through all these paths and call ClassificationHelper.CreateClassificationUsingPath each time. This will naturally work, but there's also another way that may be quite a lot faster depending on your environment.

There's a method called ClassificationHelper.CreateClassificationsUsingPaths (note the plural) which allows you to specify an array of paths to create. The biggest advantage of this method compared to the CreateClassificationUsingPath method is that it will cache what was created and queried. So, if you create a classification path /Office Equipment/Desks then it will remember that it already created the Office Equipment level, so when it processes the next path /Office Equipment/Chairs, then no queries will be executed to determine if the Office Equipment classification already exists.

If many of your paths share the same classification names up to a certain level, then you can easily gain 10% to 30% performance gain compared to foreach'ing yourself.

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
string[] classes = new string[]
    {
       "/Countries/Belgium/Flanders/Ghent/Products/Product A",
       "/Countries/Belgium/Flanders/Ghent/Products/Product B",
       "/Countries/Belgium/Flanders/Ghent/Products/Product C",
       "/Countries/Belgium/Flanders/Ghent/Products/Product D",
       "/Countries/Belgium/Flanders/Ghent/Products/Product E",
       "/Countries/Belgium/Flanders/Ghent/Products/Product F",
       "/Countries/Belgium/Flanders/Ghent/Products/Product G",
       "/Countries/Germany/Products/Product A",
       "/Countries/Germany/Products/Product B",
       "/Countries/Germany/Products/Product C",
       "/Countries/Germany/Products/Product D"
    };

// The quickest way using CreateClassificationsUsingPaths
ClassificationHelper helper = new ClassificationHelper(app);
helper.CreateClassificationsUsingPaths(Array.ConvertAll<string, ClassificationPath>(
    classes, new Converter<string, ClassificationPath>(p => new ClassificationPath(p))));

// The slower way doing the for each
foreach (string cls in classes)
{
    helper.CreateClassificationUsingPath(cls);
}

Comments

Leave a comment
You must be logged in to post comments.
Sign in now
 
 
Technical
Business
rss feed