买本<征服ajax+lucene>看看就知道了,要不过几天,我在我的blog上写一个简单的例子。

解决方案 »

  1.   


    /**
     * 单个文件增加索引
     * 
     * @param file  索引的文件
     * @param indexDir   索引输出目录
     * @throws IOException
     */
    public void fileIndex(String file,String indexDir) throws IOException{
    IndexWriter writer = null; 

    indexDir=FileUtil.dirCanUse(indexDir,outputDir);
    if(indexDir==null){
    return;
    }

    if(FileUtil.dirCanUse(file,outputDir)==null){
    System.out.println("..........."+file+" not found");
    return;
    }
    System.out.println(".......file...."+file);


    //用指定的语言分析器构造一个新的写索引器(第3个参数表示是否创建新索引) 
    try{
    writer = new IndexWriter(indexDir, analyzer, false);
    }catch( IOException e){
    //如果没有索引文件,则创建新索引
    writer = new IndexWriter(indexDir, analyzer, true);
    }

    //构造包含2个字段Field的Document对象           
    Document doc = new Document();
    //路径path字段,不索引,只存储
    Field fPath = new Field("path", file,Field.Store.YES,Field.Index.NO);


    doc.add(fPath);   

    //将文档写入索引      
    writer.addDocument(doc);       //关闭写索引器    
    writer.optimize();
    writer.close();
    }
      

  2.   

    上面的这一段判断可以不要
    indexDir=FileUtil.dirCanUse(indexDir,outputDir);
    if(indexDir==null){
    return;
    }

    if(FileUtil.dirCanUse(file,outputDir)==null){
    System.out.println("..........."+file+" not found");
    return;
    }
      

  3.   

    我最近也在看这个东西,但是下载了2.0的SRC包,怎么和Eclipse3.2结合在一起开发呀?
    看了一些文章,发现似乎在安装时都要在环境变量里写两个JAR包的位置,可我下的ZIP
    里面米有这两个包哦郁闷
    建立索引,分词和搜索我都有了一定的了解,就是不清楚怎么和Eclipse结合,哪位大侠
    帮我这只菜鸟下?
    [email protected]