Tags / search indexes not updated properly

I use “state-tags” to e.g. tag todos related to DEVONthink items.
To get a quick overview I wrote a quick script which searches for e.g. “tags:#todo” in my database. I experienced that the index for the search is not updated properly.
I first thought of an issue in my script, but when I type the same search into the DTTG search bar, it turns out, that the same items are returned here. The results contain items which don’t contain the tag anymore. I only managed to get rid of this by reindexing the database…
this is not a one time issue, I experienced it quite often and on iPhone and iPad.

Could you please post the complete script?

to be precise this is an iOS shortcut, which calls the x-callback-url for each defined state tag (#todo,#review,…)
the tag is url encoded and pasted to the end of this “base url”:
x-devonthink://x-callback-url/search?query=tags:[url-encoded-tag]

the returned value for the “text” parameter is then parsed into a dictionary and for every item in this dictionary, I create an entry “- [name][itemlink]”.

If I run it and then see the results I often see items which don’t have the tags anymore, even if I open the item in DTTG I can’t see the tag in the metadata of the item.
If I run the exact query in the search field of DTTG (e.g. “tags:#todo”), I see the item in the results, too. That’s why I’m concluding that this has nothing to do with the callback url…

to solve this, I run the url action "x-devonthinktogo://reindex and when I run the search or the shortcut again, the item is not returned as result anymore.

So, just that I understand correctly: You add and remove tags frequently and this change is not properly reflected in the index? How do you remove or add the tags and do you wait for a moment for the index to catch up before running the search?

I add and remove these tags frequently (where frequently means, that in most cases I add e.g. #todo when i import the fiel. if its done i remove the tag on whatever device I currently use). I think in most cases the problem is, that I remove the tag on my mac and I don’t open DTTG on my iPhone / iPad before running the shortcut.
BUT:
Even If I notice in the result of the shorcut, that an item in DEVONthink is shown with a tag it should not have anymore, I will open DTTG, sync it and run the shortcut again - it will still be in the results. so the index is not updated even if the tag is not shown anymore in the “info” of the item.

Yes, that is the problem: DEVONthink To Go only syncs and indexes the documents after you open the app. It might sync in the background but for indexing you need to open the application first. Indexing happens in regular intervals but not immediately.

Future versions of DEVONthink To Go might search for tags without relying on the full text index.

yes thats what i thought, too.
As I mentioned even if I sync the database and then rerun the shortcut, the items will still be included.
Also the search in the DTTG App still shows them. If I open the “info” of the data item, the tag is not displayed there.

I’d really like to bump this issue up again…
even if I open the app and sync it first, the indexing is not done and therefore the callback url returns “crap”…