1 17 package org.apache.servicemix.jbi.audit.lucene; 18 19 import java.io.IOException ; 20 21 import org.apache.lucene.analysis.standard.StandardAnalyzer; 22 import org.apache.lucene.document.Document; 23 import org.apache.lucene.queryParser.ParseException; 24 import org.apache.lucene.queryParser.QueryParser; 25 import org.apache.lucene.search.Hits; 26 import org.apache.lucene.search.IndexSearcher; 27 import org.apache.lucene.search.Query; 28 29 35 public class DefaultLuceneCallback implements LuceneCallback { 36 private String field; 37 private String query; 38 39 public DefaultLuceneCallback(String field, String query) { 40 this.field = field; 41 this.query = query; 42 } 43 44 public Object doCallback(IndexSearcher is) throws IOException { 45 try { 46 Query queryObj = QueryParser.parse(query, field, new StandardAnalyzer()); 47 Hits hits = is.search(queryObj); 48 int total = hits.length(); 49 String [] ids = new String [total]; 50 for (int i = 0; i < total; i++) { 51 Document d = hits.doc(i); 52 ids[i] = d.get("org.apache.servicemix.exchangeid"); 53 } 54 return ids; 55 } catch (ParseException pe) { 56 return new String [0]; 57 } 58 } 59 60 } 61 | Popular Tags |