Search in sources :

Example 66 with PrefixQuery

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);
}
Also used : PrefixQuery(org.apache.lucene.search.PrefixQuery) Term(org.apache.lucene.index.Term)

Example 67 with PrefixQuery

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));
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) PrefixQuery(org.apache.lucene.search.PrefixQuery) Term(org.apache.lucene.index.Term) Contact(com.zimbra.cs.mailbox.Contact) ParsedContact(com.zimbra.cs.mime.ParsedContact) Test(org.junit.Test)

Example 68 with PrefixQuery

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;
}
Also used : PrefixQuery(org.apache.lucene.search.PrefixQuery) Term(org.apache.lucene.index.Term)

Aggregations

PrefixQuery (org.apache.lucene.search.PrefixQuery)68 Term (org.apache.lucene.index.Term)62 BooleanQuery (org.apache.lucene.search.BooleanQuery)34 Query (org.apache.lucene.search.Query)30 TermQuery (org.apache.lucene.search.TermQuery)29 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)27 WildcardQuery (org.apache.lucene.search.WildcardQuery)23 BoostQuery (org.apache.lucene.search.BoostQuery)20 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)19 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)15 Document (org.apache.lucene.document.Document)14 IndexSearcher (org.apache.lucene.search.IndexSearcher)14 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)14 PhraseQuery (org.apache.lucene.search.PhraseQuery)14 RegexpQuery (org.apache.lucene.search.RegexpQuery)13 TopDocs (org.apache.lucene.search.TopDocs)13 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)12 IndexReader (org.apache.lucene.index.IndexReader)11 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)11 Field (org.apache.lucene.document.Field)10