Strongly typed searching in ADAM

This article is soooo cool, and it is so for several reasons.

First, I didn't write it. The idea, the development and writing the article are all done by Søren Trudsø Mahon from our ADAM partner DXP. Second, this isn't going to be a single blog post. This is only part one of three blog posts! This one gets you interested I'm sure, more details (and code!) will follow in the coming days. Stay tuned if you want to learn more about this! Third. It's one of those things that any self respecting developer will see and say "Cooool". But that's just my humble opinion.

Anyway. Enough said. Next is Søren speaking:

Adam’s search is strong, very strong indeed. But as a developer we don’t like to write magic strings in our code:

C#
1
2
new SearchExpression("Ancestor.Id = ?", 
  new object[] { classification.Id })

And also we don’t have any type safety with regards to the value we are searching for:

C#
1
2
new SearchExpression("Ancestor.Identifier = ?", 
  new object[] { classification.Id })

Which will give us a runtime error. So, what we would like to be able to write is a query like this:

C#
1
2
3
Application.Search()
  .Classification
     .Ancestor.Id(classification.Id)

This combines the power of strongly typed statements and the familiarity of Adam search.

Using the api:

The api is created as an extension method on Adam.Core.Application called Search(), from there you select what you want to search on fx. App.Search().Record or App.Search().Classification.

On “the” first level of the “chain” you can use the Adam Load methods Load(Guid id) or Load(IList<Guid> ids) to just directly load object of that type

C#
1
2
IEnumerable<Record> enumerable = app.Search().Record.Load(
  new[] {record1.Id, record2.Id})

Or you can perform an actual search.

C#
1
2
3
IRecordSearch identifier = app.Search().Record
    .Classification.Identifier("First");
RecordCollection records = identifier.Load();
You could also just the SearchExpression without loading any items and use that against a helper:
C#
1
2
3
IRecordSearch identifier = app.Search().Record
    .Classification.Identifier("First");
new RecordHelper(app).Exists(identifier.Expression);
And you can refine your search expression in multiple lines:
C#
1
2
3
IRecordSearch identifier = app.Search().Record
    .Classification.Identifier("First");
identifier = identifier.CreatedBy.Name("administrator");
Search examples:
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
26
27
28
var rootIdentifier = "First";

// "Searching for a single Classification"
var rootClassification = app.Search().Classification
  .Identifier(rootIdentifier).Single();

// "Searching for underneath classification with identifier 'First'"
var classificationSearch = app.Search().Classification
  .AncestorOrSelf.Identifier(rootIdentifier);
classificationSearch.Print();

// "Refining the expression to include only those created 
// by 'administrator'"
classificationSearch = classificationSearch
  .CreatedBy.Name("administrator");
classificationSearch.Print();

// "Using search expression against helper"
SearchExpression classificationSearchExpression = 
  classificationSearch.Expression;
Console.WriteLine("SearchExpression:{0}", classificationSearchExpression);
var exists = new ClassificationHelper(app)
  .Exists(classificationSearchExpression);
Console.WriteLine(exists);

// Load using just the id (actually uses ExtendedItemBase.Load(Guid id))                
Classification classification = app.Search().Classification
  .Load(rootClassification.Id);

Using it in real life:

Creating some kind of custom UI, where a user inputs for example a date or just a string combined with some other criteria and then we can build a searchexpression for that:

C#
1
2
3
4
5
6
7
8
9
10
Console.WriteLine("Input ancestor identifer and press 'Enter':");
var ancestorIdentifier = Console.ReadLine();
Console.WriteLine("Input search expression and press 'Enter':");
var searchExpression = Console.ReadLine();
var classifications = app.Search().Classification
    .AncestorOrSelf.Identifier(ancestorIdentifier)
    .Add(new SearchExpression(searchExpression))
    .Load();
classifications.Print();
Console.ReadKey();

That’s where we are now, we got the foundation, but we still need to add keywords, but adding keywords is pretty easy, so it’s something we will add along the way and whenever Adam adds new keywords.

Wanna see the code? Wait a few more days. :-)

Comments

Leave a comment
You must be logged in to post comments.
Sign in now
 
 
CATEGORIES
AnnouncementsDocMaker StudioEngineSharePoint ConnectorWeb DevelopmentWebinarsWorkflow Studio
rss feed