lucene简单搜索demo 您所在的位置:网站首页 223-333 lucene简单搜索demo

lucene简单搜索demo

#lucene简单搜索demo| 来源: 网络整理| 查看: 265

方法类

package com.wxf.Test; import com.wxf.pojo.Goods; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.*; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import java.io.IOException; import java.nio.file.Paths; /** * @Auther: wxf * @Date: 2018/6/29 15:40 */ public class IndexCRUD { private Directory dir; { try { dir = FSDirectory.open(Paths.get( System.getProperty("user.dir")+"\\src\\main\\resources\\index")); } catch (IOException e) { e.printStackTrace(); } } /** * 获取IndexWriter实例 * @return * @throws Exception */ public IndexWriter getWriter()throws Exception{ //中文分词器 StandardAnalyzer standardAnalyzer = new StandardAnalyzer(); IndexWriterConfig iwc=new IndexWriterConfig(standardAnalyzer); IndexWriter writer=new IndexWriter(dir, iwc); return writer; } public void setUp() throws Exception { Goods goods=new Goods("123","红色强化门",360); Goods goods2=new Goods("223","黑色强化门",370); Goods goods3=new Goods("333","白色强化门",380); String skuid[]={"123","223","333"}; String name[]={"红色强化门","黑色强化门","白色强化门"}; Object obj[]={goods,goods2,goods3}; IndexWriter writer=getWriter(); for(int i=0;i


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有