1 package org.apache.lucene.misc;
4 * Copyright 2004 The Apache Software Foundation
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 import org.apache.lucene.store.Directory;
21 import org.apache.lucene.store.FSDirectory;
23 import org.apache.lucene.index.Term;
24 import org.apache.lucene.index.IndexReader;
28 * Utility to get document frequency and total number of occurrences (sum of the tf for each doc) of a term.
30 public class GetTermInfo {
32 public static void main(String[] args) throws Exception {
34 FSDirectory dir = null;
35 String inputStr = null;
38 if (args.length == 3) {
39 dir = FSDirectory.open(new File(args[0]));
46 Term term = new Term(field, inputStr);
47 getTermInfo(dir,term);
50 public static void getTermInfo(Directory dir, Term term) throws Exception {
51 IndexReader reader = IndexReader.open(dir);
53 long totalTF = HighFreqTerms.getTotalTermFreq(reader, term);
54 System.out.printf("%s:%s \t total_tf = %,d \t doc freq = %,d \n",
55 term.field(), term.text(), totalTF, reader.docFreq(term));
58 private static void usage() {
60 .println("\n\nusage:\n\t"
61 + "java " + GetTermInfo.class.getName() + " <index dir> field term \n\n");