http://XXXXXXX:8080/solr/CultureSearch/select/?q=*:*&indent=on&facet=on&facet.field=domain&facet.limit=1500
group也有类似的用法,区别是他俩显示结果稍微不同,根据自己的需求来用。
Faceting
As described in the section Overview of Searching in Solr, faceting is the arrangement of search results into categories based on indexed terms. Searchers are presented with the indexed terms, along with numerical counts of how many matching documents were found were each term. Faceting makes it easy for users to explore search results, narrowing in on exactly the results they are looking for.
Topics covered in this section:
General Parameters
Field-Value Faceting Parameters
Range Faceting
Date Faceting Parameters
Pivot (Decision Tree) Faceting
Interval Faceting
Local Parameters for Faceting
Related Topics
The table below summarizes the general parameters for controlling faceting.
Parameter |
Description |
---|---|
facet |
If set to true, enables faceting. |
facet.query |
Specifies a Lucene query to generate a facet count. |
These parameters are described in the sections below.
facet
ParameterIf set to "true," this parameter enables facet counts in the query response. If set to "false" to a blank or missing value, this parameter disables faceting. None of the other parameters listed below will have any effect unless this parameter is set to "true." The default value is blank.
facet.query
ParameterThis parameter allows you to specify an arbitrary query in the Lucene default syntax to generate a facet count. By default, Solr's faceting feature automatically determines the unique terms for a field and returns a count for each of those terms. Using facet.query
, you can override this default behavior and select exactly which terms or expressions you would like to see counted. In a typical implementation of faceting, you will specify a number of facet.query
parameters. This parameter can be particularly useful for numeric-range-based facets or prefix-based facets.
You can set the facet.query
parameter multiple times to indicate that multiple queries should be used as separate facet constraints.
To use facet queries in a syntax other than the default syntax, prefix the facet query with the name of the query notation. For example, to use the hypothetical myfunc
query parser, you could set the facet.query
parameter like so:
facet.query={!myfunc}name~fred
Several parameters can be used to trigger faceting based on the indexed terms in a field.
When using this parameter, it is important to remember that "term" is a very specific concept in Lucene: it relates to the literal field/value pairs that are indexed after any analysis occurs. For text fields that include stemming, lowercasing, or word splitting, the resulting terms may not be what you expect. If you want Solr to perform both analysis (for searching) and faceting on the full literal strings, use the copyField
directive in the schema.xml
file to create two versions of the field: one Text and one String. Make sure both are indexed="true"
. (For more information about the copyField
directive, see Documents, Fields, and Schema Design.)
The table below summarizes Solr's field value faceting parameters.
Parameter |
Description |
---|---|
facet.field |
Identifies a field to be treated as a facet. |
facet.prefix |
Limits the terms used for faceting to those that begin with the specified prefix. |
facet.contains | Limits the terms used for faceting to those that contain the specified substring. |
facet.contains.ignoreCase | If facet.contains is used, ignore case when searching for the specified substring. |
facet.sort |
Controls how faceted results are sorted. |
facet.limit |
Controls how many constraints should be returned for each facet. |
facet.offset |
Specifies an offset into the facet results at which to begin displaying facets. |
facet.mincount |
Specifies the minimum counts required for a facet field to be included in the response. |
facet.missing |
Controls whether Solr should compute a count of all matching results which have no value for the field, in addition to the term-based constraints of a facet field. |
facet.method |
Selects the algorithm or method Solr should use when faceting a field. |
facet.enum.cache.minDF |
(Advanced) Specifies the minimum document frequency (the number of documents matching a term) for which the |
facet.overrequest.count | (Advanced) A number of documents, beyond the effective facet.limit to request from each shard in a distributed search |
facet.overrequest.ratio | (Advanced) A multiplier of the effective facet.limit to request from each shard in a distributed search |
facet.threads |
(Advanced) Controls parallel execution of field faceting |
These parameters are described in the sections below.
facet.field
ParameterThe facet.field
parameter identifies a field that should be treated as a facet. It iterates over each Term in the field and generate a facet count using that Term as the constraint. This parameter can be specified multiple times in a query to select multiple facet fields.
Icon
If you do not set this parameter to at least one field in the schema, none of the other parameters described in this section will have any effect.
facet.prefix
ParameterThe facet.prefix
parameter limits the terms on which to facet to those starting with the given string prefix. This does not limit the query in any way, only the facets that would be returned in response to the query.
This parameter can be specified on a per-field basis with the syntax of f.<fieldname>.facet.prefix
.
facet.contains
ParameterThe facet.contains
parameter limits the terms on which to facet to those containing the given substring. This does not limit the query in any way, only the facets that would be returned in response to the query.
This parameter can be specified on a per-field basis with the syntax of f.<fieldname>.facet.contains
.
facet.contains.ignoreCase
ParameterIf facet.contains
is used, the facet.contains.ignoreCase
parameter causes case to be ignored when matching the given substring against candidate facet terms.
This parameter can be specified on a per-field basis with the syntax of f.<fieldname>.facet.contains.ignoreCase
.
facet.sort
ParameterThis parameter determines the ordering of the facet field constraints.
|
Results |
---|---|
count |
Sort the constraints by count (highest count first). |
index |
Return the constraints sorted in their index order (lexicographic by indexed term). For terms in the ASCII range, this will be alphabetically sorted. |
The default is count
if facet.limit
is greater than 0, otherwise, the default is index
.
This parameter can be specified on a per-field basis with the syntax of f.<fieldname>.facet.sort
.
facet.limit
ParameterThis parameter specifies the maximum number of constraint counts (essentially, the number of facets for a field that are returned) that should be returned for the facet fields. A negative value means that Solr will return unlimited number of constraint counts.
The default value is 100.
This parameter can be specified on a per-field basis to apply a distinct limit to each field with the syntax of f.<fieldname>.facet.limit
.
facet.offset
ParameterThe facet.offset
parameter indicates an offset into the list of constraints to allow paging.
The default value is 0.
This parameter can be specified on a per-field basis with the syntax of f.<fieldname>.facet.offset
.
facet.mincount
ParameterThe facet.mincount
parameter specifies the minimum counts required for a facet field to be included in the response. If a field's counts are below the minimum, the field's facet is not returned.
The default value is 0.
This parameter can be specified on a per-field basis with the syntax of f.<fieldname>.facet.mincount
.
facet.missing
ParameterIf set to true, this parameter indicates that, in addition to the Term-based constraints of a facet field, a count of all results that match the query but which have no facet value for the field should be computed and returned in the response.
The default value is false.
This parameter can be specified on a per-field basis with the syntax of f.<fieldname>.facet.missing
.
facet.method
ParameterThe facet.method parameter selects the type of algorithm or method Solr should use when faceting a field.
Setting |
Results |
---|---|
enum |
Enumerates all terms in a field, calculating the set intersection of documents that match the term with documents that match the query. This method is recommended for faceting multi-valued fields that have only a few distinct values. The average number of values per document does not matter. For example, faceting on a field with U.S. States such as |
fc |
Calculates facet counts by iterating over documents that match the query and summing the terms that appear in each document. This is currently implemented using an |
fcs |
Per-segment field faceting for single-valued string fields. Enable with |
The default value is fc
(except for fields using the BoolField
field type) since it tends to use less memory and is faster when a field has many unique terms in the index.
This parameter can be specified on a per-field basis with the syntax of f.<fieldname>.facet.method
.
facet.enum.cache.minDf
ParameterThis parameter indicates the minimum document frequency (the number of documents matching a term) for which the filterCache should be used when determining the constraint count for that term. This is only used with the facet.method=enum
method of faceting.
A value greater than zero decreases the filterCache's memory usage, but increases the time required for the query to be processed. If you are faceting on a field with a very large number of terms, and you wish to decrease memory usage, try setting this parameter to a value between 25 and 50, and run a few tests. Then, optimize the parameter setting as necessary.
The default value is 0, causing the filterCache to be used for all terms in the field.
This parameter can be specified on a per-field basis with the syntax of f.<fieldname>.facet.enum.cache.minDF
.
In some situations, the accuracy in selecting the "top" constraints returned for a facet in a distributed Solr query can be improved by "Over Requesting" the number of desired constraints (ie: facet.limit
) from each of the individual Shards. In these situations, each shard is by default asked for the top "10 + (1.5 * facet.limit)
" constraints.
In some situations, depending on how your docs are partitioned across your shards, and what facet.limit
value you used, you may find it advantageous to increase or decrease the amount of over-requesting Solr does. This can be achieved by setting the facet.overrequest.count
(defaults to 10) and facet.overrequest.ratio
(defaults to 1.5) parameters.
facet.threads
ParameterThis param will cause loading the underlying fields used in faceting to be executed in parallel with the number of threads specified. Specify as facet.threads=N
where N
is the maximum number of threads used. Omitting this parameter or specifying the thread count as 0 will not spawn any threads, and only the main request thread will be used. Specifying a negative number of threads will create up to Integer.MAX_VALUE threads.
You can use Range Faceting on any date field or any numeric field that supports range queries. This is particularly useful for stitching together a series of range queries (as facet by query) for things like prices. As of Solr 3.1, Range Faceting is preferred over Date Faceting (described below).
Parameter |
Description |
---|---|
facet.range |
Specifies the field to facet by range. |
facet.range.start |
Specifies the start of the facet range. |
facet.range.end |
Specifies the end of the facet range. |
facet.range.gap |
Specifies the span of the range as a value to be added to the lower bound. |
facet.range.hardend |
A boolean parameter that specifies how Solr handles a range gap that cannot be evenly divided between the range start and end values. If true, the last range constraint will have the |
facet.range.include |
Specifies inclusion and exclusion preferences for the upper and lower bounds of the range. See the |
facet.range.other |
Specifies counts for Solr to compute in addition to the counts for each facet range constraint. |
facet.range
ParameterThe facet.range
parameter defines the field for which Solr should create range facets. For example:
facet.range=price&facet.range=age
facet.range.start
ParameterThe facet.range.start
parameter specifies the lower bound of the ranges. You can specify this parameter on a per field basis with the syntax of f.<fieldname>.facet.range.start
. For example:
f.price.facet.range.start=0.0&f.age.facet.range.start=10
facet.range.end
ParameterThe facet.range.end specifies the upper bound of the ranges. You can specify this parameter on a per field basis with the syntax of f.<fieldname>.facet.range.end
. For example:
f.price.facet.range.end=1000.0&f.age.facet.range.start=99
facet.range.gap
ParameterThe span of each range expressed as a value to be added to the lower bound. For date fields, this should be expressed using the DateMathParser
syntax (such as, facet.range.gap=%2B1DAY ... '+1DAY'
). You can specify this parameter on a per-field basis with the syntax of f.<fieldname>.facet.range.gap
. For example:
f.price.facet.range.gap=100&f.age.facet.range.gap=10
facet.range.hardend
ParameterThe facet.range.hardend
parameter is a Boolean parameter that specifies how Solr should handle cases where the facet.range.gap
does not divide evenly between facet.range.start
and facet.range.end
. If true, the last range constraint will have the facet.range.end
value as an upper bound. If false, the last range will have the smallest possible upper bound greater then facet.range.end
such that the range is the exact width of the specified range gap. The default value for this parameter is false.
This parameter can be specified on a per field basis with the syntax f.<fieldname>.facet.range.hardend
.
facet.range.include
ParameterBy default, the ranges used to compute range faceting between facet.range.start
and facet.range.end
are inclusive of their lower bounds and exclusive of the upper bounds. The "before" range defined with the facet.range.other
parameter is exclusive and the "after" range is inclusive. This default, equivalent to "lower" below, will not result in double counting at the boundaries. You can use the facet.range.include
parameter to modify this behavior using the following options:
Option |
Description |
---|---|
lower |
All gap-based ranges include their lower bound. |
upper |
All gap-based ranges include their upper bound. |
edge |
The first and last gap ranges include their edge bounds (lower for the first one, upper for the last one) even if the corresponding upper/lower option is not specified. |
outer |
The "before" and "after" ranges will be inclusive of their bounds, even if the first or last ranges already include those boundaries. |
all |
Includes all options: lower, upper, edge, outer. |
You can specify this parameter on a per field basis with the syntax of f.<fieldname>.facet.range.include
, and you can specify it multiple times to indicate multiple choices.
Icon
To ensure you avoid double-counting, do not choose both lower
and upper
, do not choose outer
, and do not choose all
.
facet.range.other
ParameterThe facet.range.other
parameter specifies that in addition to the counts for each range constraint between facet.range.start
and facet.range.end
, counts should also be computed for these options:
Option |
Description |
---|---|
before |
All records with field values lower then lower bound of the first range. |
after |
All records with field values greater then the upper bound of the last range. |
between |
All records with field values between the start and end bounds of all ranges. |
none |
Do not compute any counts. |
all |
Compute counts for before, between, and after. |
This parameter can be specified on a per field basis with the syntax of f.<fieldname>.facet.range.other
. In addition to the all
option, this parameter can be specified multiple times to indicate multiple choices, but none
will override all other options.
Date Ranges & Time Zones
Icon
Range faceting on date fields is a common situation where the TZ
parameter can be useful to ensure that the "facet counts per day" or "facet counts per month" are based on a meaningful definition of when a given day/month "starts" relative to a particular TimeZone.
For more information, see the examples in the Working with Dates section.
Date faceting using the type specific facet.date
parameters has been deprecated since Solr 3.1. Existing users are encouraged to switch to using the more general Range Faceting, which provides the same features for date fields, but can also work with any numeric field.
The response format is slightly different, but the request parameters are virtually identical.
Pivoting is a summarization tool that lets you automatically sort, count, total or average data stored in a table. The results are typically displayed in a second table showing the summarized data. Pivot faceting lets you create a summary table of the results from a faceting documents by multiple fields.
Another way to look at it is that the query produces a Decision Tree, in that Solr tells you "for facet A, the constraints/counts are X/N, Y/M, etc. If you were to constrain A by X, then the constraint counts for B would be S/P, T/Q, etc.". In other words, it tells you in advance what the "next" set of facet results would be for a field if you apply a constraint from the current facet results.
The facet.pivot
parameter defines the fields to use for the pivot. Multiple facet.pivot
values will create multiple "facet_pivot" sections in the response. Separate each list of fields with a comma.
The facet.pivot.mincount
parameter defines the minimum number of documents that need to match in order for the facet to be included in results. The default is 1.
Using the "bin/solr -e techproducts
" example, A query URL like this one will returns the data below, with the pivot faceting results found in the section "facet_pivot":
http://localhost:8983/solr/techproducts/select?q=*:*&facet.pivot=cat,popularity,inStock
&facet.pivot=popularity,cat&facet=true&facet.field=cat&facet.limit=5
&rows=0&wt=json&indent=true&facet.pivot.mincount=2
|
"facet_counts"
:{
"facet_queries"
:{},
"facet_fields"
:{
"cat"
:[
"electronics"
,
14
,
"currency"
,
4
,
"memory"
,
3
,
"connector"
,
2
,
"graphics card"
,
2
]},
"facet_dates"
:{},
"facet_ranges"
:{},
"facet_pivot"
:{
"cat,popularity,inStock"
:[{
"field"
:
"cat"
,
"value"
:
"electronics"
,
"count"
:
14
,
"pivot"
:[{
"field"
:
"popularity"
,
"value"
:
6
,
"count"
:
5
,
"pivot"
:[{
"field"
:
"inStock"
,
"value"
:
true
,
"count"
:
5
}]},
...
|
In addition to some of the general local parameters supported by other types of faceting, a stats
local parameters can be used with facet.pivot
to refer to stats.field
instances (by tag) that you would like to have computed for each Pivot Constraint.
In the example below, two different (overlapping) sets of statistics are computed for each of the facet.pivot result hierarchies:
stats=true
stats.field={!tag=piv1,piv2 min=true max=true}price
stats.field={!tag=piv2 mean=true}popularity
facet=true
facet.pivot={!stats=piv1}cat,inStock
facet.pivot={!stats=piv2}manu,inStock
|
Results:
"facet_pivot"
:{
"cat,inStock"
:[{
"field"
:
"cat"
,
"value"
:
"electronics"
,
"count"
:
12
,
"pivot"
:[{
"field"
:
"inStock"
,
"value"
:
true
,
"count"
:
8
,
"stats"
:{
"stats_fields"
:{
"price"
:{
"min"
:
74.98999786376953
,
"max"
:
399.0
}}}},
{
"field"
:
"inStock"
,
"value"
:
false
,
"count"
:
4
,
"stats"
:{
"stats_fields"
:{
"price"
:{
"min"
:
11.5
,
"max"
:
649.989990234375
}}}}],
"stats"
:{
"stats_fields"
:{
"price"
:{
"min"
:
11.5
,
"max"
:
649.989990234375
}}}},
{
"field"
:
"cat"
,
"value"
:
"currency"
,
"count"
:
4
,
"pivot"
:[{
"field"
:
"inStock"
,
"value"
:
true
,
"count"
:
4
,
"stats"
:{
"stats_fields"
:{
"price"
:{
...
"manu,inStock"
:[{
"field"
:
"manu"
,
"value"
:
"inc"
,
"count"
:
8
,
"pivot"
:[{
"field"
:
"inStock"
,
"value"
:
true
,
"count"
:
7
,
"stats"
:{
"stats_fields"
:{
"price"
:{
"min"
:
74.98999786376953
,
"max"
:
2199.0
},
"popularity"
:{
"mean"
:
5.857142857142857
}}}},
{
"field"
:
"inStock"
,
"value"
:
false
,
"count"
:
1
,
"stats"
:{
"stats_fields"
:{
"price"
:{
"min"
:
479.95001220703125
,
"max"
:
479.95001220703125
},
"popularity"
:{
"mean"
:
7.0
}}}}],
...
|
Although facet.pivot.mincount
deviates in name from the facet.mincount
parameter used by field faceting, many other Field faceting parameters described above can also be used with pivot faceting:
facet.limit
facet.offset
facet.sort
facet.overrequest.count
facet.overrequest.ratio
Another supported form of faceting is interval faceting. This sounds similar to range faceting, but the functionality is really closer to doing facet queries with range queries. Interval faceting allows you to set variable intervals and count the number of documents that have values within those intervals in the specified field.
In order to use interval faceting on a field, it is required that the field has docValues enabled. Even though the same functionality can be achieved by using a facet query with range queries, the implementation of these two methods is very different and will provide different performance depending on the context. If you are concerned about the performance of your searches you should test with both options. Interval faceting tends to be better with multiple intervals for the same fields, while facet query tend to be better in environments where cache is more effective (static indexes for example).
Name |
What it does |
---|---|
facet.interval |
Specifies the field to facet by interval. |
facet.interval.set |
Sets the intervals for the field. |
facet.interval
parameterThis parameter Indicates the field where interval faceting must be applied. It can be used multiple times in the same request to indicate multiple fields. All the interval fields must have docValues=“true” in the schema.
facet.interval=price&facet.interval=size
facet.interval.set
parameterThis parameter is used to set the intervals for the field, it can be specified multiple times to indicate multiple intervals. This parameter is global, which means that it will be used for all fields indicated with facet.interval
unless there is an override for a specific field. To override this parameter on a specific field you can use: f.<fieldname>.facet.interval.set
, for example:
f.price.facet.interval.set=[0,10]&f.price.facet.interval.set=(10,100]
Intervals must begin with either '(' or '[', be followed by the start value, then a comma (','), the end value, and finally a closing ')' or ']’.
For example:
(1,10) -> will include values greater than 1 and lower than 10
[1,10) -> will include values greater or equal to 1 and lower than 10
[1,10] -> will include values greater or equal to 1 and lower or equal to 10
The initial and end values cannot be empty. If the interval needs to be unbounded, the special character '*' can be used for both, start and end limit. When using '*', '(' and '[', and ')' and ']' will be treated equal. [*,*] will include all documents with a value in the field. The interval limits may be strings but there is no need to add quotes. All the text until the comma will be treated as the start limit, and the text after that will be the end limit. For example: [Buenos Aires,New York]. Keep in mind that a string-like comparison will be done to match documents in string intervals (case-sensitive). The comparator can't be changed.
Commas, brackets and square brackets can be escaped by using '\' in front of them. Whitespaces before and after the values will be omitted. The start limit can't be grater than the end limit. Equal limits are allowed, this allows you to indicate the specific values that you want to count, like [A,A], [B,B] and [C,Z].
Interval faceting supports output key replacement described below. Output keys can be replaced in both the facet.interval parameter
and in the facet.interval.set parameter
. For example:
&facet.interval={!key=popularity}some_field
&facet.interval.set={!key=bad}[
0
,
5
]
&facet.interval.set={!key=good}[
5
,*]
&facet=
true
|
The LocalParams syntax allows overriding global settings. It can also provide a method of adding metadata to other parameter values, much like XML attributes.
You can tag specific filters and exclude those filters when faceting. This is useful when doing multi-select faceting.
Consider the following example query with faceting:
q=mainquery&fq=status:public&fq=doctype:pdf&facet=true&facet.field=doctype
Because everything is already constrained by the filter doctype:pdf
, the facet.field=doctype
facet command is currently redundant and will return 0 counts for everything except doctype:pdf
.
To implement a multi-select facet for doctype, a GUI may want to still display the other doctype values and their associated counts, as if the doctype:pdf
constraint had not yet been applied. For example:
=== Document Type ===
[ ] Word (
42
)
[x] PDF (
96
)
[ ] Excel(
11
)
[ ] HTML (
63
)
|
To return counts for doctype values that are currently not selected, tag filters that directly constrain doctype, and exclude those filters when faceting on doctype.
q=mainquery&fq=status:public&fq={!tag=dt}doctype:pdf&facet=true&facet.field={!ex=dt}doctype
Filter exclusion is supported for all types of facets. Both the tag
and ex
local parameters may specify multiple values by separating them with commas.
To change the output key for a faceting command, specify a new name with the key
local parameter. For example:
facet.field={!ex=dt key=mylabel}doctype
The parameter setting above causes the field facet results for the "doctype" field to be returned using the key "mylabel" rather than "doctype" in the response. This can be helpful when faceting on the same field multiple times with different exclusions.