Optimize conversion to a cacheable DocIdSet
Fix ScriptFilter cache key calculation

Fixes #2651