1. 使用函数df(field,keyword) 和idf(field,keyword).
http://118.85.207.11:11100/solr/mobile/select?q={!func}product%28idf%28title,%E9%97%AE%E9%A2%98%29,tf%28title,%E9%97%AE%E9%A2%98%29%29&fl=title,score,product%28idf%28title,%E9%97%AE%E9%A2%98%29,tf%28title,%E9%97%AE%E9%A2%98%29%29&wt=json
其中tf*idf的值和score的值是相同的.
也可以在solrj中实现:
public class AppTest { @Test public void test1() throws SolrServerException{ HttpSolrServer solrServer = new HttpSolrServer("http://118.85.207.11:11100/solr/mobile"); String keyword = "问题"; SolrQuery solrQuery = new SolrQuery("q={!func}product(idf(title,$keyword),tf(title,$keyword)keyword="+keyword+")"); solrQuery.addField("title,score"); solrQuery.setRows(1); QueryResponse queryResponse = solrServer.query(solrQuery); System.out.println(queryResponse.toString()); } }
结果:
{responseHeader={status=0,QTime=16,params={fl=title,score,q=q={!func}product(idf(title,$keyword),tf(title,$keyword)keyword=问题),wt=javabin,version=2,rows=1}},response={numFound=3,start=0,maxScore=0.078723446,docs=[SolrDocument{title=4G热点问题答疑—套餐篇, score=0.078723446}]},highlighting={10001={title=[4G热点<font color=‘#FF0000‘>问题</font>答疑—套餐篇],content=[4G热点<font color=‘#FF0000‘>问题</font>答疑—套餐篇]}}}
原文:http://www.cnblogs.com/a198720/p/4381670.html