{"version":"1.0","provider_name":"Aeologic Blog","provider_url":"https:\/\/www.aeologic.com\/blog","title":"Collapse and Expand Results - Ultimate Solr Guide - Aeologic Blog","type":"rich","width":600,"height":338,"html":"<blockquote class=\"wp-embedded-content\" data-secret=\"5MqE3aNbOY\"><a href=\"https:\/\/www.aeologic.com\/blog\/collapse-and-expand-results-ultimate-solr-guide\/\">Collapse and Expand Results &#8211; Ultimate Solr Guide<\/a><\/blockquote><iframe sandbox=\"allow-scripts\" security=\"restricted\" src=\"https:\/\/www.aeologic.com\/blog\/collapse-and-expand-results-ultimate-solr-guide\/embed\/#?secret=5MqE3aNbOY\" width=\"600\" height=\"338\" title=\"&#8220;Collapse and Expand Results &#8211; Ultimate Solr Guide&#8221; &#8212; Aeologic Blog\" data-secret=\"5MqE3aNbOY\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" class=\"wp-embedded-content\"><\/iframe><script>\n\/*! This file is auto-generated *\/\n!function(d,l){\"use strict\";l.querySelector&&d.addEventListener&&\"undefined\"!=typeof URL&&(d.wp=d.wp||{},d.wp.receiveEmbedMessage||(d.wp.receiveEmbedMessage=function(e){var t=e.data;if((t||t.secret||t.message||t.value)&&!\/[^a-zA-Z0-9]\/.test(t.secret)){for(var s,r,n,a=l.querySelectorAll('iframe[data-secret=\"'+t.secret+'\"]'),o=l.querySelectorAll('blockquote[data-secret=\"'+t.secret+'\"]'),c=new RegExp(\"^https?:$\",\"i\"),i=0;i<o.length;i++)o[i].style.display=\"none\";for(i=0;i<a.length;i++)s=a[i],e.source===s.contentWindow&&(s.removeAttribute(\"style\"),\"height\"===t.message?(1e3<(r=parseInt(t.value,10))?r=1e3:~~r<200&&(r=200),s.height=r):\"link\"===t.message&&(r=new URL(s.getAttribute(\"src\")),n=new URL(t.value),c.test(n.protocol))&&n.host===r.host&&l.activeElement===s&&(d.top.location.href=t.value))}},d.addEventListener(\"message\",d.wp.receiveEmbedMessage,!1),l.addEventListener(\"DOMContentLoaded\",function(){for(var e,t,s=l.querySelectorAll(\"iframe.wp-embedded-content\"),r=0;r<s.length;r++)(t=(e=s[r]).getAttribute(\"data-secret\"))||(t=Math.random().toString(36).substring(2,12),e.src+=\"#?secret=\"+t,e.setAttribute(\"data-secret\",t)),e.contentWindow.postMessage({message:\"ready\",secret:t},\"*\")},!1)))}(window,document);\n\/\/# sourceURL=https:\/\/www.aeologic.com\/blog\/wp-includes\/js\/wp-embed.min.js\n<\/script>\n","thumbnail_url":"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2020\/06\/Collapse-and-exoands-Results-in-solr-2.png","thumbnail_width":1080,"thumbnail_height":622,"description":"The Collapsing query parser and the Expand component combine to form an approach to grouping documents for field collapsing in search results. The Collapsing query parser groups documents (collapsing the result set) according to your parameters, while the Expand component provides access to documents in the collapsed group for use in results display or other processing by a client application. Collapse &amp; Expand can together do what the older&nbsp;Result Grouping&nbsp;(group=true) does for&nbsp;most&nbsp;use-cases but not all. Collapse and Expand are not supported when Result Grouping is enabled. Generally, you should prefer Collapse &amp; Expand. Collapsing Query Parser The&nbsp;CollapsingQParser&nbsp;is really a&nbsp;post filter&nbsp;that provides more performant field collapsing than Solr\u2019s standard approach when the number of distinct groups in the result set is high. This parser collapses the result set to a single document per group before it forwards the result set to the rest of the search components. So all downstream components (faceting, highlighting, etc.) will work with the collapsed result set. The CollapsingQParser accepts the following local parameters:fieldThe field that is being collapsed on. The field must be a single valued String, Int or Float-type of field.min&nbsp;or&nbsp;max Selects the group head document for each group based on which document has the min or max value of the specified numeric field or&nbsp;function query. At most only one of the&nbsp;min,&nbsp;max, or&nbsp;sort&nbsp;(see below) parameters may be specified. If none are specified, the group head document of each group will be selected based on the highest scoring document in that group. The default is none.sort Selects the group head document for each group based on which document comes first according to the specified&nbsp;sort string. At most only one of the&nbsp;min,&nbsp;max, (see above) or&nbsp;sort&nbsp;parameters may be specified. If none are specified, the group head document of each group will be selected based on the highest scoring document in that group. The default is none.nullPolicyThere are three available null policies: ignore: removes documents with a null value in the collapse field. This is the default. expand: treats each document with a null value in the collapse field as a separate group. collapse: collapses all documents with a null value into a single group using either highest score, or minimum\/maximum.The default is&nbsp;ignore. hint Currently there is only one hint available:&nbsp;top_fc, which stands for top level FieldCache. The&nbsp;top_fc&nbsp;hint is only available when collapsing on String fields.&nbsp;top_fc&nbsp;usually provides the best query time speed but takes the longest to warm on startup or following a commit.&nbsp;top_fc&nbsp;will also result in having the collapsed field cached in memory twice if it\u2019s used for faceting or sorting. For very high cardinality (high distinct count) fields,&nbsp;top_fc&nbsp;may not fare so well. The default is none.size Sets the initial size of the collapse data structures when collapsing on a&nbsp;numeric field only. The data structures used for collapsing grow dynamically when collapsing on numeric fields. Setting the size above the number of results expected in the result set will eliminate the resizing cost. The default is 100,000. Sample Usage Syntax Collapse on&nbsp;group_field&nbsp;selecting the document in each group with the highest scoring document: Collapse on&nbsp;group_field&nbsp;selecting the document in each group with the minimum value of&nbsp;numeric_field: Collapse on&nbsp;group_field&nbsp;selecting the document in each group with the maximum value of&nbsp;numeric_field: Collapse on&nbsp;group_field&nbsp;selecting the document in each group with the maximum value of a function. Note that the&nbsp;cscore()&nbsp;function can be used with the min\/max options to use the score of the current document being collapsed. Collapse on&nbsp;group_field&nbsp;with a null policy so that all docs that do not have a value in the&nbsp;group_field&nbsp;will be treated as a single group. For each group, the selected document will be based first on a&nbsp;numeric_field, but ties will be broken by score: Collapse on&nbsp;group_field&nbsp;with a hint to use the top level field cache: The CollapsingQParserPlugin fully supports the QueryElevationComponent. Expand Component The ExpandComponent can be used to expand the groups that were collapsed by the CollapsingQParserPlugin. Example usage with the CollapsingQParserPlugin: In the query above, the CollapsingQParserPlugin will collapse the search results on the&nbsp;ISBN&nbsp;field. The main search results will contain the highest ranking document from each book. The ExpandComponent can now be used to expand the results so you can see the documents grouped by ISBN. For example: The \u201cexpand=true\u201d parameter turns on the ExpandComponent. The ExpandComponent adds a new section to the search output labeled \u201cexpanded\u201d. Inside the expanded section there is a&nbsp;map&nbsp;with each group head pointing to the expanded documents that are within the group. As applications iterate the main collapsed result set, they can access the&nbsp;expanded&nbsp;map to retrieve the expanded groups. The ExpandComponent has the following parameters:expand.sortOrders the documents within the expanded groups. The default is&nbsp;score desc.expand.rowsThe number of rows to display in each group. The default is 5 rows.expand.qOverrides the main query (q), determines which documents to include in the main group. The default is to use the main query.expand.fqOverrides main filter queries (fq), determines which documents to include in the main group. The default is to use the main filter queries. This is it for today, stay tuned for more informative posts in future."}