private bool FilterDocuments(WorkContext context, IStorageActionsAccessor accessor, string key)
{
var documentMetadataByKey = accessor.Documents.DocumentMetadataByKey(key, null);
if (documentMetadataByKey == null)
return true;
var generator = context.IndexDefinitionStorage.GetViewGenerator(Index);
if (generator == null)
return false;
if (generator.ForEntityNames.Count == 0)
return false;// there is a new document and this index applies to it
var entityName = documentMetadataByKey.Metadata.Value<string>(Constants.RavenEntityName);
if (entityName == null)
return true; // this document doesn't belong to this index any longer, need to remove it
return generator.ForEntityNames.Contains(entityName) == false;
}