private void unlockIndex(String indexLocation) {
   if (IndexReader.indexExists(indexLocation)) {
     try {
       if (IndexReader.isLocked(indexLocation)) {
         Directory directory = FSDirectory.getDirectory(indexLocation);
         IndexReader.unlock(directory);
       }
     } catch (IOException e) {
       log.fatal("Error trying to unlock " + indexLocation + " index.", e);
     }
   }
 }
  private List getHitIds(Query query) throws IOException {
    ArrayList matchIds = new ArrayList();
    LinkedHashSet matchIdsSet = new LinkedHashSet();
    if (query != null) {
      if (r != null) {
        if (!r.isCurrent()) {
          while (r.isLocked(dir)) ;
          r = IndexReader.open(dir);
          searcher = new IndexSearcher(r);
        }
      } else {
        r = IndexReader.open(dir);
        searcher = new IndexSearcher(r);
      }
      DocumentCollector s = new DocumentCollector(searcher);
      searcher.search(query, s);
      //            searcher.search(query);
      searcher.close();
      List hits = s.getStudies();
      for (int i = 0; i < hits.size(); i++) {
        Document d = (Document) hits.get(i);
        Field authority = d.getField("authority");
        String authorityStr = authority.stringValue();
        Field studyId = d.getField("studyId");
        String studyIdStr = studyId.stringValue();
        /*
        if (studyIdStr.length() < 5) {
            StringBuffer pad = new StringBuffer();
            for (int j = studyIdStr.length(); j < 5; j++) {
                pad.append('0');
            }
            studyIdStr = pad.toString() + studyIdStr;

        }
         */
        //                Long studyIdLong = Long.valueOf(studyIdStr);
        String fileName = authorityStr + File.separator + studyIdStr;
        //                System.out.println(fileName);
        matchIdsSet.add(fileName);
      }
      searcher.close();
    }
    matchIds.addAll(matchIdsSet);
    return matchIds;
  }