免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
Lucene

Lucene-5.2.1學(xué)習(xí):入門(mén)

發(fā)表于4個(gè)月前(2015-08-11 12:06)   閱讀(902) | 評(píng)論(04人收藏此文章, 我要收藏
0

12月12日北京OSC源創(chuàng)會(huì) —— 開(kāi)源技術(shù)的年終盛典 ?  

1、Lucene的核心jar包

lucene-core-5.2.1.jar

lucene-analyzers-common-5.2.1.jar

lucene-queryparser-5.2.1.jar

2、主要開(kāi)發(fā)包說(shuō)明

org.apache.lucene.analysis:語(yǔ)言分析器,主要用于分詞

org.apache.lucene.document:索引文檔的管理

org.apache.lucene.index:索引管理,如增、刪、改

org.apache.lucene.queryparser:查詢(xún)分析

org.apache.lucene.search:檢索管理

org.apache.lucene.store:數(shù)據(jù)存儲(chǔ)管理

org.apache.lucene.util:工具包

3、寫(xiě)入索引操作的核心類(lèi)

Directory:代表索引文檔的存儲(chǔ)位置,這是一個(gè)抽象類(lèi)有FSDirectoryRAMDirectory兩個(gè)主要子類(lèi)。前者將索引寫(xiě)入文件系統(tǒng),后者將索引文檔寫(xiě)入內(nèi)存。

Analyzer:建立索引時(shí)使用的分析器,主要子類(lèi)有StandardAnalyzer(一個(gè)漢字一個(gè)詞),還可以由第三方提供如開(kāi)源社區(qū)提供一些中文分詞器。

IndexWriterConfig:操作索引庫(kù)的配置信息

IndexWriter:建立索引的核心類(lèi),用來(lái)操作索引(增、刪、改)

Document:代表一個(gè)索引文檔

Field:代表索引文檔中存儲(chǔ)的數(shù)據(jù),新版本的Lucene進(jìn)行了細(xì)化給出了多個(gè)子類(lèi):IntField、LongFieldFloatField、DoubleField、TextField、StringField等。

4、寫(xiě)入索引

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package cn.harmel.lucene;
import java.io.IOException;
import java.nio.file.Paths;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
public class First {
    public static void main(String[] args) throws IOException {
        Analyzer a = new StandardAnalyzer();
        Directory dir = FSDirectory.open(Paths.get("./index"));
        IndexWriterConfig iwc = new IndexWriterConfig(a);
        IndexWriter iw = new IndexWriter(dir, iwc);
        Document doc = new Document();
        doc.add(new TextField("info""this is my first lucene test", Field.Store.YES));
        iw.addDocument(doc);
        iw.close();
        dir.close();
    }
}

5、查詢(xún)索引操作的核心類(lèi)

IndexReader:讀取索引的工具類(lèi),常用子類(lèi)有DirectoryReader

IndexSearch:查詢(xún)索引的核心類(lèi)

QueryParser:查詢(xún)分析器,表示從哪里查用哪個(gè)分析器

Query:代表一次查詢(xún)

TopDocs:封裝了匹配情況,比如匹配多少個(gè)

ScoreDoc:匹配的數(shù)據(jù),里面封裝了索引文檔的得分和索引ID

6、查詢(xún)索引

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cn.harmel.lucene;
import java.io.IOException;
import java.nio.file.Paths;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
public class Second {
    public static void main(String[] args) throws IOException, ParseException {
        Analyzer a = new StandardAnalyzer();
        Directory dir = FSDirectory.open(Paths.get("./index"));
        IndexReader reader = DirectoryReader.open(dir);
        IndexSearcher is = new IndexSearcher(reader);
        QueryParser parser = new QueryParser("info", a);
        Query query = parser.parse("lucene");
        TopDocs topDocs = is.search(query, 1000);
        System.out.println("總共匹配多少個(gè):" + topDocs.totalHits);
        ScoreDoc[] hits = topDocs.scoreDocs;
        // 應(yīng)該與topDocs.totalHits相同
        System.out.println("多少條數(shù)據(jù):" + hits.length);
        for (ScoreDoc scoreDoc : hits) {
            System.out.println("匹配得分:" + scoreDoc.score);
            System.out.println("文檔索引ID:" + scoreDoc.doc);
            Document document = is.doc(scoreDoc.doc);
            System.out.println(document.get("info"));
        }
        reader.close();
        dir.close();
    }
}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Lucene簡(jiǎn)單實(shí)現(xiàn)文件索引及查詢(xún)
Lucene版Hello world(世界,你好)
實(shí)戰(zhàn) Lucene,第 1 部分: 初識(shí) Lucene
[原創(chuàng)]全文搜索引擎Lucene學(xué)習(xí)筆記(頁(yè) 1) - 『 編程設(shè)計(jì) 』 - 青韶論壇 湘...
一步一步跟我學(xué)習(xí)lucene(9)---lucene搜索之拼寫(xiě)檢查和相似度查詢(xún)提示
用Lucene建立索引及查詢(xún)示例
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服