Hello.

Thank you for this information. I started testing it and %iKnow.Queries.SourceAPI:GetSimilar()  returned the following as a result local:

result(1)=$lb(890,":SQL:2002:20020308X00320",.4737,.9606,57,27,686,.4737)

The list is formed from these values:

$lb(srcId, externalId, percentageMatched, percentageNew, nbOfTgtsInRefSrc, nbOfTgtsInCommon, nbOfTgtsInSimSrc, matchScore)

What does that mean?

  • srcId -sourceId of similar document
  • externalId - external source id of similar document
  • percentageMatched - number of targets common between source and similar documents divided by number of targets in source document
  • percentageNew - number of targets in similar document that is not present in source document divided by total number of targets in similar document
  • nbOfTgtsInRefSrc - number of targets in source document
  • nbOfTgtsInCommon - number of targets common between source and similar documents
  • nbOfTgtsInSimSrc - number of targets in similar document
  • matchScore - seems equal to percentageMatched

Is that correct? Are there documentation on that?

Here's an idea on how to do it without triggers altogether.

1. Set IsLeader property only in case member is a leader. So its 1 or NULL.

2. Add unique index on (Team, IsLeader). Unique index can have any number of NULL records.

3. If you try to add more than one leader, you'll get an error:

ERROR #5808: Key not unique: Utils.TeamMember:IsLeaderIndex:^Utils.TeamMemberI("IsLeaderIndex"," 1"," 1") [%SaveData+14^Utils.TeamMember.1:USER]

Sample code:

Class Utils.TeamMember Extends %Persistent
{

Property Team As %String;

Property Member As %String;

Property IsLeader(VALUELIST = ",1");

Index IsLeaderIndex On (Team, IsLeader) [ Unique ];

/// do ##class(Utils.TeamMember).Test()
ClassMethod Test(AddTwoLeaders = {$$$YES})
{
    do ..%KillExtent()
    write $System.Status.GetErrorText(..Add(1, "Alice"))
    write $System.Status.GetErrorText(..Add(1, "Bob"))
    write $System.Status.GetErrorText(..Add(1, "Clover"))
    write $System.Status.GetErrorText(..Add(1, "Dave", 1))
    if AddTwoLeaders {
        write $System.Status.GetErrorText(..Add(1, "Helen", 1))
    }
}

ClassMethod Add(Team, Member, IsLeader = "")
{
    set obj = ..%New()
    set obj.Team = Team
    set obj.Member = Member
    set obj.IsLeader = IsLeader
    quit obj.%Save()
}

}