http://zm603380946.iteye.com/blog/1827318

完全个人理解,如有更好的方法,欢迎一起讨论

LuceneUtils.java

package com.zbiti.lucene;

import java.io.File;

import java.io.IOException;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Set;

import net.sf.json.JSONArray;

import net.sf.json.JSONObject;

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.IndexWriter;

import org.apache.lucene.index.IndexWriterConfig;

import org.apache.lucene.index.Term;

import org.apache.lucene.index.IndexWriter.MaxFieldLength;

import org.apache.lucene.queryParser.MultiFieldQueryParser;

import org.apache.lucene.queryParser.ParseException;

import org.apache.lucene.queryParser.QueryParser;

import org.apache.lucene.search.CachingWrapperFilter;

import org.apache.lucene.search.Filter;

import org.apache.lucene.search.IndexSearcher;

import org.apache.lucene.search.Query;

import org.apache.lucene.search.QueryWrapperFilter;

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 org.wltea.analyzer.lucene.IKAnalyzer;

import com.zbiti.util.sys.JsonUtils;

/**

* Lucene 辅助类

* @author 张明

*

*/

public class LuceneUtils {

//读取数据放入的地址

private static String IndexPath = "C:\\update\\index";

static Directory dir = null;

//初始化静态代码块

static{

try {

dir = FSDirectory.open(new File(IndexPath));

} catch (IOException e) {

e.printStackTrace();

}

}

/**

* 创建本地文件

* @param list 传递过来的数据是一个list

* @throws Exception

*/

public static boolean createData(List<Information> list){

try {

Directory dir =FSDirectory.open(new File(IndexPath));

IndexWriterConfig writerConfig=new IndexWriterConfig(Version.LUCENE_36, new IKAnalyzer());

//设置每次创建都重新创建

writerConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE);

IndexWriter writer = new IndexWriter(dir, writerConfig) ;

//循环处理将数据放入Lucene中

for(int i=0; i< list.size(); i++){

Information information = list.get(i);

Document doc = new Document();

//设置字段

setField(information, doc);

writer.addDocument(doc);

}

//提交

writer.optimize();

writer.commit();

writer.close();

return true;

} catch (CorruptIndexException e) {

e.printStackTrace();

return false;

} catch (LockObtainFailedException e) {

e.printStackTrace();

return false;

} catch (IOException e) {

e.printStackTrace();

return false;

}

}

/**

* 创建一条数据

* @param information 一条数据,传送过来的数据必须是完整的数据

* @return

*/

public static boolean createData(Information information){

try {

Directory dir =FSDirectory.open(new File(IndexPath));

IndexWriterConfig writerConfig=new IndexWriterConfig(Version.LUCENE_36, new IKAnalyzer());

IndexWriter writer = new IndexWriter(dir, writerConfig);

Document doc = new Document();

//设置字段

setField(information, doc);

writer.addDocument(doc);

writer.optimize();

writer.commit();

writer.close();

return true;

} catch (CorruptIndexException e) {

e.printStackTrace();

return false;

} catch (LockObtainFailedException e) {

e.printStackTrace();

return false;

} catch (IOException e) {

e.printStackTrace();

return false;

}

}

/**

* 更新一条信息

* @param information 根据bjStorageId的唯一性来更新数据

* 传送过来的数据必须是完整的数据,Lucene的更新不同于sql更新,更新是一天信息的完整更新

* @return

*/

public static boolean updateData(Information information){

try {

Directory dir =FSDirectory.open(new File(IndexPath));

//第三个参数代表更新的时候不重新创建原本的数据

IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(Version.LUCENE_CURRENT), false, MaxFieldLength.UNLIMITED);

Document doc = new Document();

//设置字段

setField(information, doc);

Term term = new Term("bjStorageId",information.getBjStorageId().toString());

writer.updateDocument(term,doc);

writer.optimize();

writer.commit();

writer.close();

return true;

} catch (CorruptIndexException e) {

e.printStackTrace();

return false;

} catch (LockObtainFailedException e) {

e.printStackTrace();

return false;

} catch (IOException e) {

e.printStackTrace();

return false;

}

}

/**

* 删除一条数据

* @return 根据bjStorageId的唯一性来删除数据

*/

