Lucene全文搜索 分组,精确查找,模糊查找
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全文搜索 分组,精确查找,模糊查找的更多相关文章
- lucene全文搜索之四:创建索引搜索器、6种文档搜索器实现以及搜索结果分析(结合IKAnalyzer分词器的搜索器)基于lucene5.5.3
前言: 前面几章已经很详细的讲解了如何创建索引器对索引进行增删查(没有更新操作).如何管理索引目录以及如何使用分词器,上一章讲解了如何生成索引字段和创建索引文档,并把创建的索引文档保存到索引目录,到这 ...
- lucene全文搜索之三:生成索引字段,创建索引文档(给索引字段加权)基于lucene5.5.3
前言:上一章中我们已经实现了索引器的创建,但是我们没有索引文档,本章将会讲解如何生成字段.创建索引文档,给字段加权以及保存文档到索引器目录 luncene5.5.3集合jar包下载地址:http:// ...
- lucene全文搜索之二:创建索引器(创建IKAnalyzer分词器和索引目录管理)基于lucene5.5.3
前言: lucene全文搜索之一中讲解了lucene开发搜索服务的基本结构,本章将会讲解如何创建索引器.管理索引目录和中文分词器的使用. 包括标准分词器,IKAnalyzer分词器以及两种索引目录的创 ...
- lucene全文搜索之一:lucene的主要功能和基本结构(基于lucene5.5.3)
前言:lucene并不是像solr或elastic那样提供现成的.直接部署可用的系统,而是一套jar包,提供了一些常见语言分词.构建索引和创建搜索器等等功能的API,我们常用到的也就是分词器.索引目录 ...
- Lucene 全文搜索解析
一.创建查询对象的方式 对要搜索的信息创建 Query 查询对象,Lucene 会根据 Query 查询对象生成最终的查询语法.类似关系数据库 Sql 语法一样,Lucene 也有自己的查询语法,比如 ...
- Lucene全文搜索之分词器:使用IK Analyzer中文分词器(修改IK Analyzer源码使其支持lucene5.5.x)
注意:基于lucene5.5.x版本 一.简单介绍下IK Analyzer IK Analyzer是linliangyi2007的作品,再此表示感谢,他的博客地址:http://linliangyi2 ...
- C# 全文搜索Lucene
全文出自:https://blog.csdn.net/huangwenhua5000/article/details/9341751 1 lucene简介1.1 什么是luceneLucene是一个全 ...
- Apache Solr采用Java开发、基于Lucene的全文搜索服务器
http://docs.spring.io/spring-data/solr/ 首先介绍一下solr: Apache Solr (读音: SOLer) 是一个开源.高性能.采用Java开发.基于Luc ...
- OSCHina技术导向:Java全文搜索框架Lucene
Lucene 是apache软件基金会一个开放源代码的全文检索引擎工具包,是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎,部分文本分析引擎.Lucene的目的是为软件开发人员提供一个简单易用 ...
随机推荐
- java对数计算
Java对数函数的计算方法非常有问题,然而在API中却有惊人的误差.但是假如运用了以下的方法,用Java处理数字所碰到的小麻烦就可以轻而易举的解决了. Sun的J2SE提供了一个单一的Java对数方法 ...
- Arch最小化安装LXDE桌面环境
安装最小化的LXDE桌面环境: pacman -S lxde-common 安装LXDE Session: pacman -S lxsession 不安装这个没法登录进桌面环境 安装LXDE面板: p ...
- Chapter 16_4 私密性
在Lua面向对象编程的基础设计当中,没有提供私密性机制.但是可以用其他方法实现,从而获得对象的访问控制. 这种实现不常用,作为兴趣爱好,只做基本了解. 基本做法是:通过两个table来表示一个对象.一 ...
- NOIP2013-普及组复赛-第一题-计数问题
题目描述 Description 试计算在区间 1 到 n 的所有整数中,数字 x(0 ≤ x ≤ 9)共出现了多少次?例如,在 1到 11 中,即在 1.2.3.4.5.6.7.8.9.10.11 ...
- 倒叙筛除list
for(int i=list.Count-1;i>=0;i--) { if(list[i]) { list.RemoveAt(i); } }
- jqgird 实践
$.jgrid.defaults.styleUI="Bootstrap"; $("#table_list_2").jqGrid({ multiselect: t ...
- 【CRC校验】学习笔记
#include<stdio.h> unsigned ]= { 0x01,0x02,0x03,0x04,0x05,0x06 }; ] = { 0x0000, 0x1021, 0x2042, ...
- html 图片上传预览
Html5 upload img 2012年12月27日 20:36 <!DOCTYPE HTML> <html> <head> <meta http-equ ...
- pc打开手机站提示切换为手机屏幕
.turn { position: absolute; width: 100%; height: 100%; left:; top:; background: url(../images.png) c ...
- error while loading shared libraries: libseaudit.so.4: cannot open shared object file: Error 40
安装共享库后要注意共享库路径设置问题, 如下: 1) 如果共享库文件安装到了/lib或/usr/lib目录下, 那么需执行一下ldconfig命令 ldconfig命令的用途, 主要是在默认搜寻目录( ...