1.solrconfig.xml添加如下配置:
<searchComponent name="terms" class="solr.TermsComponent"/> <!-- A request handler for demonstrating the terms component --> <requestHandler name="/terms" class="solr.SearchHandler" startup="lazy"> <lst name="defaults"> <bool name="terms">true</bool> <bool name="distrib">false</bool> </lst> <arr name="components"> <str>terms</str> </arr> </requestHandler>
http://localhost:8983/solr/test_core/terms?q=*%3A*&wt=json&indent=true&terms.fl=field
返回结果:默认按结果的出现频率倒序排序。
{ "responseHeader":{ "status":0, "QTime":31}, "terms":{ "field":[ "新闻图片",4262, "专题",4261, "设计",3229, "凤凰网",2020, "凤凰新媒体",1980, "创意",1610, "艺术",1170, "时尚",1128, "nba",1025, "新闻",940] } }
相关参数说明
erms={true|false} - Turn on the TermsComponent
terms.fl={FIELD NAME} - Required. The name of the field to get the terms from. May be specified multiple times as terms.fl=field1&terms.fl=field2...
terms.mincount=<Integer> - Optional. The minimum doc frequency to return in order to be included. Results are inclusive of the mincount (i.e. >= mincount)
terms.maxcount=<Integer> - Optional. The maximum doc frequency. Default is -1 to have no upper bound. Results are inclusive of the maxcount (i.e. <= maxcount)
terms.regex={String} - Optional. Restrict matches to terms that match the regular expression. Solr3.1
terms.regex.flag={case_insensitive|comments|multiline|literal|dotall|unicode_case|canon_eq|unix_lines} - Optional. Flags to be used when evaluating the regular expression defined in the "terms.regex" parameter (see http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html#compile%28java.lang.String,%20int%29 fore more details). This parameter can be defined multiple times (each time with different flag) Solr3.1
terms.limit={integer} - The maximum number of terms to return. The default is 10. If < 0, then include all terms.