public static boolean deleteData(String bjStorageId){

try {

Directory dir =FSDirectory.open(new File(IndexPath));

//第三个参数代表更新的时候不重新创建原本的数据

IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(Version.LUCENE_CURRENT), false, MaxFieldLength.UNLIMITED);

Term term = new Term("bjStorageId", bjStorageId);

writer.deleteDocuments(term);

writer.optimize();

writer.commit();

writer.close();

return true;

} catch (CorruptIndexException e) {

e.printStackTrace();

return false;

} catch (LockObtainFailedException e) {

e.printStackTrace();

return false;

} catch (IOException e) {

e.printStackTrace();

return false;

}

}

/**

* 查询数据

* @param searchStr 即将要查询的字符串

* @param fieldStr 需要查询的字段数组

* @param flag   是否统计标志

* @param groupStr 分组字段数组

* @param flagAcc 是否根据条件精确查询

* @param mapFilter查询条件

* @return

*/

public static Map<String,Object> getDataList(String
searchStr, String[] fieldArray, boolean flag, String[] groupArray,
boolean flagAcc, Map<String,Object> mapFilter){

try {

IndexSearcher search = new IndexSearcher(dir);

System.out.println("lucene中的数据总数为:------->>>" + search.maxDoc());

QueryParser qp=new MultiFieldQueryParser(Version.LUCENE_36, fieldArray, new IKAnalyzer());

Query query=qp.parse(searchStr);

//一次查询多少个结果

//TopDocs tDocs=search.search(query,1000000);

TopDocs tDocs = null;

//是否二次查询,根据多条件精确查找

if(flagAcc){

LuceneFilter luceneFilter = new LuceneFilter();

Set<String> keySet = mapFilter.keySet();

for (String key : keySet)

luceneFilter.addFilter(key, mapFilter.get(key).toString());

query=luceneFilter.getFilterQuery(query);//结果过滤

tDocs = search.search(query,1000000);

}else{

tDocs=search.search(query,1000000);

}

int numTotalHits = tDocs.totalHits;

System.out.println("lucene中的搜索出来的数据总数为:------->>>" + numTotalHits);

Map<String,Object> map = new HashMap<String,Object>();

map.put("information", tDocs);

map.put("search", search);

//是否同时查询分组统计数据

if(flag){

for(int j=0; j < groupArray.length; j++){

JSONArray jsonArr = new JSONArray();

JSONObject jsonObj = new JSONObject();

Map<String,Object> groupMap = getDataByGroupBy(search, query, groupArray[j]);

Set<String> keySet = groupMap.keySet();

for (String key : keySet) {

jsonObj.put("id",key);

jsonObj.put("count", groupMap.get(key));

jsonArr.add(jsonObj);

}

map.put(groupArray[j],jsonArr);

}

}

//解析数据

// Document doc = null;

// for(int i=0; i<numTotalHits; i++){

// int  k = tDocs.scoreDocs[i].doc ; //文档内部编号

// doc = search.doc(k);

// System.out.println(doc.get("name") +"--" + doc.get("id") + "-----" + doc.get("type") + "---" + doc.get("testField"));

// }

// search.close();

return map;

} catch (CorruptIndexException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} catch (ParseException e) {

e.printStackTrace();

}

return null;

}

/**

* 根据field指定的字段来进行分组统计总数

* @param search

* @param query

* @param field

*/

public static Map<String,Object> getDataByGroupBy(IndexSearcher search, Query query, String field){

try {

GroupCollector myCollector = new GroupCollector();

myCollector.setF(field);

search.search(query, myCollector);

GroupField gf = myCollector.getGroupField();

List<String> values = gf.getValues();

//读取数据

Map<String,Object> map = new HashMap<String,Object>();

for (String value : values) {

map.put(value, gf.getCountMap().get(value));

}

return map;

} catch (IOException e) {

e.printStackTrace();

return null;

}

}

/**

  * 设置字段信息

  * @param information

  * NOT_ANALYZED不支持模糊查找, ANALYZED支持模糊查找

  */

