### Question:
NubIndex implements AutoCloseable { public List<NameUsageMatch> matchByName(String name, boolean fuzzySearch, int maxMatches) { final String analyzedName = LuceneUtils.analyzeString(analyzer, name).get(0); LOG.debug("Analyzed {} query \"{}\" becomes >>{}<<", fuzzySearch ? "fuzzy" : "straight", name, analyzedName); if (analyzedName.length() < 2) { return Lists.newArrayList(); } Term t = new Term(NubIndex.FIELD_CANONICAL_NAME, analyzedName); Query q; if (fuzzySearch) { q = new FuzzyQuery(t, analyzedName.length() > 10 ? 2 : 1, 1); } else { q = new TermQuery(t); } try { return search(q, name, fuzzySearch, maxMatches); } catch (RuntimeException e) { LOG.warn("Lucene failed to fuzzy search for name [{}]. Try a straight match instead", name); return search(new TermQuery(t), name, false, maxMatches); } } NubIndex(Directory d); static NubIndex newMemoryIndex(NameUsageMapper mapper); static NubIndex newMemoryIndex(Iterable<NameUsageMatch> usages); static NubIndex newFileIndex(File indexDir, NameUsageMapper mapper, UUID nubDatasetKey); NameUsageMatch matchByUsageId(Integer usageID); List<NameUsageMatch> matchByName(String name, boolean fuzzySearch, int maxMatches); @Override void close();  }### Answer:
@Test public void testMatchByName() throws Exception { final Integer abiesAlbaKey = 7; NameUsageMatch m = index.matchByUsageId(abiesAlbaKey); assertEquals(abiesAlbaKey, m.getUsageKey()); assertEquals("Abies alba Mill.", m.getScientificName()); assertEquals(Rank.SPECIES, m.getRank()); assertFalse(m.isSynonym()); assertNull(m.getAcceptedUsageKey()); m = index.matchByName("Abies alba", true, 2).get(0); assertEquals(abiesAlbaKey, m.getUsageKey()); m = index.matchByName("abies alba", true, 2).get(0); assertEquals(abiesAlbaKey, m.getUsageKey()); m = index.matchByName("Abbies alba", true, 2).get(0); assertEquals(abiesAlbaKey, m.getUsageKey()); m = index.matchByName("abyes alba", true, 2).get(0); assertEquals(abiesAlbaKey, m.getUsageKey()); m = index.matchByName(" apies alba", true, 2).get(0); assertEquals(abiesAlbaKey, m.getUsageKey()); m = index.matchByName("Abies alllbbbbaaa", true, 2).get(0); assertEquals(abiesAlbaKey, m.getUsageKey()); m = index.matchByName("Aebies allba", true, 2).get(0); assertEquals(abiesAlbaKey, m.getUsageKey()); assertTrue(index.matchByName("Obies alba", true, 2).isEmpty()); assertTrue(index.matchByName("Abies elba", false, 2).isEmpty()); m = index.matchByName("Picea abies", false, 2).get(0); assertTrue(m.isSynonym()); }