class LuceneHelper {

	public List<Integer> query(String query, String field, int n) {
		searcher = getSearcher();
		TopScoreDocCollector collector = TopScoreDocCollector.create(n, true);
		List<Integer> results = new ArrayList<Integer>();
		Query q = null;

		try {
			q = new QueryParser(Version.LUCENE_41, field, new StandardAnalyzer(
					Version.LUCENE_41)).parse("\"" + query + "\"");
		} catch (ParseException e) {
			logger.error("querying the index: {} ", e.toString());
			return results;
		}

		try {
			searcher.search(q, collector);
		} catch (IOException e) {
			logger.error("querying the index: {} ", e.toString());
			return results;
		}

		ScoreDoc[] hits = collector.topDocs().scoreDocs;
		for (int i = 0; i < hits.length; ++i) {
			int docId = hits[i].doc;
			results.add(getWikiId(docId));
		}

		logger.debug("query {} docs {}", query, results);
		return results;
	}

}

class LuceneHelperTest {

	static LuceneHelper helper;
	static File luceneDir;

	@Test
	public void testQuery() {

		List<Integer> results = helper.query("diego");
		assertEquals(3, results.size());
		Set<Integer> expected = new HashSet<Integer>();
		expected.add(1);
		expected.add(4);
		expected.add(5);

		assertEquals(expected, new HashSet<Integer>(results));

	}

}