public static void setField(Information information, Document doc){

doc.add(new Field("actualStorageId",
information.getActualStorageId()!=null?information.getActualStorageId().toString():"",
Field.Store.YES, Field.Index.NOT_ANALYZED));

doc.add(new Field("deviceId",
information.getDeviceId()!=null?information.getDeviceId().toString():"",
Field.Store.YES, Field.Index.NOT_ANALYZED));

doc.add(new Field("brandId",
information.getBrandId()!=null?information.getBrandId().toString():"",
Field.Store.YES, Field.Index.NOT_ANALYZED));

doc.add(new Field("netId",
information.getNetId()!=null?information.getNetId().toString():"",
Field.Store.YES, Field.Index.NOT_ANALYZED));

doc.add(new Field("bjSpecialtyId",
information.getBjSpecialtyId()!=null?information.getBjSpecialtyId().toString():"",
Field.Store.YES, Field.Index.NOT_ANALYZED));

doc.add(new Field("deviceType",
information.getDeviceType()!=null?information.getDeviceType().toString():"",
Field.Store.YES, Field.Index.NOT_ANALYZED));

doc.add(new Field("bjStorageId",
information.getBjStorageId()!=null?information.getBjStorageId().toString():"",
Field.Store.YES, Field.Index.NOT_ANALYZED));

doc.add(new Field("bjType",
information.getBjType()!=null?information.getBjType().toString():"",
Field.Store.YES, Field.Index.NOT_ANALYZED));

doc.add(new Field("state1Cd",
information.getState1Cd()!=null?information.getState1Cd().toString():"",
Field.Store.YES, Field.Index.NOT_ANALYZED));

doc.add(new Field("state2Cd",
information.getState2Cd()!=null?information.getState2Cd().toString():"",
Field.Store.YES, Field.Index.NOT_ANALYZED));

doc.add(new Field("isStocktake",
information.getIsStocktake()!=null?information.getIsStocktake().toString():"",
Field.Store.YES, Field.Index.NOT_ANALYZED));

doc.add(new Field("shelfId",
information.getShelfId()!=null?information.getShelfId().toString():"",
Field.Store.YES, Field.Index.NOT_ANALYZED));

/*==================================================================================================================*/

doc.add(new Field("actualStorageRoom",
information.getActualStorageRoom()!=null?information.getActualStorageRoom().toString():"",
Field.Store.YES, Field.Index.ANALYZED));

doc.add(new Field("originalSerialNum",
information.getOriginalSerialNum()!=null?information.getOriginalSerialNum().toString():"",
Field.Store.YES, Field.Index.ANALYZED));

doc.add(new Field("deviceModel",
information.getDeviceModel()!=null?information.getDeviceModel().toString():"",
Field.Store.YES, Field.Index.ANALYZED));

doc.add(new Field("frontPic",
information.getFrontPic()!=null?information.getFrontPic().toString():"",
Field.Store.YES, Field.Index.ANALYZED));

doc.add(new Field("brandName",
information.getBrandName()!=null?information.getBrandName().toString():"",
Field.Store.YES, Field.Index.ANALYZED));

doc.add(new Field("netType",
information.getNetType()!=null?information.getNetType().toString():"",
Field.Store.YES, Field.Index.ANALYZED));

doc.add(new Field("netName",
information.getNetName()!=null?information.getNetName().toString():"",
Field.Store.YES, Field.Index.ANALYZED));

doc.add(new Field("specialtyName",
information.getSpecialtyName()!=null?information.getSpecialtyName().toString():"",
Field.Store.YES, Field.Index.ANALYZED));

doc.add(new Field("shelfCode",
information.getShelfName()!=null?information.getShelfName().toString():"",
Field.Store.YES, Field.Index.ANALYZED));

}

public static void main(String[] args) {

}

}

//辅助类

LuceneFilter.java

package com.zbiti.lucene;

import java.util.ArrayList;

import java.util.List;

import org.apache.lucene.index.Term;

import org.apache.lucene.search.Filter;

import org.apache.lucene.search.FilteredQuery;

import org.apache.lucene.search.Query;

import org.apache.lucene.search.QueryWrapperFilter;

import org.apache.lucene.search.TermQuery;

/**

* 条件辅助类

* @author 张明

*

*/

public class LuceneFilter {

private List<Filter> filterList;

    public LuceneFilter(){

        filterList = new ArrayList<Filter>();

    }

    public void addFilter(String Field,String Value){

        Term term=new Term(Field,Value);//添加term

        QueryWrapperFilter filter=new QueryWrapperFilter(new TermQuery(term));//添加过滤器

        filterList.add(filter);//加入List,可以增加多個过滤

    }

    public Query getFilterQuery(Query query){

        for(int i=0;i<filterList.size();i++){

            //取出多個过滤器,在结果中再次定位结果

            query = new FilteredQuery(query, filterList.get(i));

        }

        return query;

    }   

}

Information.java

package com.zbiti.lucene;

