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?

0
4 comments

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.

0

Hi Dmitry, but it does !!

 
/**
* @param project it is guaranteed to return data which is up-to-date withing the project
*                Keys obtained from the files which do not belong to the project specified may not be up-to-date or even exist
*/
@NotNull
public abstract <K> Collection<K> getAllKeys(@NotNull ID<K, ?> indexId, @NotNull Project project);


How can I get the keys for the current project only? (or create an index for current project only)


EDIT:
I guess I could check the containingFiles for every key and check if that returns some file from the current project to know if the key is valid in current project.
But I guess that will be really slow, also I guess the index in general will became slower everytime we create a new project (I mean every project will affect the performance of the others even when they are not related).
I feel I'm missing something here, is there any index specific for project or some tip to manage index for current project?

0

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 (

i.g. getContainingFiles, getValues() ). Such processing is usually done with filtering of needed VirtualFiles by virtual file filter 
(GlobalSearchScope / IdFilter parameters).

- getAllKeys(indexId, project) will return set of keys that will contain "up to date" keyset for supplied project.

0

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 !!

0

Please sign in to leave a comment.