/**
   * Test method for {@link
   * org.talend.dataquality.standardization.record.SynonymRecordSearcher#addSearcher(org.talend.dataquality.standardization.index.SynonymIndexSearcher,
   * int)} .
   */
  @Test
  public void testAddSearcher() {
    SynonymRecordSearcher recSearcher = new SynonymRecordSearcher(2);
    try {
      recSearcher.addSearcher(null, 0);
    } catch (Exception e) {
      Assert.assertNotNull("we should get an exception here", e);
    }
    try {
      recSearcher.addSearcher(new SynonymIndexSearcher(), 2);
      Assert.fail(
          "Index should be out of bounds here: trying to set a searcher at position in an empty array");
    } catch (Exception e) {
      Assert.assertNotNull("we should get an exception here", e);
    } catch (java.lang.AssertionError e) {
      Assert.assertNotNull(
          "we should get an assertion error here when -ea is added to the VM arguments", e);
    }

    try {
      SynonymIndexSearcher searcher = new SynonymIndexSearcher();
      recSearcher.addSearcher(searcher, 1);
    } catch (Exception e) {
      fail(e.getMessage());
    }

    try {
      SynonymIndexSearcher searcher = new SynonymIndexSearcher();
      recSearcher.addSearcher(searcher, -1);
    } catch (Exception e) {
      Assert.assertNotNull("we should get an exception here", e);
    }
  }
  public void testSearch(String[] record, int topDocLimit, int resultLimit) {
    SynonymRecordSearcher recSearcher = new SynonymRecordSearcher(record.length);
    for (int i = 0; i < record.length; i++) {
      initIdx(
          PluginUtil.getPluginInstallPath(HandLuceneImplTest.PLUGIN_ID).concat("data/idx")
              + (i + 1));
      SynonymIndexSearcher searcher =
          new SynonymIndexSearcher(
              PluginUtil.getPluginInstallPath(HandLuceneImplTest.PLUGIN_ID).concat("data/idx")
                  + (i + 1));
      searcher.setTopDocLimit(topDocLimit);
      recSearcher.addSearcher(searcher, i);
    }

    try {
      TopDocs topDocs;
      int hits = 1;
      for (int i = 0; i < record.length; i++) {
        topDocs = recSearcher.getSearcher(i).searchDocumentBySynonym(record[i]);
        hits *= topDocs.totalHits;
      }

      List<OutputRecord> results = recSearcher.search(resultLimit, record);
      Assert.assertNotNull(results);
      Assert.assertFalse(results.isEmpty());
      for (OutputRecord outputRecord : results) {
        Assert.assertNotNull(outputRecord);
        String[] resultingRecord = outputRecord.getRecord();
        Assert.assertEquals(record.length, resultingRecord.length);
        System.out.println(StringUtils.join(resultingRecord, '|'));
        System.out.println("\t" + outputRecord.getScore());
      }
      Assert.assertEquals(Math.min(hits, resultLimit), results.size());

      for (int i = 0; i < record.length; i++) {
        recSearcher.getSearcher(i).close();
      }
    } catch (ParseException e) {
      e.printStackTrace();
      fail("should not get an exception here");
    } catch (IOException e) {
      e.printStackTrace();
      fail("should not get an exception here");
    }
    System.out.println("");
  }