/**

* Bean

*

* @author 张明

*

*/

public class Information {

/**

* 实物库房ID(分组字段)

*/

private Integer actualStorageId;

/**

* 设备型号ID(分组字段)

*/

private Integer deviceId;

/**

* 品牌ID(分组字段)

*/

private Integer brandId;

/**

* 网元ID(分组字段)

*/

private Integer netId;

/**

* 专业ID(分组字段)

*/

private Integer bjSpecialtyId;

/**

* 设备类型(分组字段)

*/

private String deviceType;

/**

* 备件编号(分组字段)

*/

private Integer bjStorageId;

/** *******************区分字段******************* */

/**

* 备件类型(区分备件-BJ,送修件SXJ)(分组字段)

*/

private String bjType;

/**

* 资产库房备件状态(分组字段)

*/

private String state1Cd;

/**

* 实物库房备件状态(分组字段)

*/

private String state2Cd;

/**

* 是否已盘点(分组字段)

*/

private String isStocktake;

/**

* 网元类型(分组字段)

*/

private String netType;

/**

* 货架ID(分组字段)

*/

private Integer shelfId;

/*=======================================================*/

/**

* 实物库房

*/

private String actualStorageRoom;

/**

* 序列号(送修件原序列号)

*/

private String originalSerialNum;

/**

* 设备型号

*/

private String deviceModel;

/**

* 设备前图片

*/

private String frontPic;

/**

* 品牌名称

*/

private String brandName;

/**

* 网元名称

*/

private String netName;

/**

* 专业类别

*/

private String specialtyName;

/**

* 货架名称

*/

private String shelfName;

public Integer getBjStorageId() {

return bjStorageId;

}

public void setBjStorageId(Integer bjStorageId) {

this.bjStorageId = bjStorageId;

}

public Integer getActualStorageId() {

return actualStorageId;

}

public void setActualStorageId(Integer actualStorageId) {

this.actualStorageId = actualStorageId;

}

public String getActualStorageRoom() {

return actualStorageRoom;

}

public void setActualStorageRoom(String actualStorageRoom) {

this.actualStorageRoom = actualStorageRoom;

}

public String getOriginalSerialNum() {

return originalSerialNum;

}

public void setOriginalSerialNum(String originalSerialNum) {

this.originalSerialNum = originalSerialNum;

}

public String getState1Cd() {

return state1Cd;

}

public void setState1Cd(String state1Cd) {

this.state1Cd = state1Cd;

}

public String getState2Cd() {

return state2Cd;

}

public void setState2Cd(String state2Cd) {

this.state2Cd = state2Cd;

}

public String getIsStocktake() {

return isStocktake;

}

public void setIsStocktake(String isStocktake) {

this.isStocktake = isStocktake;

}

public Integer getDeviceId() {

return deviceId;

}

public void setDeviceId(Integer deviceId) {

this.deviceId = deviceId;

}

public String getDeviceModel() {

return deviceModel;

}

public void setDeviceModel(String deviceModel) {

this.deviceModel = deviceModel;

}

public String getDeviceType() {

return deviceType;

}

public void setDeviceType(String deviceType) {

this.deviceType = deviceType;

}

public String getFrontPic() {

return frontPic;

}

public void setFrontPic(String frontPic) {

this.frontPic = frontPic;

}

public Integer getBrandId() {

return brandId;

}

public void setBrandId(Integer brandId) {

this.brandId = brandId;

}

public String getBrandName() {

return brandName;

}

public void setBrandName(String brandName) {

this.brandName = brandName;

}

public Integer getNetId() {

return netId;

}

public void setNetId(Integer netId) {

this.netId = netId;

}

public String getNetType() {

return netType;

}

public void setNetType(String netType) {

this.netType = netType;

}

public String getNetName() {

return netName;

}

public void setNetName(String netName) {

this.netName = netName;

}

public Integer getBjSpecialtyId() {

return bjSpecialtyId;

}

public void setBjSpecialtyId(Integer bjSpecialtyId) {

this.bjSpecialtyId = bjSpecialtyId;

}

public String getSpecialtyName() {

return specialtyName;

}

public void setSpecialtyName(String specialtyName) {

this.specialtyName = specialtyName;

}

public Integer getShelfId() {

return shelfId;

}

public void setShelfId(Integer shelfId) {

this.shelfId = shelfId;

}

public String getShelfName() {

return shelfName;

}

public void setShelfName(String shelfName) {

this.shelfName = shelfName;

}

public String getBjType() {

return bjType;

}

public void setBjType(String bjType) {

this.bjType = bjType;

}

}

