title: IndexSearcher in Lucene is always returning 0 totalHits
body: <p>The search method of IndexSearcher in Lucene is not returning any output. The number of documents that are returned by the query is always 0. I had built the index using the following code:</p>
  
  <pre><code>    void buildIndex(File indexDir, File trainDir, HashMap&lt;String,Integer&gt; dictionary) 
              throws IOException, FileNotFoundException {
  
              Directory fsDir = FSDirectory.open(indexDir);
              IndexWriterConfig iwConf 
                  = new IndexWriterConfig(VERSION,mAnalyzer);
  
              iwConf.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
              IndexWriter indexWriter
                  = new IndexWriter(fsDir,iwConf);
  
              File file = trainDir;
              String csvFilename = "/home/serene/Downloads/IndustryClassification/Train/Training.csv";
              CSVReader csvReader = new CSVReader(new FileReader(csvFilename),'\t');
              String[] row = null;
              while((row = csvReader.readNext()) != null) {
                  Document d = new Document();
                  String companyname = row[1];
                  String NAICSID = row[2];
                  //System.out.println(NAICSID);
                  String description = row[4];
                  d.add(new TextField("company",companyname,Store.YES));
                  d.add(new StringField("category",NAICSID,Store.YES));
                  dictionary.put(NAICSID, 1);
                  d.add(new TextField("description", description, Store.NO));
                  //System.out.println(d.toString());
                  indexWriter.addDocument(d);
              }
              csvReader.close();
              int numDocs = indexWriter.numDocs();
              indexWriter.forceMerge(1);
              indexWriter.commit();
              indexWriter.close();
              System.out.println("index=" + indexDir.getName());
              System.out.println("num docs=" + numDocs);
          }
  </code></pre>
  
  <p>When trying to get the output for a test query using the following code, I am not getting any output for the categories as scoreDocs.length is always 0 and the code within the for loop isn't executed.</p>
  
  <pre><code>    void testIndex(File indexDir, File testDir, Set&lt;String&gt;NEWSGROUPS)
              throws IOException, FileNotFoundException, ParseException {
              Directory fsDir = FSDirectory.open(indexDir);
              DirectoryReader reader = DirectoryReader.open(fsDir);
              IndexSearcher searcher = new IndexSearcher(reader);
              Analyzer analyzer = new StandardAnalyzer(VERSION);
              System.out.print("inside testIndex");
              int[][] confusionMatrix
                  = new int[NEWSGROUPS.size()][NEWSGROUPS.size()];
              String csvFilename = "/home/serene/Downloads/IndustryClassification/Test/Test.csv";
              CSVReader csvReader = new CSVReader(new FileReader(csvFilename), '\t');
              String[] row = null;
              while((row = csvReader.readNext()) != null) {
                  String companyname = row[1];
                  String NAICSID = row[2];
                  String description = row[4];
  
                  Query query = new QueryParser(Version.LUCENE_44,"contents",analyzer).parse(QueryParser.escape(description));
  
                  System.out.print(query +"\n");
                  TopDocs hits = searcher.search(query,3);
                  ScoreDoc[] scoreDocs = hits.scoreDocs;
                  System.out.println(hits.totalHits);
                  for (int n = 0; n &lt; scoreDocs.length; ++n) {
                      ScoreDoc sd = scoreDocs[n];
                      int docId = sd.doc;
                      Document d = searcher.doc(docId);
                      String category = d.get("category");
                      System.out.println(category);
                  }
              }
              csvReader.close();   
      }
  </code></pre>