use of org.apache.lucene.search.PrefixQuery in project ansj_seg by NLPchina.
the class AppTest method main.
public static void main(String[] args) throws IOException {
// Set<String> filter = new HashSet<String>() ;
//
// BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("/home/ansj/公共的/stopLibrary.dic"))) ;
//
// String temp = null ;
//
// while((temp=br.readLine())!=null){
// filter.add(temp) ;
// }
//
// StringReader reader = new StringReader("龙虎胶囊 6 * 7cm") ;
// Tokenizer tokenizer = new AnsjTokenizer(new IndexAnalysis(reader), reader, filter, false);
// while(tokenizer.incrementToken()){
// CharTermAttribute attribute = tokenizer.getAttribute(CharTermAttribute.class) ;
// System.out.println(attribute);
// }
PrefixQuery pq = new PrefixQuery(new Term("name", "中国"));
System.out.println(pq);
}
use of org.apache.lucene.search.PrefixQuery in project zm-mailbox by Zimbra.
the class AbstractIndexStoreTest method prefixQuery.
@Test
public void prefixQuery() throws Exception {
ZimbraLog.test.debug("--->TEST prefixQuery");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Contact contact1 = createContact(mbox, "a", "bc", "abc@zimbra.com");
Contact contact2 = createContact(mbox, "a", "bcd", "abcd@zimbra.com");
createContact(mbox, "x", "Y", "xy@zimbra.com");
createContact(mbox, "x", "Yz", "x.Yz@zimbra.com");
// Make sure all indexing has been done
mbox.index.indexDeferredItems();
IndexStore index = mbox.index.getIndexStore();
ZimbraIndexSearcher searcher = index.openSearcher();
ZimbraTopDocs result = searcher.search(new PrefixQuery(new Term(LuceneFields.L_CONTACT_DATA, "ab")), 100);
Assert.assertNotNull("searcher.search result object - searching for 'ab' prefix", result);
ZimbraLog.test.debug("Result for search for 'ab'\n" + result.toString());
Assert.assertEquals("Number of hits searching for 'ab' prefix", 2, result.getTotalHits());
String contact1Id = String.valueOf(contact1.getId());
String contact2Id = String.valueOf(contact2.getId());
String match1Id = getBlobIdForResultDoc(searcher, result, 0);
String match2Id = getBlobIdForResultDoc(searcher, result, 1);
ZimbraLog.test.debug("Contact1ID=%s Contact2ID=%s match1id=%s match2id=%s", contact1Id, contact2Id, match1Id, match2Id);
if (contact1Id.equals(match1Id)) {
Assert.assertEquals("2nd match isn't contact2's ID", contact2Id, match2Id);
} else if (contact1Id.equals(match2Id)) {
Assert.assertEquals("2nd match isn't contact1's ID", contact2Id, match1Id);
} else {
Assert.fail(String.format("Contact 1 ID [%s] doesn't match either [%s] or [%s]", contact1Id, match1Id, match2Id));
}
}
use of org.apache.lucene.search.PrefixQuery in project exhibitor by soabase.
the class QueryBuilder method pathPrefix.
public QueryBuilder pathPrefix(String pathPrefix) {
Term term = new Term(FieldNames.PATH, pathPrefix);
queries.add(new PrefixQuery(term));
return this;
}
Aggregations