title: Precision recall in lucene java
body: <p>I want to use Lucene to calculate Precision and Recall.</p>
  
  <p>I did these steps:</p>
  
  <ol>
  <li><p>Made some index files. To do this I used indexer code and indexed <code>.txt</code> files which exist in this path <code>C:/inn</code> (there are 4 text files in this folder) and take them in "outt" folder by setting the indexpath to <code>C:/outt</code> in the Indexer code.</p></li>
  <li><p>Created a package called <code>lia.benchmark</code> and a class inside it which is called "PrecisionRecall" and add <code>externaljars</code> (rightclick --> Java build path --> add external jars) and added <code>Lucene-benchmark-.3.2.0jar</code> and <code>Lucene-core-3.3.0jar</code></p></li>
  <li><p>Set the <code>topicsfile</code> path in code to <code>C:/lia2e/src/lia/benchmark/topics.txt</code> and<br>
  <code>qrelsfile</code> to <code>C:/lia2e/src/lia/benchmark/qrels.txt</code> and dir to "C:/outt".</p>
  
  <p>Here is code:</p>
  
  <pre><code>package lia.benchmark;        
  import java.io.File;  
  import java.io.PrintWriter;  
  import java.io.BufferedReader;  
  import java.io.FileReader;  
  import org.apache.lucene.search.*;  
  import org.apache.lucene.store.*;  
  import org.apache.lucene.benchmark.quality.*;  
  import org.apache.lucene.benchmark.quality.utils.*;  
  import org.apache.lucene.benchmark.quality.trec.*;  
  
   public class PrecisionRecall {  
  
     public static void main(String[] args) throws Throwable {  
  
    File topicsFile = new File("C:/lia2e/src/lia/benchmark/topics.txt");  
           File qrelsFile = new File("C:/lia2e/src/lia/benchmark/qrels.txt");  
           Directory dir = FSDirectory.open(new File("C:/outt"));  
           IndexSearcher searcher = new IndexSearcher(dir, true);  
  
           String docNameField = "filename";  
  
           PrintWriter logger = new PrintWriter(System.out, true);  
  
           TrecTopicsReader qReader = new TrecTopicsReader();   
           QualityQuery qqs[] = qReader.readQueries(                        
                   new BufferedReader(new FileReader(topicsFile)));  
  
           Judge judge = new TrecJudge(new BufferedReader(          
                  new FileReader(qrelsFile)));                                          
  
           judge.validateData(qqs, logger);                                          
  
           QualityQueryParser qqParser = new SimpleQQParser("title", "contents");  
  
           QualityBenchmark qrun = new QualityBenchmark(qqs, qqParser, searcher, docNameField);  
     SubmissionReport submitLog = null;  
           QualityStats stats[] = qrun.execute(judge,                   
                     submitLog, logger);  
  
          QualityStats avg = QualityStats.average(stats);          
          avg.log("SUMMARY",2,logger, "  ");  
     dir.close();  
    }  
  } 
  </code></pre></li>
  <li><p>Initialized qrels and topics. In documents folder (C:\inn) I have 4 txt files which  2 of them is relevance to my query ( query is apple) so I filled qrels and topics.</p>
  
  <p>the qrels file like this:</p>
  
  <pre><code>&lt;top&gt;  
      &lt;num&gt; Number: 0 
      &lt;title&gt; apple
      &lt;desc&gt; Description:  
      &lt;narr&gt; Narrative:  
  &lt;/top&gt;  
  </code></pre>
  
  <p>and  topics file like this:</p>
  
  <pre><code>0    0      789.txt           1
  0    0      101.txt           1
  </code></pre>
  
  <p>I tried also the Path format namely for example "C:\inn\789.txt"  instead of  "789.txt" 
  but results are  zero:</p>
  
  <pre><code>0 - contents:apple
  0 Stats:
  Search Seconds: 0.016
  DocName Seconds: 0.000
  Num Points: 2.000
  Num Good Points: 0.000
  Max Good Points: 2.000
  Average Precision: 0.000
  MRR: 0.000
  Recall: 0.000
  Precision At 1: 0.000
  SUMMARY
  Search Seconds: 0.016
  DocName Seconds: 0.000
  Num Points: 2.000
  Num Good Points: 0.000
  Max Good Points: 2.000
  Average Precision: 0.000
  MRR: 0.000
  Recall: 0.000
  Precision At 1: 0.000
  </code></pre></li>
  </ol>
  
  <p>Can you tell me what is wrong with me?</p>
  
  <p>I really need to know why results are zero.</p>