GroupField.java

package com.zbiti.lucene;

import java.util.ArrayList;

import java.util.Collections;

import java.util.Comparator;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

/**

*

* @author 张明

*

*/

public class GroupField {

// 所有可能的分组字段值,排序按每个字段值的文档个数大小排序

private List<String> values = new ArrayList<String>();

// 保存字段值和文档个数的对应关系

private Map<String, Integer> countMap = new HashMap<String, Integer>();

public Map<String, Integer> getCountMap() {

return countMap;

}

public void setCountMap(Map<String, Integer> countMap) {

this.countMap = countMap;

}

public List<String> getValues() {

Collections.sort(values, new ValueComparator());

return values;

}

public void setValues(List<String> values) {

    this.values = values;

}

public void addValue(String value) {

    if (value == null || "".equals(value))

        return;

    if (countMap.get(value) == null) {

        countMap.put(value, 1);

        values.add(value);

    }else{

        countMap.put(value, countMap.get(value) + 1);

    }

}

class ValueComparator implements Comparator<String> {

    public int compare(String value0, String value1) {

        if (countMap.get(value0) > countMap.get(value1)) {

            return -1;

        } else if (countMap.get(value0) < countMap.get(value1)) {

            return 1;

        }

        return 0;

    }

}

}

GroupCollector.java

package com.zbiti.lucene;

import java.io.IOException;

import org.apache.lucene.index.IndexReader;

import org.apache.lucene.search.Collector;

import org.apache.lucene.search.FieldCache;

import org.apache.lucene.search.Scorer;

/**

*

* @author 张明

*

*/

public class GroupCollector extends Collector{

// 保存分组统计结果

private GroupField groupField = new GroupField();

//fieldCache

    private String[] fieldCache;

    //统计字段

    private String field;

    String spliter;

    int length;

public void setFc(String[] fieldCache) {

        this.fieldCache = fieldCache;

    }

@Override

    public void setScorer(Scorer scorer) throws IOException {

    }

@Override

    public void setNextReader(IndexReader reader, int docBase)

            throws IOException {

    fieldCache = FieldCache.DEFAULT.getStrings(reader, field);

    }

@Override

    public void collect(int doc) throws IOException {

        // 添加的GroupField中,由GroupField负责统计每个不同值的数目

    groupField.addValue(fieldCache[doc]);

    }

@Override

    public boolean acceptsDocsOutOfOrder() {

        return true;

    }

public GroupField getGroupField() {

        return groupField;

    }

public void setSpliter(String spliter) {

        this.spliter = spliter;

    }

public void setLength(int length) {

        this.length = length;

    }

public void setF(String field) {

        this.field = field;

    }

}

//测试类

package com.zbiti.lucene;

import java.io.IOException;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import org.apache.lucene.document.Document;

import org.apache.lucene.index.CorruptIndexException;

import org.apache.lucene.search.IndexSearcher;

import org.apache.lucene.search.TopDocs;

