Introduce additional frequency metric other than term frequency

I want to introduce additional frequency metric on top of term
frequency at index time. The frequency metric is calculated based on the
term-document matrix.

I tried overriding DefaultSimilarity.Java. The class contains the
term frequency, document frequency information. But, the mapping of the
term frequency to the term and document is missing in that class.

I tried using ScoreFunctionBuilder.Java to modify the scoring at
query time. But, the score is independent of term-frequency and only
depends on the modified scoring logic.

I want the exact class which calculates the term frequency and
document frequency and can we override the class using a plugin. Kindly
help me out on this issue.

Also, the inference from Mastering Elasticsearch Guide book is that
term frequency is calculated and stored at the time of Indexing. If this
is correct, please let me know the class which calculates the term
frequency at the time of Indexing. Also correct me if I am wrong.