@@ -0,0 +1,3003 @@
+/**%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.apache.lucene.queries.function.valuesource;%0A%0Aimport org.apache.lucene.index.IndexReader;%0Aimport org.apache.lucene.queries.function.DocValues;%0Aimport org.apache.lucene.queries.function.ValueSource;%0Aimport org.apache.lucene.queries.function.docvalues.LongDocValues;%0Aimport org.apache.lucene.search.IndexSearcher;%0Aimport org.apache.lucene.util.BytesRef;%0A%0Aimport java.io.IOException;%0Aimport java.util.Map;%0A%0A/**%0A * %3Ccode%3ETotalTermFreqValueSource%3C/code%3E returns the total term freq (sum of term freqs across all docuyments).%0A * @lucene.internal%0A */%0Apublic class TotalTermFreqValueSource extends ValueSource %7B%0A  protected String field;%0A  protected String indexedField;%0A  protected String val;%0A  protected BytesRef indexedBytes;%0A%0A  public TotalTermFreqValueSource(String field, String val, String indexedField, BytesRef indexedBytes) %7B%0A    this.field = field;%0A    this.val = val;%0A    this.indexedField = indexedField;%0A    this.indexedBytes = indexedBytes;%0A  %7D%0A%0A  public String name() %7B%0A    return %22totaltermfreq%22;%0A  %7D%0A%0A  @Override%0A  public String description() %7B%0A    return name() + '(' + field + ',' + val + ')';%0A  %7D%0A%0A  @Override%0A  public DocValues getValues(Map context, IndexReader.AtomicReaderContext readerContext) throws IOException %7B%0A    return (DocValues)context.get(this);%0A  %7D%0A%0A  @Override%0A  public void createWeight(Map context, IndexSearcher searcher) throws IOException %7B%0A    long totalTermFreq = 0;%0A    for (IndexReader.AtomicReaderContext readerContext : searcher.getTopReaderContext().leaves()) %7B%0A      totalTermFreq += readerContext.reader.totalTermFreq(indexedField, indexedBytes);%0A    %7D%0A    final long ttf = totalTermFreq;%0A    context.put(this, new LongDocValues(this) %7B%0A      @Override%0A      public long longVal(int doc) %7B%0A        return ttf;%0A      %7D%0A    %7D);%0A  %7D%0A%0A  @Override%0A  public int hashCode() %7B%0A    return getClass().hashCode() + indexedField.hashCode()*29 + indexedBytes.hashCode();%0A  %7D%0A%0A  @Override%0A  public boolean equals(Object o) %7B%0A    if (this.getClass() != o.getClass()) return false;%0A    TotalTermFreqValueSource other = (TotalTermFreqValueSource)o;%0A    return this.indexedField.equals(other.indexedField) && this.indexedBytes.equals(other.indexedBytes);%0A  %7D%0A%7D%0A

add totaltermfreq to relevancy functions