@Test public void testHint() { AutoComplete ac = new AutoComplete(); ac.feed("张艺兴", 5000); ac.feed("张艺谋", 3000); ac.feed("张三", 500); assertEquals(ac.hint("张", 10), new LinkedHashSet<String>() {{ add("张艺兴"); add("张艺谋"); add("张三"); }}); assertEquals(ac.hint("张艺", 10), new LinkedHashSet<String>() {{ add("张艺兴"); add("张艺谋"); }}); }
public Set<String> hint(String prefix, long count) { String key = "auto_complete:" + prefix; return client.zrevrange(key, 0, count - 1); }
AutoComplete { public Set<String> hint(String prefix, long count) { String key = "auto_complete:" + prefix; return client.zrevrange(key, 0, count - 1); } }
AutoComplete { public Set<String> hint(String prefix, long count) { String key = "auto_complete:" + prefix; return client.zrevrange(key, 0, count - 1); } AutoComplete(); }
AutoComplete { public Set<String> hint(String prefix, long count) { String key = "auto_complete:" + prefix; return client.zrevrange(key, 0, count - 1); } AutoComplete(); void feed(String keyword, double weight); Set<String> hint(String prefix, long count); }
AutoComplete { public Set<String> hint(String prefix, long count) { String key = "auto_complete:" + prefix; return client.zrevrange(key, 0, count - 1); } AutoComplete(); void feed(String keyword, double weight); Set<String> hint(String prefix, long count);  }