Lucene學習總結 擴充套件查詢

2021-06-09 06:47:08 字數 2085 閱讀 8563

custom sort method:

sort sort = new sort(new sortfield("location",

new distancecomparatorsource(10, 10)));

topfielddocs docs = searcher.search(query, null, 3, sort);

fielddoc fielddoc = (fielddoc) docs.scoredocs[0];

document document = searcher.doc(fielddoc.doc);

custom hitcollector:

public void testcollecting() throws exception {

termquery query = new termquery(new term("contents", "junit"));

indexsearcher searcher = new indexsearcher(testutil.getbookindexdirectory());

booklinkcollector collector = new booklinkcollector(searcher);

searcher.search(query, collector);

map linkmap = collector.getlinks();

topdocs hits = searcher.search(query, 10);

testutil.dumphits(searcher, hits);

searcher.close();

extending queryparser:getfieldquery,getfuzzyquery,getprefixquery,getrangequery,getbooleanquery,getwildcardquery

custom filter:

specialsaccessor accessor = new testspecialsaccessor(isbns);

filter filter = new specialsfilter(accessor);

wildcardquery educationbooks = // #2

new wildcardquery(new term("category", "*education*")); // #2

filteredquery edbooksonspecial = // #2

new filteredquery(educationbooks, filter); // #2

termquery logobooks = // #3

new termquery(new term("subject", "logo")); // #3

booleanquery logooredbooks = new booleanquery(); // #4

logooredbooks.add(logobooks, booleanclause.occur.should); // #4

logooredbooks.add(edbooksonspecial, booleanclause.occur.should); // #4

topdocs hits = searcher.search(logooredbooks, 10);

payloads:相當於對文件分類,defaultsimilarity,payloadhelper,

doc1.add(new field("category", "foods|0.984 shopping|0.503", field.store.yes, field.index.analyzed));  

string queries = "category:foods content:egg";

searcher.setsimilarity(new payloadsimilarity());

payloadsearcher.display(payloadsearcher.search(queries), start, end);

lucene學習總結

一,建立索引 1,建立indexwriter directory fsdirectory。open file analyzer new standardanalyzer version indexwriter new indexwriter directory,analyzer,boolean,bo...

Lucene學習總結三

前兩篇,講到了lucene的一些用法,這一篇,我們繼續lucene的其他的特性 一 索引庫優化 1 1什麼是索引庫 索引庫是lucene的重要的儲存結構,它包括二部份 原始記錄表,詞彙表 原始記錄表 存放的是原始記錄資訊,lucene為存入的內容分配乙個唯一的編號 詞彙表 存放的是經過分詞器拆分出來...

Lucene學習總結之七 Lucene搜尋過程解析

本系列文章將詳細描述幾乎最新版本的lucene的基本原理和 分析。其中總體架構和索引檔案格式是lucene 2.9的,索引過程分析是lucene 3.0的。鑑於索引檔案格式沒有太大變化,因而原文沒有更新,原理和架構的文章中引用了前輩的一些圖,可能屬於早期的lucene,但不影響對原理和架構的理解。本...