微吼云上線多路互動直播服務 加速多場景互動直播落地
800
2025-03-31
Lucene 8.5.2核心API
Apache Lucene是一個高性能的全功能文本搜索引擎庫。
另請:說明
頂級程序包。
文字分析。
快速,通用的基于語法的令牌生成器根據Unicode標準附件#29中StandardTokenizer?指定的Unicode文本分段算法實現分詞規則?。
文本分析的通用屬性。
編解碼器API:用于自定義索引編碼和結構的API。
BlockTree術語詞典。
StoredFieldsFormat,它允許對存儲的字段進行跨文檔和跨字段的壓縮。
Lucene 5.0索引格式的組件有關索引格式org.apache.lucene.codecs.lucene80的概述,請參見。
Lucene 6.0索引格式的組件。
Lucene 7.0索引格式的組件。
Lucene 8.0索引格式的組件有關索引格式org.apache.lucene.codecs.lucene84的概述,請參見。
Lucene 8.4文件格式。
可以將每個字段委派為不同格式的帖子格式。
Document用于索引和搜索的邏輯表示。
Lucene Core的地理空間實用程序實現
維護和訪問索引的代碼。
代碼以搜索索引。
該軟件包包含可在Lucene中使用的各種排名模型。
跨度的演算。
二進制I / O API,用于所有索引數據。
一些實用程序類。
用于正則表達式的有限狀態自動機。
塊KD樹,實現在所描述的通用的空間數據結構?本文。
壓縮實用程序。
有限狀態傳感器
用于將令牌流作為圖形使用的實用程序類。
可比對象包裝
壓縮整數數組和流。
Apache Lucene是一個高性能的全功能文本搜索引擎庫。這是一個簡單的示例,說明如何使用Lucene進行索引和搜索(使用JUnit檢查結果是否符合我們的預期):
Analyzer analyzer = new StandardAnalyzer();
Path indexPath = Files.createTempDirectory("tempIndex");
Directory directory = FSDirectory.open(indexPath)
IndexWriterConfig config = new IndexWriterConfig(analyzer);
IndexWriter iwriter = new IndexWriter(directory, config);
Document doc = new Document();
String text = "This is the text to be indexed.";
doc.add(new Field("fieldname", text, TextField.TYPE_STORED));
iwriter.addDocument(doc);
iwriter.close();
// Now search the index:
DirectoryReader ireader = DirectoryReader.open(directory);
IndexSearcher isearcher = new IndexSearcher(ireader);
// Parse a simple query that searches for "text":
QueryParser parser = new QueryParser("fieldname", analyzer);
Query query = parser.parse("text");
ScoreDoc[] hits = isearcher.search(query, 10).scoreDocs;
assertEquals(1, hits.length);
// Iterate through the results:
for (int i = 0; i < hits.length; i++) {
Document hitDoc = isearcher.doc(hits[i].doc);
assertEquals("This is the text to be indexed.", hitDoc.get("fieldname"));
}
ireader.close();
directory.close();
IOUtils.rm(indexPath);
Lucene API分為幾個軟件包:
org.apache.lucene.analysis?定義一個抽象Analyzer?API,用于將文本從Reader?轉換為TokenStream,枚舉為Attributes?的枚舉。可以通過將TokenFilters應用于的輸出來組成TokenStream?Tokenizer。Tokenizer和TokenFilters串在一起并與一起應用Analyzer。??analyticss?-common提供了許多Analyzer實現,包括?StopAnalyzer?和基于語法的StandardAnalyzer。
org.apache.lucene.codecs?提供了對倒排索引結構的編碼和解碼的抽象,以及可以根據應用程序需求選擇的不同實現。
org.apache.lucene.document?提供一個簡單的Document?類。文檔只是一組名為Field的,其值可以是字符串或的實例Reader。
org.apache.lucene.index?提供了兩個主要的類:IndexWriter,用于創建文檔并將其添加到索引;和IndexReader,用于訪問索引中的數據。
org.apache.lucene.search?提供表示查詢的數據結構(即TermQuery?用于單個單詞,PhraseQuery?短語和BooleanQuery?查詢的布爾組合)IndexSearcher?,并將查詢轉換成TopDocs。提供了許多QueryParser,用于從字符串或xml生成查詢結構。
org.apache.lucene.store?定義用于存儲持久性數據的抽象類,該類Directory是由編寫并由IndexOutput?讀取的命名文件的集合IndexInput。提供了多種實現,但是FSDirectory通常建議您這樣做,因為它會嘗試有效地使用操作系統磁盤緩沖區高速緩存。
org.apache.lucene.util?包含一些方便的數據結構和util類,即FixedBitSet?和PriorityQueue。
Document通過添加來?創建Field;
使用創建一個IndexWriter?并向其中添加文檔addDocument();
調用QueryParser.parse()?從字符串中構建查詢;和
創建一個IndexSearcher?并將查詢傳遞給其search()?方法。
IndexFiles.java為目錄中包含的所有文件創建索引。
SearchFiles.java提示查詢并搜索索引。
>?java -cp lucene-core.jar:lucene-demo.jar:lucene-queryparser.jar:lucene-analyzers-common.jar org.apache.lucene.demo.SearchFiles
Query:?chowder
Searching for: chowder
34 total matching documents
1. rec.food.recipes/soups/spam-chowder
[ ... thirty-four documents contain the word "chowder" ... ]
Query:?"clam chowder" AND Manhattan
Searching for: +"clam chowder" +manhattan
2 total matching documents
1. rec.food.recipes/soups/clam-chowder
[ ... two documents contain the phrase "clam chowder" and the word "manhattan" ... ]
[ Note: "+" and "-" are canonical, but "AND", "OR" and "NOT" may be used. ]
API Lucene/Solr
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。