public void testPrefixFilter() throws Exception { Filter prefixFilter = new PrefixFilter( new Term("category", "/technology/computers")); assertEquals("only /technology/computers/* books", 8, TestUtil.hitCount(searcher, allBooks, prefixFilter)); }
/** * Creates new prefix query. Depending on {@link getUseConstantScoreQuery()} * it's either {@link org.apache.lucene.search.ConstantScoreQuery} with * {@link org.apache.lucene.search.PrefixFilter} or just * {@link org.apache.lucene.search.PrefixQuery}. * @param term term * @return prefix query */ private Query newPrefixQuery(String fieldName, String term) { return this.getUseConstantScoreQuery()? new ConstantScoreQuery(new PrefixFilter(new Term(fieldName,term))): new PrefixQuery(new Term(fieldName,term)); }