how to lucene serch in android
Posted
by
xyz Sad
on Stack Overflow
See other posts from Stack Overflow
or by xyz Sad
Published on 2011-11-26T09:46:10Z
Indexed on
2011/11/26
9:52 UTC
Read the original article
Hit count: 237
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???..
© Stack Overflow or respective owner