摘要:看最后的部分高級檢索花費時間毫秒你可以在一個程序中開始索引,也可以寫個定時器來定時索引,看需求。以上代碼是樓主幸苦的作品,轉(zhuǎn)載請不要改動,本人確保代碼完全可用。
我想只要是學過數(shù)據(jù)庫的孩紙,不管是mysql,還是sqlsever,一提到查找,本能的想到的便是like關(guān)鍵字,其實去轉(zhuǎn)盤網(wǎng)(分類模式)之前也是采用這種算法,但我可以告訴大家一個很不幸的事情,like匹配其實會浪費大量的有用資源,原因這里不說了請自己想一想,我們還是直接擺事實驗證。
現(xiàn)在用去轉(zhuǎn)盤網(wǎng)搜:hello 找個單詞,如下:
http://www.quzhuanpan.com/sou...
翻頁你會發(fā)現(xiàn)只要是包含hello的單詞都找到了,但是如果你用like的話是不會有這個效果的,不信讓我們再看一下,還好他來說電影網(wǎng)的分詞算法我還沒來得及修改,還可以看到現(xiàn)象:
http://www.talaishuo.com/sear...
你會發(fā)現(xiàn)只有開始包含hello這個字段的搜索串才能得到匹配,這就問題來了,數(shù)據(jù)庫中大量的資源豈不是白白浪費了,不過沒事,偉大的人類還是很聰明的,發(fā)明了分詞,分詞的原理我就不講了,請自己百度吧,還是直接上代碼,提示,這里需要四個jar包作為工具,我先上傳的去轉(zhuǎn)盤,想要做分詞的請先下載:
分詞包下載地址1
分詞包下載地址2
直接看代碼:
package com.tray.indexData; import java.io.File; import java.io.IOException; import java.io.StringReader; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Document; import org.apache.lucene.document.Fieldable; import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.index.Term; import org.apache.lucene.queryParser.MultiFieldQueryParser; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopScoreDocCollector; import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.search.highlight.Highlighter; import org.apache.lucene.search.highlight.QueryScorer; import org.apache.lucene.search.highlight.SimpleHTMLFormatter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; import org.wltea.analyzer.lucene.IKAnalyzer; import com.tray.bean.SerachResult; import com.tray.common.tools.DateFormater; public class LuceneSearch { private static String DISC_URL = "/home/indexData/data"; static { String os = System.getProperty("os.name"); if(os.toLowerCase().startsWith("win")){ DISC_URL = "E:indexDatadata"; } else{ DISC_URL ="/home/indexData/data"; } } //指定分詞器 private Analyzer analyzer=new IKAnalyzer(); private static Directory directory; //配置 private static IndexWriterConfig iwConfig; //配置IndexWriter private static IndexWriter writer; private static File indexFile = null; private static Version version = Version.LUCENE_36; private final int PAPGESIZE=10; /** * 全量索引 * @Author haoning */ public void init() throws Exception { try { indexFile = new File(DISC_URL); if (!indexFile.exists()) { indexFile.mkdir(); } directory=FSDirectory.open(indexFile); //配置IndexWriterConfig iwConfig = new IndexWriterConfig(version,analyzer); iwConfig.setOpenMode(OpenMode.CREATE_OR_APPEND); //創(chuàng)建寫索引對象 writer = new IndexWriter(directory,iwConfig); } catch (Exception e) { } } public void closeWriter(){ try { writer.close(); } catch (CorruptIndexException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void commit(){ try { writer.commit(); } catch (CorruptIndexException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } /** * 一個一個索引 * @Author haoning */ public void singleIndex(Document doc) throws Exception { writer.addDocument(doc); } /** * 一個跟新 * @Author haoning */ public void singleUpdate(Document doc) throws Exception { Term term = new Term("url", doc.get("url")); writer.updateDocument(term,doc); } /** * 全量索引 * @Author haoning */ public void fullIndex(Document[] documentes) throws Exception { writer.deleteAll(); for (Document document : documentes) { writer.addDocument(document); } writer.commit(); } /** * 根據(jù)id刪除索引 * @Author haoning */ public void deleteIndex(Document document)throws Exception{ Term term = new Term("url", document.get("url"));//url才是唯一標志 writer.deleteDocuments(term); writer.commit(); } /** * 根據(jù)id增量索引 * @Author haoning */ public void updateIndex(Document[] documentes) throws Exception{ for (Document document : documentes) { Term term = new Term("url", document.get("url")); writer.updateDocument(term, document); } writer.commit(); } /** * 直接查詢 * @Author haoning */ public void simpleSearch(String filedStr,String queryStr,int page, int pageSize) throws Exception{ File indexDir = new File(DISC_URL); //索引目錄 Directory dir=FSDirectory.open(indexDir); //根據(jù)索引目錄創(chuàng)建讀索引對象 IndexReader reader = IndexReader.open(dir); //搜索對象創(chuàng)建 IndexSearcher searcher = new IndexSearcher(reader); TopScoreDocCollector topCollector = TopScoreDocCollector.create(searcher.maxDoc(), false); Term term = new Term(filedStr, queryStr); Query query = new TermQuery(term); searcher.search(query, topCollector); ScoreDoc[] docs = topCollector.topDocs((page-1)*pageSize, pageSize).scoreDocs; printScoreDoc(docs, searcher); } /** * 高亮查詢 * @Author haoning */ public MaphighLightSearch(String filed,String keyWord,int curpage, int pageSize) throws Exception{ List list=new ArrayList (); Map map = new HashMap (); if (curpage <= 0) { curpage = 1; } if (pageSize <= 0 || pageSize>20) { pageSize = PAPGESIZE; } File indexDir = new File(DISC_URL); //索引目錄 Directory dir=FSDirectory.open(indexDir);//根據(jù)索引目錄創(chuàng)建讀索引對象 IndexReader reader = IndexReader.open(dir);//搜索對象創(chuàng)建 IndexSearcher searcher = new IndexSearcher(reader); int start = (curpage - 1) * pageSize; Analyzer analyzer = new IKAnalyzer(true); QueryParser queryParser = new QueryParser(Version.LUCENE_36, filed, analyzer); queryParser.setDefaultOperator(QueryParser.AND_OPERATOR); Query query = queryParser.parse(keyWord); int hm = start + pageSize; TopScoreDocCollector res = TopScoreDocCollector.create(hm, false); searcher.search(query, res); SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter("", ""); Highlighter highlighter = new Highlighter(simpleHTMLFormatter, new QueryScorer(query)); long amount = res.getTotalHits(); //long pages = (rowCount - 1) / pageSize + 1; //計算總頁數(shù) map.put("amount",amount);//總共多少條記錄 TopDocs tds = res.topDocs(start, pageSize); ScoreDoc[] sd = tds.scoreDocs; for (int i = 0; i < sd.length; i++) { Document doc = searcher.doc(sd[i].doc); String temp=doc.get("name"); //做高亮處理 TokenStream ts = analyzer.tokenStream("name", new StringReader(temp)); SerachResult record=new SerachResult(); String name = highlighter.getBestFragment(ts,temp); String skydirverName=doc.get("skydirverName"); String username=doc.get("username"); String shareTime=doc.get("shareTime"); String describ=doc.get("describ"); String typeId=doc.get("typeId"); String id=doc.get("id"); String url=doc.get("url"); record.setName(name); record.setSkydriverName(skydirverName); record.setUsername(username); record.setShareTime(DateFormater.getFormatDate(shareTime,"yyyy-MM-dd HH:mm:ss")); record.setDescrib(describ); record.setTypeId(Integer.parseInt(typeId)); record.setId(new BigInteger(id)); record.setUrl(url); list.add(record); /*System.out.println("name:"+name); System.out.println("skydirverName:"+skydirverName); System.out.println("username:"+username); System.out.println("shareTime:"+shareTime); System.out.println("describ:"+describ); System.out.println("typeId:"+typeId); System.out.println("id:"+id); System.out.println("url:"+url);*/ } map.put("source",list); return map; } /** * 根據(jù)前綴查詢 * @Author haoning */ public void prefixSearch(String filedStr,String queryStr) throws Exception{ File indexDir = new File(DISC_URL); //索引目錄 Directory dir=FSDirectory.open(indexDir); //根據(jù)索引目錄創(chuàng)建讀索引對象 IndexReader reader = IndexReader.open(dir); //搜索對象創(chuàng)建 IndexSearcher searcher = new IndexSearcher(reader); Term term = new Term(filedStr, queryStr); Query query = new PrefixQuery(term); ScoreDoc[] docs = searcher.search(query, 3).scoreDocs; printScoreDoc(docs, searcher); } /** * 通配符查詢 * @Author haoning */ public void wildcardSearch(String filedStr,String queryStr) throws Exception{ File indexDir = new File(DISC_URL); //索引目錄 Directory dir=FSDirectory.open(indexDir); //根據(jù)索引目錄創(chuàng)建讀索引對象 IndexReader reader = IndexReader.open(dir); //搜索對象創(chuàng)建 IndexSearcher searcher = new IndexSearcher(reader); Term term = new Term(filedStr, queryStr); Query query = new WildcardQuery(term); ScoreDoc[] docs = searcher.search(query, 3).scoreDocs; printScoreDoc(docs, searcher); } /** * 分詞查詢 * @Author haoning */ public void analyzerSearch(String filedStr,String queryStr) throws Exception{ File indexDir = new File(DISC_URL); //索引目錄 Directory dir=FSDirectory.open(indexDir); //根據(jù)索引目錄創(chuàng)建讀索引對象 IndexReader reader = IndexReader.open(dir); //搜索對象創(chuàng)建 IndexSearcher searcher = new IndexSearcher(reader); QueryParser queryParser = new QueryParser(version, filedStr, analyzer); Query query = queryParser.parse(queryStr); ScoreDoc[] docs = searcher.search(query, 3).scoreDocs; printScoreDoc(docs, searcher); } /** * 多屬性分詞查詢 * @Author haoning */ public void multiAnalyzerSearch(String[] filedStr,String queryStr) throws Exception{ File indexDir = new File(DISC_URL); //索引目錄 Directory dir=FSDirectory.open(indexDir); //根據(jù)索引目錄創(chuàng)建讀索引對象 IndexReader reader = IndexReader.open(dir); //搜索對象創(chuàng)建 IndexSearcher searcher = new IndexSearcher(reader); QueryParser queryParser = new MultiFieldQueryParser(version, filedStr, analyzer); Query query = queryParser.parse(queryStr); ScoreDoc[] docs = searcher.search(query, 3).scoreDocs; printScoreDoc(docs, searcher); } public void printScoreDoc(ScoreDoc[] docs,IndexSearcher searcher)throws Exception{ for (int i = 0; i < docs.length; i++) { List list = searcher.doc(docs[i].doc).getFields(); for (Fieldable fieldable : list) { String fieldName = fieldable.name(); String fieldValue = fieldable.stringValue(); System.out.println(fieldName+" : "+fieldValue); } } } } 注意由于去轉(zhuǎn)盤網(wǎng)(http://www.quzhuanpan.com)是部署到linux上的,所以DISC_URL可以更具系統(tǒng)變換,我是通過url來判定索引文件是否唯一的,你可以更具id來判斷,具體情況具體對待吧。 package com.tray.indexData; import java.sql.SQLException; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import com.mysql.jdbc.Connection; import com.mysql.jdbc.ResultSet; import com.mysql.jdbc.Statement; public class IndexFile { private static Connection conn = null; private static Statement stmt = null; private final int NUM=500000; private LuceneSearch ls; private long count=0; public ResultSet deal6SourceTable(String tableName) throws SQLException{ String sql = "SELECT distinct `NAME`,SKYDRIVER_NAME,USERNAME,SHARE_TIME,DESCRIB,TYPE_ID,ID,URL FROM "+tableName+" where STATUS=1 and TYPE_ID !="-1" and (TYPE_NAME is null or TYPE_NAME!=1) limit "+NUM; //System.out.println(sql); ResultSet rs = (ResultSet) stmt.executeQuery(sql); return rs; } public void update6SourceTable(String tableName) throws SQLException{ Statement st = (Statement) conn.createStatement(); String sql = "update "+tableName+" set TYPE_NAME=1 where STATUS=1 and TYPE_ID !="-1" and (TYPE_NAME is null or TYPE_NAME!=1) limit "+NUM; //System.out.println("update"+sql); try { st.executeUpdate(sql); } catch (SQLException e) { e.printStackTrace(); } } public void indexInit(){//數(shù)據(jù)庫+lcene初始化 conn = (Connection) JdbcUtil.getConnection(); if(conn == null) { try { throw new Exception("數(shù)據(jù)庫連接失敗!"); } catch (Exception e) { e.printStackTrace(); } } ls=new LuceneSearch(); try { ls.init(); } catch (Exception e2) { e2.printStackTrace(); } } public void indexEnd(){//數(shù)據(jù)庫+lcene關(guān)閉 ls.closeWriter(); try { conn.close();//關(guān)閉數(shù)據(jù)庫 } catch (SQLException e) { e.printStackTrace(); } } public void Index6Data() throws SQLException{ try { stmt = (Statement) conn.createStatement(); } catch (SQLException e1) { e1.printStackTrace(); } ResultSet r1=null; ResultSet r2=null; ResultSet r3=null; ResultSet r4=null; ResultSet r5=null; ResultSet r6=null; boolean stop=false; do{ r1=deal6SourceTable("film_and_tv_info"); stop=this.createIndex(r1,ls,"1"); //給數(shù)據(jù)庫創(chuàng)建索引,此處執(zhí)行一次,不要每次運行都創(chuàng)建索引,以后數(shù)據(jù)有更新可以后臺調(diào)用更新索引 if(!stop){ ls.commit();//加個判斷條件 } //System.out.println("stop"+stop); }while(!stop); stop=false; do{ r2=deal6SourceTable("music_and_mv_info"); stop=this.createIndex(r2,ls,"2"); //給數(shù)據(jù)庫創(chuàng)建索引,此處執(zhí)行一次,不要每次運行都創(chuàng)建索引,以后數(shù)據(jù)有更新可以后臺調(diào)用更新索引 if(!stop){ ls.commit();//加個判斷條件 } }while(!stop); stop=false; do{ r3=deal6SourceTable("e_book_info"); stop=this.createIndex(r3,ls,"3"); //給數(shù)據(jù)庫創(chuàng)建索引,此處執(zhí)行一次,不要每次運行都創(chuàng)建索引,以后數(shù)據(jù)有更新可以后臺調(diào)用更新索引 if(!stop){ ls.commit();//加個判斷條件 } }while(!stop); stop=false; do{ r4=deal6SourceTable("bt_file_info"); stop=this.createIndex(r4,ls,"4"); //給數(shù)據(jù)庫創(chuàng)建索引,此處執(zhí)行一次,不要每次運行都創(chuàng)建索引,以后數(shù)據(jù)有更新可以后臺調(diào)用更新索引 if(!stop){ ls.commit();//加個判斷條件 } }while(!stop); stop=false; do{ r5=deal6SourceTable("characteristic_software_info"); stop=this.createIndex(r5,ls,"5"); //給數(shù)據(jù)庫創(chuàng)建索引,此處執(zhí)行一次,不要每次運行都創(chuàng)建索引,以后數(shù)據(jù)有更新可以后臺調(diào)用更新索引 if(!stop){ ls.commit();//加個判斷條件 } }while(!stop); stop=false; do{ r6=deal6SourceTable("source_code_info"); stop=this.createIndex(r6,ls,"6"); //給數(shù)據(jù)庫創(chuàng)建索引,此處執(zhí)行一次,不要每次運行都創(chuàng)建索引,以后數(shù)據(jù)有更新可以后臺調(diào)用更新索引 if(!stop){ ls.commit();//加個判斷條件 } }while(!stop); stop=false; } public ResultSet deal2Share(String tableName) throws SQLException{ String sql = "SELECT distinct NAME,SKYDRIVER_NAME,USERNAME,SHARE_TIME,DESCRIB,TYPE_ID,ID,SHORTURL from "+tableName+" where STATUS=1 and FS_ID ="1" limit "+NUM; //利用FS_ID這個字段,沒什么用處 ResultSet rs = (ResultSet) stmt.executeQuery(sql); return rs; } public ResultSet deal3Share(String tableName) throws SQLException{ String sql = "SELECT distinct title,channel,uid,ctime,description,port,id,shorturl from "+tableName+" where name ="1" limit "+NUM; ResultSet rs = (ResultSet) stmt.executeQuery(sql); return rs; } public void Index3Data() throws SQLException{ try { stmt = (Statement) conn.createStatement(); } catch (SQLException e1) { e1.printStackTrace(); } ResultSet r1=null; ResultSet r2=null; ResultSet r3=null; boolean stop=false; do{ r1=deal2Share("share1"); stop=this.createIndex(r1,ls,"7"); //給數(shù)據(jù)庫創(chuàng)建索引,此處執(zhí)行一次,不要每次運行都創(chuàng)建索引,以后數(shù)據(jù)有更新可以后臺調(diào)用更新索引 if(!stop){ ls.commit();//加個判斷條件 } //System.out.println("stop"+stop); }while(!stop); stop=false; do{ r2=deal2Share("share2"); stop=this.createIndex(r2,ls,"8"); //給數(shù)據(jù)庫創(chuàng)建索引,此處執(zhí)行一次,不要每次運行都創(chuàng)建索引,以后數(shù)據(jù)有更新可以后臺調(diào)用更新索引 if(!stop){ ls.commit();//加個判斷條件 } }while(!stop); stop=false; do{ r3=deal3Share("share3"); stop=this.createIndex(r3,ls,"9"); //給數(shù)據(jù)庫創(chuàng)建索引,此處執(zhí)行一次,不要每次運行都創(chuàng)建索引,以后數(shù)據(jù)有更新可以后臺調(diào)用更新索引 if(!stop){ ls.commit();//加個判斷條件 } }while(!stop); stop=false; } public void update2ShareTable(String tableName) throws SQLException{ Statement st = (Statement) conn.createStatement(); String sql = "update "+tableName+" set FS_ID=0 where STATUS=1 and FS_ID ="1" limit "+NUM; //利用FS_ID這個字段,沒什么用處 //System.out.println("update"+sql); try { st.executeUpdate(sql); } catch (SQLException e) { e.printStackTrace(); } } public void update3ShareTable(String tableName) throws SQLException{ Statement st = (Statement) conn.createStatement(); String sql = "update "+tableName+" set name=0 where name ="1" limit "+NUM; //System.out.println("update"+sql); try { st.executeUpdate(sql); } catch (SQLException e) { e.printStackTrace(); } } public boolean createIndex(ResultSet rs,LuceneSearch ls,String mark) { try { String tableName=null; if(mark.equals("1")){ tableName="film_and_tv_info"; } if(mark.equals("2")){ tableName="music_and_mv_info"; } if(mark.equals("3")){ tableName="e_book_info"; } if(mark.equals("4")){ tableName="bt_file_info"; } if(mark.equals("5")){ tableName="characteristic_software_info"; } if(mark.equals("6")){ tableName="source_code_info"; } if(mark.equals("7")){ tableName="share1"; } if(mark.equals("8")){ tableName="share2"; } if(mark.equals("9")){ tableName="share3"; } boolean isNull=rs.next(); //System.out.println("hehe"+isNull); if(isNull==false){ return true;//處理完畢 } while(isNull){ if(Integer.parseInt(mark)>=1&&Integer.parseInt(mark)<=8){ Document doc = new Document(); //System.out.println("name"+rs.getString("NAME")); Field name = new Field("name",rs.getString("NAME"),Field.Store.YES,Field.Index.ANALYZED); String skName=rs.getString("SKYDRIVER_NAME"); if(skName==null){ skName="百度"; } Field skydirverName = new Field("skydirverName",skName, Field.Store.YES,Field.Index.NOT_ANALYZED); Field username = new Field("username",rs.getString("USERNAME"),Field.Store.YES, Field.Index.ANALYZED); Field shareTime = new Field("shareTime",rs.getString("SHARE_TIME"), Field.Store.YES,Field.Index.NOT_ANALYZED); String desb=rs.getString("DESCRIB"); if(desb==null){ desb="-1"; } Field describ = new Field("describ",desb,Field.Store.NO,Field.Index.NOT_ANALYZED); Field typeId = new Field("typeId",rs.getString("TYPE_ID"), Field.Store.YES,Field.Index.NOT_ANALYZED); Field id = new Field("id",rs.getString("ID"),Field.Store.YES,Field.Index.NOT_ANALYZED); Field url =null; if(Integer.parseInt(mark)>=7&&Integer.parseInt(mark)<=8){ url = new Field("url",rs.getString("SHORTURL"), Field.Store.YES,Field.Index.ANALYZED); } else{ url = new Field("url",rs.getString("URL"), Field.Store.YES,Field.Index.ANALYZED); } doc.add(name); doc.add(skydirverName); doc.add(username); doc.add(shareTime); doc.add(describ); doc.add(typeId); doc.add(id); doc.add(url); ls.singleUpdate(doc);//用跟新更為合適 isNull=rs.next(); } else{ Document doc = new Document(); //System.out.println("title"+rs.getString("title")); Field name = new Field("name",rs.getString("title"),Field.Store.YES,Field.Index.ANALYZED); String skName=rs.getString("channel"); Field skydirverName = new Field("skydirverName",skName, Field.Store.YES,Field.Index.NOT_ANALYZED); Field username = new Field("username",rs.getString("uid"),Field.Store.YES, Field.Index.ANALYZED); Field shareTime = new Field("shareTime",rs.getString("ctime"), Field.Store.YES,Field.Index.NOT_ANALYZED); String desb=rs.getString("description"); if(desb==null){ desb="-1"; } Field describ = new Field("describ",desb,Field.Store.NO,Field.Index.NOT_ANALYZED); Field typeId = new Field("typeId",rs.getString("port"), Field.Store.YES,Field.Index.NOT_ANALYZED); Field id = new Field("id",rs.getString("id"),Field.Store.YES,Field.Index.NOT_ANALYZED); Field url = new Field("url",rs.getString("shorturl"), Field.Store.YES,Field.Index.ANALYZED); doc.add(name); doc.add(skydirverName); doc.add(username); doc.add(shareTime); doc.add(describ); doc.add(typeId); doc.add(id); doc.add(url); ls.singleUpdate(doc);//用跟新更為合適 isNull=rs.next(); } count=count+1; } if(Integer.parseInt(mark)>=1&&Integer.parseInt(mark)<=6){ update6SourceTable(tableName);//處理完成后做標志 } else if(Integer.parseInt(mark)>=7&&Integer.parseInt(mark)<=8){ update2ShareTable(tableName);//處理完成后做標志 } else{ update3ShareTable(tableName);//處理完成后做標志 } System.out.println("Has index "+count+"條數(shù)據(jù),數(shù)據(jù)來自表"+tableName); } catch (Exception e) { e.printStackTrace(); } return false; } } 數(shù)據(jù)庫之類的請不要關(guān)心,看思路即可,你如果需要換成你的即可,這里就不多說了。 看最后的部分: package com.tray.indexData; import java.sql.SQLException; public class Application { public static void main(String[] args){ /*IndexFile indexFile=new IndexFile(); indexFile.indexInit(); try { indexFile.Index6Data(); } catch (SQLException e1) { e1.printStackTrace(); } indexFile.indexEnd();*/ IndexFile indexFile1=new IndexFile(); indexFile1.indexInit(); try { indexFile1.Index3Data(); } catch (SQLException e1) { e1.printStackTrace(); } indexFile1.indexEnd(); LuceneSearch lch=new LuceneSearch(); try { long a = System.currentTimeMillis(); lch.highLightSearch("name", "flv", 1,3); long b = System.currentTimeMillis(); long c = b - a; System.out.println("[高級檢索花費時間:" + c + "毫秒]"); } catch (Exception e) { e.printStackTrace(); } } }
你可以在一個applicationic程序中開始索引,也可以寫個定時器來定時索引,看需求。以上代碼是樓主幸苦的作品,轉(zhuǎn)載請不要改動,本人確保代碼完全可用。本人建個qq群,歡迎大家一起交流技術(shù), 群號:512245829 喜歡微博的朋友關(guān)注:轉(zhuǎn)盤娛樂即可
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/65942.html
摘要:最初,它是以開源項目為應(yīng)用主體的,結(jié)合詞典分詞和文法分析算法的中文分詞組件。填補了國內(nèi)中文分詞方面開源組件的空白,致力于此并希翼成為互聯(lián)網(wǎng)網(wǎng)站首選的中文分詞開源組件。中文分詞追求分詞的高效率和用戶良好體驗。 1:Elasticsearch的開源中文分詞器 IK Analysis(Star:2471) IK中文分詞器在Elasticsearch上的使用。原生IK中文分詞是從文件系統(tǒng)中讀取...
摘要:系列文章系列一快速入門系列二使用及索引文檔的基本操作系列三查詢及高亮是什么在維基百科的定義是一套用于全文檢索和搜索的開放源代碼程序庫,由軟件基金會支持和提供。全面準確和快速是衡量全文檢索系統(tǒng)的關(guān)鍵指標。結(jié)果列表有相關(guān)度排序。 系列文章: Lucene系列(一)快速入門 Lucene系列(二)luke使用及索引文檔的基本操作 Lucene系列(三)查詢及高亮 Lucene是什么? Luc...
閱讀 2582·2021-09-30 09:48
閱讀 2573·2019-08-30 14:10
閱讀 2713·2019-08-29 11:22
閱讀 1842·2019-08-26 13:51
閱讀 2280·2019-08-26 12:02
閱讀 2421·2019-08-23 16:06
閱讀 3559·2019-08-23 14:06
閱讀 1097·2019-08-23 13:56