Question
Lukas Dolezal · Apr 10

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

0
0 205
Discussion (5)2
Log in or sign up to continue

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)

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.

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.

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

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