Solr’s New Expand Component

posted in: grouping

Coming in Solr 4.8 is a new search component called the ExpandComponent. The ExpandComponent can be used to expand parent/child relationships in Solr. This blog describes how to use the ExpandComponent to expand the groups that were collapsed by the CollapsingQParserPlugin.

The CollapsingQParserPlugin can be used to collapse search results on a field. for example:

q=”Solr is great”&fq={!collapse field=book}

In the query above, the CollapsingQParserPlugin will collapse the search results on the book 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 book. For example:

q=”Solr is great”&fq={!collapse field=book}&expand=true

In the query above the “expand=true” parameter turns on the ExpandComponent. The ExpandComponent adds a new section to the search output labeled “expanded”.

Inside the expanded section there is a map 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 expanded map to retrieve the expanded groups.

But, wait there’s more. The ExpandComponent takes several parameters that allow you to manage the result list inside the groups:

expand.sort=chapter_num+asc

Orders the documents in the group by ascending chapters. If you don’t provide an expand.sort parameter the order defaults to relevance based on the main query.

expand.rows=10

Determines how many rows to display in each group. The default is 5.

expand.fq=hello
expand.q=world

By default the ExpandComponent returns results that match the main query and all the filter queries. You can override these queries by passing in your own expand.q or multiple expand.fq parameters. This way you can expand results that don’t match the main query.

You may be wondering: can the ExpandComponent be used to expand other parent child relationships besides field collapsing/grouping?

It can. In my next blog I’ll describe how to use the ExpandComponent to expand the child documents of a Solr Block Join.