Rebuild class index
I have a class. In class there is an index. This index is for quick search on name property.
Class User { ..... Property Name as %String; Index NameInd On Name; ..... }
This class is mapped to some global ^GL(userId) = "Name*other data....****"
And there is also index global ^GLNameIndex(Name, userId) = ""
When I add new User entry through class, f. i.
S user = ##class(User).%New() S user.Name = "Some name" D user.%Save()
calling method %Save() adding new entry to index automatically.
And this way index ^GLNameIndex is always actual.
But in my program new user entry can be added without class interface, through terminal program.
In terminal program new user entry is added by direct recording to global, f. i.
S ^GL(userId) = "Name*other data."
In this case, new user name is not adding to index global ^GLNameIndex and index is not actual.
How should I resolve this case, when new user adding without class interface? Should I manually adding new user name to index global or there is some class method for rebuilding index?
Method
Why you have two different ways to create objects?
If you have class, you should use object or SQL way to create or change objects.
If you add it manually through direct access to global, you should also create all indexes, this way.
Instead of %BuildIndices, you can try to use method %FileIndices, with Object's id as a first argument.
I have two different ways for creating new objects because of there are two different interfaces in the program. There is old interface via terminal with direct access to globals and there is new zen web interface with classes.
And some users prefer to work with old terminal interface, so I must to maintain also the old inteface.
Can you give me some example with %FileIndices? I didn't find anything
http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.SearchPageZen...
Thanks, Amir, for your advice.
I decided to change in old program methods for saving and deleting entries. I changed direct access to global on object access and methods %Save() and %DeleteId(). These methods automatically handle new index global. I also call old methods for old index global and other old code.
Methods %FileIndices and %SaveIndices marked as [Internal].
Functional of %BuildIndices more than enough.
Really? See pStartID/pEndID.
Still read this articleru.
Hi!
The method %FileIndices(id) may help you. The problem is that you won't know which ID you must use to call it. Have new objects been added? Which have been changed?
I assume you have taken an old style global and mapped it to classes and have created an index for it. That's ok. Normally old style applications will have its own indices on the same global or another. They probably have an index on Name already that they use and you should try to map that existing subscript as your name index on your mapped class instead of creating a new index.
But if you really want to go on and create a new index, you have only two choices:
As you can see, all options imply changing the old style code. I would push for option number 1 as this can be the start of some real good improvements to your old style application.
There is no middle ground here, unless you want to rebuild all your indices every day.
Depending on how many places this global is referred on your application, the way the application is compartmentalized, and if you are using indirection or not throughout your application, these changes can be very simple or very complex to do and test.
Another way of going about this is to try to use the journals APIs to read the journal files, detect changes on this specific global and update the index... That would prevent you from touching the old style application. I have never done this before, but I believe it is pretty feasible.
Kind regards,
AS
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue