Lucene相关度排序

Lucene相关度排序

/**
 * 
 * 相关度排序...
 * @author Administrator
 *
 */
public class TestScore {

	/**
	 * @param args
	 * @throws ParseException 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws ParseException, IOException {
		IndexSearcher indexSearcher=LuceneUtils.getIndexSearcher();
		
		String keywords="你不问";
		//根据多个字段进行搜索...
		/**
		 * 1:matchVersion
		 * 
		 * 2:需要根据那些字段进行搜索,数组
		 * 
		 * 3:分词器...  
		 */
		String [] fields ={"title"};
		QueryParser queryParser=new MultiFieldQueryParser(LuceneUtils.getCurrentVersion(),fields,LuceneUtils.getAnalyzer());
		Query query=queryParser.parse(keywords);
		TopDocs topDocs=indexSearcher.search(query, 100);
		ScoreDoc scoreDocs []=topDocs.scoreDocs;
		
		for(ScoreDoc scoreDoc:scoreDocs){
			//这个id 是lucene 自己内部维护的
			int docID=scoreDoc.doc;
			float f=scoreDoc.score;
//			new intFiled("id",article.getId(),Store.YES);肯定不一样,我这边只是去了一个字段的名称叫id,是int  number
			Document document=indexSearcher.doc(docID);
			System.out.println("docID=="+document.get("id")+"==对应的得分..."+f);
		}
		
		
	}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值