how to lucene serch in android
- by xyz Sad
Lucen with android logic ..???
public class TestAndroidLuceneActivity extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
try {
Directory directory = new RAMDirectory();
Analyzer analyzer = new StandardAnalyzer();
Document doc = new Document();
doc.add(new Field("header", "ABC", Field.Store.YES,Field.Index.TOKENIZED));
indexWriter.addDocument(doc);
doc.add(new Field("header", "DEF",
Field.Store.YES,Field.Index.TOKENIZED));
indexWriter.addDocument(doc);
doc.add(new Field("header", "GHI",
Field.Store.YES,Field.Index.TOKENIZED));
indexWriter.addDocument(doc);
doc.add(new Field("header", "JKL",
Field.Store.YES,Field.Index.TOKENIZED));
indexWriter.addDocument(doc);
indexWriter.optimize();
indexWriter.close();
IndexSearcher indexSearcher = new IndexSearcher(directory);
QueryParser parser = new QueryParser("header", analyzer);
// Query query = parser.parse("(" + "Anil" + ")");
Query query = parser.parse("(" + "ABC" + ")");
Hits hits = indexSearcher.search(query);
for (int i = 0; i < hits.length(); i++) {
Document hitDoc = hits.doc(i);
Log.i("TestAndroidLuceneActivity", "Lucene: " +hitDoc.get("header"));
// Toast.makeText(this, hitDoc.get("header"),Toast.LENGTH_LONG).show();
}
indexSearcher.close();
directory.close();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
i have this code but i m not able to understnd plz send me related or modifed and
set it main.xml show me some out put plzz..its does not serch after "ABC" plz tell me wat
is the problem in logic any thing missing???..