user3266188
user3266188

Reputation: 161

Solr Term Frequency returning 0

I currently using SOLR indexing in my JAVA Program. I would like to retrieve the term frequency using the following code however its returning me 0. I went to the /data/index folder and found that some of the index files are missing. I think this could be the reason its returning me 0? or perhaps theres something wrong with my code?

public long tf(String term) throws IOException, SolrServerException {
    String file = "/Users/admin/Downloads/solr-4.10.3/example/solr/collection1/data/index";
    IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(file)));

    long tf = reader.totalTermFreq(new Term("content", term)); 
    reader.close();

    return tf;

Upvotes: 1

Views: 137

Answers (1)

Swapneel Sawant
Swapneel Sawant

Reputation: 11

public abstract long totalTermFreq(Term term) throws IOException

Returns the number of documents containing the term term. This method returns 0 if the term or field does not exists, or -1 if the Codec does not support the measure. This method does not take into account deleted documents that have not yet been merged away.

Upvotes: 1

Related Questions