麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > Java > 正文

java Lucene 中自定義排序的實現

2020-03-24 18:19:41
字體:
來源:轉載
供稿:網友
Lucene中的自定義排序功能和Java集合中的自定義排序的實現方法差不多,都要實現一下比較接口. 在Java中只要實現Comparable接口就可以了.但是在Lucene中要實現SortComparatorSource接口和ScoreDocComparator接口.在了解具體實現方法之前先來看看這兩個接口的定義吧.
SortComparatorSource接口的功能是返回一個用來排序ScoreDocs的comparator(Expert: returns a comparator for sorting ScoreDocs).該接口只定義了一個方法.如下:
Java代碼
/**
* Creates a comparator for the field in the given index.
* @param reader - Index to create comparator for.
* @param fieldname - Field to create comparator for.
* @return Comparator of ScoreDoc objects.
* @throws IOException - If an error occurs reading the index.
*/
html' target='_blank'>public ScoreDocComparator newComparator(IndexReader reader,String fieldname) throws IOException
view plaincopy to clipboardprint?
/**
* Creates a comparator for the field in the given index.
* @param reader - Index to create comparator for.
* @param fieldname - Field to create comparator for.
* @return Comparator of ScoreDoc objects.
* @throws IOException - If an error occurs reading the index.
*/
public ScoreDocComparator newComparator(IndexReader reader,String fieldname) throws IOException
/**
* Creates a comparator for the field in the given index.
* @param reader - Index to create comparator for.
* @param fieldname - Field to create comparator for.
* @return Comparator of ScoreDoc objects.
* @throws IOException - If an error occurs reading the index.
*/
public ScoreDocComparator newComparator(IndexReader reader,String fieldname) throws IOException
該方法只是創造一個ScoreDocComparator 實例用來實現排序.所以我們還要實現ScoreDocComparator 接口.來看看ScoreDocComparator 接口.功能是比較來兩個ScoreDoc 對象來排序(Compares two ScoreDoc objects for sorting) 里面定義了兩個Lucene實現的靜態實例.如下:
Java代碼
//Special comparator for sorting hits according to computed relevance (document score).
public static final ScoreDocComparator RELEVANCE;
//Special comparator for sorting hits according to index order (document number).
public static final ScoreDocComparator INDEXORDER;
view plaincopy to clipboardprint?
//Special comparator for sorting hits according to computed relevance (document score).
public static final ScoreDocComparator RELEVANCE;
//Special comparator for sorting hits according to index order (document number).
public static final ScoreDocComparator INDEXORDER;
//Special comparator for sorting hits according to computed relevance (document score).
public static final ScoreDocComparator RELEVANCE;

//Special comparator for sorting hits according to index order (document number).
public static final ScoreDocComparator INDEXORDER;
有3個方法與排序相關,需要我們實現 分別如下:
Java代碼
/**
* Compares two ScoreDoc objects and returns a result indicating their sort order.
* @param i First ScoreDoc
* @param j Second ScoreDoc
* @return -1 if i should come before j;
* 1 if i should come after j;
* 0 if they are equal
*/
public int compare(ScoreDoc i,ScoreDoc j);
/**
* Returns the value used to sort the given document. The object returned must implement the java.io.Serializable interface. This is used by multisearchers to determine how to collate results from their searchers.
* @param i Document
* @return Serializable object
*/
public Comparable sortValue(ScoreDoc i);
/**
* Returns the type of sort. Should return SortField.SCORE, SortField.DOC, SortField.STRING, SortField.INTEGER, SortField.FLOAT or SortField.CUSTOM. It is not valid to return SortField.AUTO. This is used by multisearchers to determine how to collate results from their searchers.
* @return One of the constants in SortField.
*/
public int sortType();
view plaincopy to clipboardprint?
/**
* Compares two ScoreDoc objects and returns a result indicating their sort order.
* @param i First ScoreDoc
* @param j Second ScoreDoc
* @return -1 if i should come before j;
* 1 if i should come after j;
* 0 if they are equal
*/
public int compare(ScoreDoc i,ScoreDoc j);
/**
* Returns the value used to sort the given document. The object returned must implement the java.io.Serializable interface. This is used by multisearchers to determine how to collate results from their searchers.
* @param i Document
* @return Serializable object
*/
public Comparable sortValue(ScoreDoc i);
/**
* Returns the type of sort. Should return SortField.SCORE, SortField.DOC, SortField.STRING, SortField.INTEGER, SortField.FLOAT or SortField.CUSTOM. It is not valid to return SortField.AUTO. This is used by multisearchers to determine how to collate results from their searchers.
* @return One of the constants in SortField.
*/

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 成人店女老板视频在线看 | 天堂成人一区二区三区 | 免费在线看a | 成人在线视频在线观看 | 中文字幕视频在线播放 | 在线观看免费毛片视频 | 国产91成人| 欧美国产第一页 | av在线免费电影 | 精品一区二区免费视频视频 | 999久久国精品免费观看网站 | 海外中文字幕在线观看 | 亚洲综合视频网站 | 免费看一级片 | 激情宗合 | asian超清日本肉体pics | 国产精品免费久久久久久 | 成人免费福利视频 | 欧美一级小视频 | 逼特逼视频在线观看 | 欧美日韩在线视频一区二区 | 杏美月av| 毛片免费大全短视频 | 欧美性受xxx黑人xyx性爽 | 免费人成在线播放 | 久久影院在线观看 | 水卜樱一区二区av | 蜜桃网在线观看 | 久久久一区二区三区精品 | 在线亚洲播放 | 日韩欧美精品电影 | 国产91小视频在线观看 | 亚洲成人午夜精品 | 男女牲高爱潮免费视频男女 | 欧美一级特黄特色大片免费 | 欧美综合日韩 | 黄色国产在线观看 | 久久精品79国产精品 | 欧美性生交xxxxx久久久 | 精品一区二区在线观看视频 | 欧产日产国产精品99 |