Written by

Software developer
Question Lukas Dolezal · Apr 10, 2022

Index inheritance

I want to store data in an index global without defining an index in an inherited class.
Example:

Class Aclass [ Abstract ]
{
Index TXSBI On TextSearch(KEYS);
Index TXSSI On TextSimilarity(KEYS) [ Data = TextSimilarity(ELEMENTS) ];
Property TextSearch As %Text(LANGUAGECLASS = "%ZText.Czech", MAXLEN = 1000, XMLPROJECTION = "NONE");
Property TextSimilarity As %Text(LANGUAGECLASS = "%ZText.CzechSim", MAXLEN = 1000, SIMILARITYINDEX = "TXSSI", XMLPROJECTION = "NONE");
...
//other code
Class AAclass Extends (%Persistent, ClassType.SuperClass, Aclass, Bclass...)
{

}

Is there a way to inherit indexes? (without defining these indices) ^AAclassI("TXSSI" ...
Do you have any advice on how to do this?
Thank you

Comments

Timothy Leavitt · Apr 11, 2022

Generally I'd do this as follows:

Class DC.Demo.DefinesIndices Extends %Persistent [ Abstract, NoExtent ]
{

Index TXSBI On TextSearch(KEYS);

Index TXSSI On TextSimilarity(KEYS) [ Data = TextSimilarity(ELEMENTS) ];

Property TextSearch As %Text(LANGUAGECLASS = "%Text.English", MAXLEN = 1000, XMLPROJECTION = "NONE");

Property TextSimilarity As %Text(LANGUAGECLASS = "%Text.English", MAXLEN = 1000, SIMILARITYINDEX = "TXSSI", XMLPROJECTION = "NONE");

}

Class DC.Demo.InheritsIndices Extends DC.Demo.DefinesIndices
{

Storage Default
{
<Data name="InheritsIndicesDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>TextSearch</Value>
</Value>
<Value name="3">
<Value>TextSimilarity</Value>
</Value>
</Data>
<DataLocation>^DC.Demo.InheritsIndicesD</DataLocation>
<DefaultData>InheritsIndicesDefaultData</DefaultData>
<IdLocation>^DC.Demo.InheritsIndicesD</IdLocation>
<IndexLocation>^DC.Demo.InheritsIndicesI</IndexLocation>
<StreamLocation>^DC.Demo.InheritsIndicesS</StreamLocation>
<Type>%Storage.Persistent</Type>
}

}

Key points:

  • Indices are only inherited from the primary superclass (see https://docs.intersystems.com/iris20212/csp/docbook/DocBook.UI.Page.cls…) - the docs aren't super clear on this.
  • Your primary superclass needs to be persistent
  • [Abstract, NoExtent] lets you define a class that extends %Persistent but doesn't have storage - so subclasses have their own storage (which is presumably what you want)
0
Lukas Dolezal  Apr 12, 2022 to Timothy Leavitt

Thanks for the reply. Unfortunately, this solution will not help me. I want to extend some classes by inheriting them from other classes (with some properties, methods, indexes). This property inheritance adds this data to the storage (global ^ xD). But the index is not stored in ^ xI because it is not the first superclass.

0
Vitaliy Serdtsev · Apr 11, 2022

Here's what I found: IndexClass (%Dictionary.ClassDefinition) IndexClass (%Dictionary.CompiledClass)

That is, you can write something like this:

Class dc.test Extends %Persistent IndexClass dc.anothertest ]
{
}

The same applies to MemberSuper.

Unfortunately, I haven't found any examples of how to use it or if it works at all.

0
Lukas Dolezal  Apr 12, 2022 to Vitaliy Serdtsev

Thanks for the reply. Unfortunately, this solution will not help me. It does not create an index global. Probably because I use several superclasses.

0
Vitaliy Serdtsev  Apr 13, 2022 to Lukas Dolezal

Notes on Indices Defined in Classes

When working with indices in class definitions, here are some points to keep in mind:

• Index definitions are only inherited from the primary (first) superclass.
• ...
 

Simple sample

Class dc.Aclass Abstract ]
{

Index idxF On f;

Property As %Integer;

}Class dc.test Extends (dc.Aclass%Persistent) [ ClassType = persistent ]
{

ClassMethod Test()
{
  ^dc.testD,^dc.testI
  
  &sql(insert into dc.test(fvalues(30))
  &sql(insert into dc.test(fvalues(303))
  
  zw ^dc.testD,^dc.testI
}

}

Output:

USER>##class(dc.test).Test()
^dc.testD=2
^dc.testD(1)=$lb("",30)
^dc.testD(2)=$lb("",303)
^dc.testI("idxF",30,1)=""
^dc.testI("idxF",303,2)=""
0