Add ref. codes to the search index, fixes #5863

Add both, inherit reference code and reference code, in the search index
so the setting can be changed without rebuilding the index.
Load repository and ancestors before creating the inherit reference code