public class TestLucene {
public static void main(String[] args) throws CorruptIndexException, IOException {

//创建

List<Information> list = new ArrayList<Information>();

for(int i=0; i< 10000; i++){

Information information = new Information();

information.setActualStorageId(i);

information.setDeviceId(i);

if(i<300)

information.setBrandId(8888);

else

information.setBrandId(7777);

if(i < 500)

information.setNetId(100);

else

information.setNetId(200);

information.setBjSpecialtyId(i);

if(i <= 100)

information.setDeviceType("AMD");

else

information.setDeviceType("INTEL");

information.setBjStorageId(i);

if(i <= 20)

information.setActualStorageRoom("实际库房名称");

else

information.setActualStorageRoom("库房名称");

information.setOriginalSerialNum("序列号");

information.setState1Cd("001");

information.setState2Cd("002");

information.setIsStocktake("true");

information.setDeviceModel("设备型号");

information.setFrontPic("/pm/tp.png");

if(i <= 600 && i > 500)

information.setBrandName("实际银行名称");

else

information.setBrandName("银行名称");

information.setNetType("网元类型");

information.setNetName("网元名称");

information.setSpecialtyName("专业类别");

information.setShelfId(i);

information.setShelfName("货架编码名称");

information.setBjType("BJ");

list.add(information);

}

LuceneUtils.createData(list);

//====================================================================================================

//查询

// String[] fields = {"netId"};

// String str = "100";

String[] fields = {"actualStorageRoom","brandName"};

// //不分组统计

Map<String,Object> mapFilter = new HashMap<String,Object>();

Map<String,Object> map = LuceneUtils.getDataList("实际", fields, false, null, false, mapFilter);

TopDocs topDocs = (TopDocs)map.get("information");

IndexSearcher search = (IndexSearcher)map.get("search");

// Document doc = null;

// //取数据字段内容

// for(int i=0; i<topDocs.totalHits; i++){

// int  k = topDocs.scoreDocs[i].doc ; //文档内部编号

// doc = search.doc(k);

// System.out.println(doc.get("actualStorageRoom") +"--" + doc.get("brandName") + "----" + doc.get("netId")) ;

// }

// search.close();

//======================================================================================================

// //分组统计

String str5 = "100";

String[] fields5 = {"netId"};

String[] groupFields = {"deviceType"};

Map<String,Object> mapGroup = LuceneUtils.getDataList(str5, fields5, true, groupFields, false, null);

System.out.println("统计信息 ------->>> " + mapGroup.get("deviceType"));

search.close();

//=======================================================================================================

//新增

Information information = new Information();

information.setActualStorageId(80001);

information.setDeviceId(80001);

information.setBrandId(80001);

information.setNetId(80001);

information.setBjSpecialtyId(80001);

information.setDeviceType("INTEL");

information.setBjStorageId(80001);

information.setActualStorageRoom("实际库房名称");

information.setOriginalSerialNum("序列号");

information.setState1Cd("001");

information.setState2Cd("002");

information.setIsStocktake("true");

information.setDeviceModel("设备型号");

information.setFrontPic("/pm/tp.png");

information.setBrandName("银行名称");

information.setNetType("网元类型");

information.setNetName("网元名称");

information.setSpecialtyName("专业类别");

information.setShelfId(80001);

information.setShelfName("货架编码名称");

information.setBjType("BJ");

LuceneUtils.createData(information);

String str6 = "实际";

String[] fields1 = {"actualStorageRoom","brandName"};

LuceneUtils.getDataList(str6, fields1, false, null, false, null);

//更新

Information information2 = new Information();

information2.setActualStorageId(400);

information2.setDeviceId(80001);

information2.setBrandId(80001);

information2.setNetId(80001);

information2.setBjSpecialtyId(400);

information2.setDeviceType("INTEL");

information2.setBjStorageId(2);

information2.setActualStorageRoom("更新库房名称");

information2.setOriginalSerialNum("序列号");

information2.setState1Cd("001");

information2.setState2Cd("002");

information2.setIsStocktake("true");

information2.setDeviceModel("设备型号");

information2.setFrontPic("/pm/tp.png");

information2.setBrandName("银行名称");

information2.setNetType("网元类型");

information2.setNetName("网元名称");

information2.setSpecialtyName("专业类别");

information2.setShelfId(80001);

information2.setShelfName("货架编码名称");

information2.setBjType("BJ");

LuceneUtils.updateData(information2);

String str2 = "实际";

String[] fields2 = {"actualStorageRoom","brandName"};

LuceneUtils.getDataList(str2, fields2, false, null, false, null);

//删除

LuceneUtils.deleteData("600");

String str3 = "实际";

String[] fields3 = {"actualStorageRoom","brandName"};

LuceneUtils.getDataList(str3, fields3, false, null, false, null);

}

}

