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>
2.URL访问
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.lower={The lower bound term} - Optional. The term to start at. If not specified, the empty string is used, meaning start at the beginning of the field.
- terms.lower.incl={true|false} - Optional. Include the lower bound term in the result set. Default is true.
-
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.prefix={String} - Optional. Restrict matches to terms that start with the prefix.
-
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.
- terms.upper={The upper bound term} - The term to stop at. Either upper or terms.limit must be set.
- terms.upper.incl={true|false} - Include the upper bound term in the result set. Default is false.
- terms.raw={true|false} - If true, return the raw characters of the indexed term, regardless of if it is human readable. For instance, the indexed form of numeric numbers is not human readable. The default is false.
- terms.sort={count|index} - If count, sorts the terms by the term frequency (highest count first). If index, returns the terms in index order. Default is to sort by count.