最近在学习Lucene全文检索,我检索的对象是一个文档库,主要检索里面的内容,要是有符合我所设置的关键字的文档,就将文档名称列出来,我已写好一个例子,但是当我输入英文的时候,可以检索,输入中午时就不行了。我用的是Lucene2.3.2。大家有什么好的解决办法吗?

解决方案 »

  1.   

    楼主去下一个极易分词器 je-analysis-1.5.1.jar
    换成
    Analyzer zh2 = new MMAnalyzer(); // 词库分词
      

  2.   

    你用的是哪个分词器,我用的是
    StandardAnalyzer standardAnalyzer=new StandardAnalyzer(Version.LUCENE_30);
    没问题的啊
      

  3.   

    我用的是StandardAnalyzer,但你括号的(Version.LUCENE_30);这个lucene2.3.2中没有吧?我把代码贴下吧:
     public int createDateBase(File file){//创建索引
     int returnValue=0;
     if(!file.isDirectory()){
     file.mkdirs();
     }
     try {
    IndexWriter indexWriter=new IndexWriter(file,new StandardAnalyzer(),true);
    indexWriter.close();
    returnValue=1;
    } catch (Exception e) {
    e.printStackTrace();

     return returnValue;
     }
    public int insertRecord(String dbpath,File file){
    int returnValue=0;
    try {
    IndexWriter indexWriter=new IndexWriter(dbpath,new StandardAnalyzer(),false);
    this.addFile(indexWriter,file);
    returnValue=1;
    } catch (Exception e) {
    e.printStackTrace();
    }
    return returnValue;

    }
    public ArrayList queryRecords(String searchkey,String dbpath,String searchField){
    ArrayList list=null;
    try {
    IndexSearcher searcher=new IndexSearcher(dbpath);
    Hits hits=null;//是用来保存搜索的结果的。
    Query query=null;
    QueryParser queryParser=new QueryParser(searchField,new StandardAnalyzer());
    query=queryParser.parse(searchkey);
    hits=searcher.search(query);
    if(hits!=null){
    list=new ArrayList();
    int hitLength=hits.length();
    Document doc =null;
    for(int i=0;i<hitLength;i++){
    doc=hits.doc(i);
    list.add(doc.get("filePath"));
    }
    }
    } catch (Exception e) {
    e.printStackTrace();

    return list;

    }
      

  4.   

    少了这个方法
    public int insertRecord(String dbpath,String filePath){
    return this.insertRecord(dbpath, new File(filePath));
    } private void addFile(IndexWriter indexWriter, File file) {
    Document doc=new Document();
    try{
    doc.add(new Field("filePath",file.getAbsolutePath(),Field.Store.YES,Field.Index.TOKENIZED));
    doc.add(new Field("contents", new FileReader(file)));
    indexWriter.addDocument(doc);
    indexWriter.close();
    }catch(Exception e){
    e.printStackTrace();
    }
    }
      

  5.   

    我把所有的StandardAnalyzer换成了MMAnalyzer,但还是不行
      

  6.   

    用IK分词器吧
    而且你的lucene版本有点低 性能也不会太好
    http://85600367.javaeye.com/admin/blogs/855535
    这是我跑过的例子 你可以改一下 
      

  7.   

    建议楼主看一下这篇文章。
    http://www.javaeye.com/topic/839504这位牛人给了一个例子。中英文都能检索到。
      

  8.   

    跟楼主一样,我最近也在研究这玩意儿,官网上最新版本是:3.0.3的。
    我自己写了个demo,也不好使,纠结。