Lucene相关度排序

来源:互联网 发布:java实现加减乘除 编辑:程序博客网 时间:2024/05/21 22:35

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  numberDocument document=indexSearcher.doc(docID);System.out.println("docID=="+document.get("id")+"==对应的得分..."+f);}}}


0 0