SOLR Aggregate Queries

Source: Internet
Author: User
Tags min solr
1 Group Queries Overview:There are two types of group queries commonly used in SOLR, facet groupings and group groupings, with the following two queries:
1.1 facet Groupings

The query results of the SOLR species for navigation are faceted, and the count information is added according to the classification on the results of the user query, and then the user makes a further search based on the count information.

Facet is one of SOLR's advanced search features that gives users a more user-friendly search experience. While searching for keywords, you can group and count the fields of the facet.

SOLR Fact provides 4 types of fact

<lstname= "Facet_counts" > 
  <lstname= "facet_queries"/> <lstname= 
  "Facet_fields"/> 
  <lstname= "Facet_dates"/> 
  <lstname= "facet_ranges"/> 
</lst> 
facet_queries: Represents a custom conditional query facet, a database-like count function
Facet_fields    : Represents a grouping of queries based on fields, a combination of groupby count that resembles a database
facet_ Dates: Group query according to date interval
facet_ranges: Of course, the date has the interval, the number also has, this is according to the number grouping query


Description

The basic function of facets is to classify the data in the search results.

Facet Usage

Facet.field: Specifies the field to classify
Facet=on or facet=true indicates that the function is turned
on facet.prefix indicates the field prefix
facet.limit indicates the number
of records returned Facet.offict means starting from the first, mainly for paging
facet.query can arbitrarily define the query
  


Range Facet

Fields that are typically used for date types or numeric types.

&facet=on
&facet.query=date:[2009-1-1t0:0:0zto 2010-1-1t0:0:0z]


Parameter description

Facet.range   need to do facet query field
facet.range.start      set start point
facet.range.end       set end point
Facet.range.gap       limits the interval difference for each range
facet.range.hardend          specifies how to handle the last interval
facet.range.include Specify how the threshold is handled
facet.range.other    Specifies how to handle the result of a bounded range
facet.range.method           Specify the facet algorithm

The following query:

http://localhost:8983/solr/solr_select/query?q=*:* &facet=on&facet.field=name

Group query results by Name field




1.2 Group Group

SOLR Group processing of results can also be used in addition to facets. The SOLR group is a field that groups the results, returning the results in each group that satisfy the query sequentially.

Group contrast facet

The concept of group and facet is very similar, it is used to group. Facets return all relevant results and allow the user to redefine the result set based on the facet's catalog. Facets can filter the number of groups, as well as sorting, and date range, time range groupings, but if you want to get specific data, you need to query one or more times. Group can get the number of groups grouped, one request, can get all the data.

Group and facet can be used together, but only Facet.field and Facet.range are used, and date and dimension statistics pivot faceting are not supported.

The following query:

http://localhost:8983/solr/solr_select/query?q=*:* &group=true&group.field=name


Parameter description:

Parameters type Description
Group Boolean value Set to true to indicate that the result needs to be grouped
Group.field String Fields that need to be grouped, Strfield or TextField when the field type is required
Group.func Query statements You can specify a query function
Group.query Query statements You can specify a query statement
Rows Integer Returns how many groups of results, default 10
Start Integer Specify the result start position/offset
Group.limit Integer Returns multiple results per group, default 1
Group.offset Integer Specify the start position/offset of each set of results
Sort Sorting algorithms Control the return order of individual groups
Group.sort Sorting algorithms Control the order within each grouping
Group.format Grouped/simple Set to simple to allow results to be returned as a single list
Group.main Boolean value When set to true, the result will be determined primarily by the grouping command for the first field
Group.ngroups Boolean value When set to True, SOLR returns the number of packets, the default Fasle
Group.truncate Boolean value When set to true, the number of facets will be based on the document with high correlation in group grouping, default Fasle
Group.cache.percent Integer 0-100 is set to greater than 0 o'clock, which indicates the cached result, which defaults to 0. The key for Boolean query, wildcard query, fuzzy query has improved, but will slow down the common word query.




2 Stats Component aggregation query

Summary: SOLR can use statscomponent to implement aggregated statistical queries on numbers, strings, or date fields, that is:min, max, AVG, COUNT, sum functions

Stats Component Parameter Description:

Parameters Description
Stats Boolean value, set to True to open stats Component
Stats.field Specify the fields that need to be counted
Stats.facet Generates a child result set for the specified facet
Stats.calcdistinct Boolean values that will return "countdistinct" and "distinctvalues" at a high cost. Default Fasle

Stats Component Statistical content

Statistical Projects Description Types of support whether the default output
Min Minimum value All Is
Max Maximum Value All Is
Sum And Numbers, dates Is
Count Number All Is
Missing Number of NULL values All Is
Sumofsquares Sum of squares Numbers, dates Is
Mean Mean number, date Is
StdDev Standard deviation Numbers, dates Is
Percentiles Accuracy/Several decimal places Digital Whether
Distinctvalues set/non-repeating value collection All Whether
CountDistinct Set exact number/non-repeating value collection size, very expensive to use All Whether
Cardinality Set number/non-repeating value collection size, may not be accurate All Whether

The following query:

http://localhost:8983/solr/solr_select/select?q=*:* &stats=true&stats.field=id&rows=0&indent= True


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.