Problem with FileBasedIndexes (returning out of date keys?)
Hi, I'm having a problem with my index, when I use:
FileBasedIndex.getInstance().getAllKeys
FileBasedIndex.getInstance().requestRebuild(id);
FileBasedIndex.getInstance().scheduleRebuild(id, new Throwable());
And it seems that is reindexing because my indexer is executed correctly (and is returning the correct "Map" for every fileContent), but the keys are not modified, I'm always receiving the same keys with "getAllKeys"
Could you please help me to refresh the index?
Thanks !!
PS: when I use File > Invalidate Caches /Restart. And restart the IDE, then the index is refreshed correctly. But I need a way to refresh my index within an Action just in case. Is possible to do that?
Please sign in to leave a comment.
This is normal. The simple fact that the getAllKeys() method does not take a parameter of type "Project" should indicate to you that it will not filter the keys by project.
Hi Dmitry, but it does !!
Hi,
Some notes for your questions:
- Indices are application level "service" over VirtualFile's (no project indices), for the sake of simplicity like Map<Key, Collection<Pair<VirtualFile, Value>>>.
- Most important indices operation is (quick) processing of Collection<Pair<VirtualFile, Value>> for particular key (
- getAllKeys(indexId, project) will return set of keys that will contain "up to date" keyset for supplied project.
OK, thanks Maxim, but I'm not sure why the getAllkeys is needing a Project, and why we cannot get only the keys from current project (I mean if we can filter later with getValues or getContainingFiles by Project using the correct GlobalSpec, then why we can't just start filtering the keys by project too? )
Currently what I'm doing to get the keys for current project only is to check if the keys contains virtual files included in current project, seems to be running fine, but it feels like a really slow operation for just getting the keys...
Do you think there is a better or more efficient way to get the keys for the current project only??
Thanks !!