lucene可以放到android中使用吗?如果需要修改lucene源码,要怎么改呢?我用lucene写了一个放在android平板上的搜索器,可是不报错,但也不运行,这是怎么回事?有谁会改吗?package android.search;import java.io.File;    import java.io.FileReader;import java.io.IOException;import org.apache.lucene.analysis.standard.StandardAnalyzer;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.index.CorruptIndexException;import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.queryParser.ParseException;import org.apache.lucene.queryParser.QueryParser;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.Query;import org.apache.lucene.search.ScoreDoc;import org.apache.lucene.search.TopDocs;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;import org.apache.lucene.store.LockObtainFailedException;import org.apache.lucene.util.Version;    import android.app.Activity;    import android.os.Bundle;    import android.os.Environment;  import android.util.Log;  import android.view.View;    import android.view.View.OnClickListener;    import android.widget.Button;    import android.widget.EditText;    import android.widget.TextView;    import android.widget.Toast;    // extends Activtiy     //implements OnClickListener 实现click方法    public class AndroidsearchActivity extends Activity implements OnClickListener {        /** Called when the activity is first created. */                private File file;  //文件对象      private String path;  //路径      private String info;  //目标文件所在路径      private String key; //关键字        private TextView result; // 显示结果        private EditText et; // 编辑view        private Button search_btn; // button view                @Override        public void onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);  //创建程序          setContentView(R.layout.main);  //导入main。xml                      result = (TextView)findViewById(R.id.TextView_Result);  //结果          et = (EditText)findViewById(R.id.key);  //关键词          search_btn = (Button)findViewById(R.id.button_search); // 按键          //file = new File(Environment.getExternalStorageDirectory().getPath());           // file = new File("/mnt/");  //确定搜索的路径          info = getString(R.string.info);  //将String.xml中的“目标文件所在路径”这就话传给info          search_btn.setOnClickListener(this);//设置监听        }            /* (non-Javadoc)       * @see android.view.View.OnClickListener#onClick(android.view.View)       */        public void onClick(View v) { //点击按钮此程序运行                 // TODO Auto-generated method stub        StringBuffer sb = new StringBuffer();        path = "";         //path付初值为空          result.setText("");  //将结果显示设为空白               key = et.getText().toString();  //将从文本框中得到的文件名转换为String型              index();  //运行BrowserFile方法          search(sb);        result.setText(sb);    }        public void index(){IndexWriter indexwriter = null;Directory directory;try {directory = FSDirectory.open(new File("/mnt/sdcard/kankan/"));//将索引创建在平板电脑的/mnt/sdcard/kankan/目录下IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_35,new StandardAnalyzer(Version.LUCENE_35));indexwriter = new IndexWriter(directory,iwc);Document document = null;File file = new File("/mnt/sdcard/kankan/");//确定搜索路径for(File files:file.listFiles()){document=new Document();document.add(new Field("content",new FileReader(file)));document.add(new Field("file",files.getName(),Field.Store.YES,Field.Index.ANALYZED));document.add(new Field("path",files.getPath(),Field.Store.YES,Field.Index.ANALYZED));if(indexwriter!=null)indexwriter.close();}} catch (IOException e2) {// TODO Auto-generated catch blocke2.printStackTrace();}}public StringBuffer search(StringBuffer sb){Directory directory;try {directory = FSDirectory.open(new File("/mnt/sdcard/kankan/"));//打开索引IndexReader indexreader;indexreader = IndexReader.open(directory);IndexSearcher indexsearcher = new IndexSearcher(indexreader);QueryParser queryparser = new QueryParser(Version.LUCENE_35,"content",new StandardAnalyzer(Version.LUCENE_35));Query query;query = queryparser.parse("ads");TopDocs tds;tds = indexsearcher.search(query, 20);ScoreDoc[] sds= tds.scoreDocs;for(ScoreDoc sd:sds){Document d;d = indexsearcher.doc(sd.doc);sb.append(d.get("filename")+"["+d.get("path")+"]");}indexreader.close();} catch (IOException e4) {// TODO Auto-generated catch blocke4.printStackTrace();} catch (ParseException e) {// TODO Auto-generated catch blocke.printStackTrace();}return sb;}}  

更多相关文章

  1. Android(安卓)activity属性设置大全
  2. Android(安卓)ADB server didn't ACK * failed to start daemon
  3. android 学习基础篇---开发环境的搭建 Eclipse SDK jdk ADT
  4. 1.2 Android(安卓)开发环境搭建
  5. Android(安卓)保存文件路径
  6. Android(安卓)NDK报错(Eclipse)及解决方法
  7. 在Windows系统中使用NDK编译Android二进制文件并运行
  8. 一键解决Ubuntu下安装Eclipse Android/C/C++ 开发环境
  9. Android原生运行uniapp使用5+app创建项目时的SDK集成步骤(一)

随机推荐

  1. Android之简易电话 & 短信
  2. Android复习(九)
  3. sd卡相关
  4. android保存图片到图库
  5. Android(安卓)NoTitle 不显示标题
  6. android console 常见信息
  7. android 小米时钟的实现
  8. android download file and save to sdCa
  9. Android特有的数据结构分析
  10. (Android)处理图片成圆形