Use defer to avoid call stack fail.
Ensure common terms across termsets are added only once.
More robust check for unique term => docid relation.
Merge branch 'dev' into dev-nogyp