Lucene全文搜索 分组,精确查找,模糊查找的更多相关文章

  1. lucene全文搜索之四:创建索引搜索器、6种文档搜索器实现以及搜索结果分析(结合IKAnalyzer分词器的搜索器)基于lucene5.5.3

    前言: 前面几章已经很详细的讲解了如何创建索引器对索引进行增删查(没有更新操作).如何管理索引目录以及如何使用分词器,上一章讲解了如何生成索引字段和创建索引文档,并把创建的索引文档保存到索引目录,到这 ...

  2. lucene全文搜索之三:生成索引字段,创建索引文档(给索引字段加权)基于lucene5.5.3

    前言:上一章中我们已经实现了索引器的创建,但是我们没有索引文档,本章将会讲解如何生成字段.创建索引文档,给字段加权以及保存文档到索引器目录 luncene5.5.3集合jar包下载地址:http:// ...

  3. lucene全文搜索之二:创建索引器(创建IKAnalyzer分词器和索引目录管理)基于lucene5.5.3

    前言: lucene全文搜索之一中讲解了lucene开发搜索服务的基本结构,本章将会讲解如何创建索引器.管理索引目录和中文分词器的使用. 包括标准分词器,IKAnalyzer分词器以及两种索引目录的创 ...

  4. lucene全文搜索之一:lucene的主要功能和基本结构(基于lucene5.5.3)

    前言:lucene并不是像solr或elastic那样提供现成的.直接部署可用的系统,而是一套jar包,提供了一些常见语言分词.构建索引和创建搜索器等等功能的API,我们常用到的也就是分词器.索引目录 ...

  5. Lucene 全文搜索解析

    一.创建查询对象的方式 对要搜索的信息创建 Query 查询对象,Lucene 会根据 Query 查询对象生成最终的查询语法.类似关系数据库 Sql 语法一样,Lucene 也有自己的查询语法,比如 ...

  6. Lucene全文搜索之分词器:使用IK Analyzer中文分词器(修改IK Analyzer源码使其支持lucene5.5.x)

    注意:基于lucene5.5.x版本 一.简单介绍下IK Analyzer IK Analyzer是linliangyi2007的作品,再此表示感谢,他的博客地址:http://linliangyi2 ...

  7. C# 全文搜索Lucene

    全文出自:https://blog.csdn.net/huangwenhua5000/article/details/9341751 1 lucene简介1.1 什么是luceneLucene是一个全 ...

  8. Apache Solr采用Java开发、基于Lucene的全文搜索服务器

    http://docs.spring.io/spring-data/solr/ 首先介绍一下solr: Apache Solr (读音: SOLer) 是一个开源.高性能.采用Java开发.基于Luc ...

  9. OSCHina技术导向:Java全文搜索框架Lucene

    Lucene 是apache软件基金会一个开放源代码的全文检索引擎工具包,是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎,部分文本分析引擎.Lucene的目的是为软件开发人员提供一个简单易用 ...

随机推荐

  1. [ An Ac a Day ^_^ ] UVALive 7270 Osu! Master

    2015icpc北京区域赛的签到题 还是很签到的 一次就过了 题意呢 就是统计B C后最长上升序列还有S的个数 当然B C要被S分割开…… /* *************************** ...

  2. Java I/O 操作的一些基本知识

    1.文件类:File ,也是唯一的单独的文件类.可以对文件进行操作.其方法有:exists(),delete(),isDirectory(),createNewFile(),getName(),get ...

  3. php 备份数据库

    <?php    header("Content-type:text/html;charset=utf-8");    //配置信息  $cfg_dbhost = 'loca ...

  4. redis高级实用特性(1)

    1.安全性 2.主从复制 3.事务处理 4.持久化机制 5.发布订阅消息 6.虚拟内存的使用 安全性:设置客户端连接后进行任何其他指定前需要使用的密码 警告:因为redis速度相当快,所以在一台比较好 ...

  5. ECOS-Ecstore 后台管理地址修改

    ECStore默认出厂的后台管理地址是: http://域名/index.php/shopadmin http://域名/shopadmin [配置过rewrite后,并开启伪静态] 如果想要更个性的 ...

  6. C - 娜娜梦游仙境系列——吃不完的糖果

    C - 娜娜梦游仙境系列——吃不完的糖果 Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Oth ...

  7. 网页 JavaScript的DOM操作

    今天,我首先对之前学习的内容进行了复习,然后学习了当鼠标指向某一个按钮时,切换对应的背景图片. <div id="d1"> </div> <input ...

  8. Shell脚本中让进程休眠的方法(sleep用法)

    有时候写Shell的脚本,用于顺序执行一系列的程序. 有些程序在停止之后并没能立即退出,就例如有一个 tomcat 挂了,就算是用 kill -9 命令也还没瞬间就结束掉. 这么如果 shell 还没 ...

  9. power oj/2360/Change

    题目链接[https://www.oj.swust.edu.cn/problem/show/2360] 题意:给出两个四位数A.B,目地是用最少的步骤使A变成B.变换规则如下:1.相邻的两位数可以交换 ...

  10. android 布局页面文件出错故障排除Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V

    今天在看布局文件的时候出现 android 布局页面文件出错故障排除Exception raised during rendering: java.lang.System.arraycopy([CI[ ...