zoukankan      html  css  js  c++  java
  • Lucene全文检索

      Lucene写入和更新操作:            
    if
    (id.equals("")) { 2 this.goodsService.save(goods); 3 4 String goods_lucene_path = System.getProperty("user.dir") 5 + File.separator + "luence" + File.separator + "goods"; 6 File file = new File(goods_lucene_path); 7 if (!file.exists()) { 8 CommUtil.createFolder(goods_lucene_path); 9 } 10 LuceneVo vo = new LuceneVo(); 11 vo.setVo_id(goods.getId()); 12 vo.setVo_title(goods.getGoods_name()); 13 vo.setVo_content(goods.getGoods_details()); 14 vo.setVo_type("goods"); 15 vo.setVo_store_price(CommUtil.null2Double(goods 16 .getStore_price())); 17 vo.setVo_add_time(goods.getAddTime().getTime()); 18 vo.setVo_goods_salenum(goods.getGoods_salenum()); 19 LuceneUtil lucene = LuceneUtil.instance(); 20 LuceneUtil.setIndex_path(goods_lucene_path); 21 lucene.writeIndex(vo); 22 } else { 23 this.goodsService.update(goods); 24 25 String goods_lucene_path = System.getProperty("user.dir") 26 + File.separator + "luence" + File.separator + "goods"; 27 File file = new File(goods_lucene_path); 28 if (!file.exists()) { 29 CommUtil.createFolder(goods_lucene_path); 30 } 31 LuceneVo vo = new LuceneVo(); 32 vo.setVo_id(goods.getId()); 33 vo.setVo_title(goods.getGoods_name()); 34 vo.setVo_content(goods.getGoods_details()); 35 vo.setVo_type("goods"); 36 vo.setVo_store_price(CommUtil.null2Double(goods 37 .getStore_price())); 38 vo.setVo_add_time(goods.getAddTime().getTime()); 39 vo.setVo_goods_salenum(goods.getGoods_salenum()); 40 LuceneUtil lucene = LuceneUtil.instance(); 41 LuceneUtil.setIndex_path(goods_lucene_path); 42 lucene.update(CommUtil.null2String(goods.getId()), vo); 43 }
         Lucene查询:

       LuceneResult pList = lucene.search(keyword, CommUtil.null2Int(currentPage), CommUtil.null2Int(store_price_begin), CommUtil.null2Int(store_price_end), null, sort); for (LuceneVo vo : pList.getVo_list()) { Goods goods = this.goodsService.getObjById(vo.getVo_id()); pList.getGoods_list().add(goods); } CommUtil.saveLucene2ModelAndView("goods", pList, mv);
        
    public static void saveLucene2ModelAndView(String type, LuceneResult pList, ModelAndView mv)
       {
         if (pList != null) {
           if (type.equals("goods")) {
             mv.addObject("objs", pList.getGoods_list());
           }
           if (type.equals("store")) {
             mv.addObject("objs", pList.getStore_list());
           }
           mv.addObject("totalPage", Integer.valueOf(pList.getPages()));
           mv.addObject("pageSize", Integer.valueOf(pList.getPageSize()));
           mv.addObject("rows", Integer.valueOf(pList.getRows()));
           mv.addObject("currentPage", new Integer(pList.getCurrentPage()));
           mv.addObject(
             "gotoPageFormHTML", 
             showPageFormHtml(pList.getCurrentPage(), 
             pList.getPages()));
         }
       }
  • 相关阅读:
    常用函数
    PostgreSql那点事(文件读取写入、命令执行的办法)
    如何检测Windows中的横向渗透攻击
    小米笔记本pro版bios经常找不到硬盘
    grunt教程
    nodejs廖雪峰大神教程
    ClickOnce是什么?如何使用?
    asp.net中的ORA-12154: TNS: 无法解析指定的连接标识符
    未能加载文件或程序集 ICSharpCode.SharpZipLib
    PL/SQL 循环
  • 原文地址:https://www.cnblogs.com/beyang/p/5909173.html
Copyright © 2011-2022 走看看