Question

As mentioned in the question I am trying to utilize Solr's result grouping feature to (surprise) group my search results. From what I understand Solrnet 0.3.1 supports field collapsing but is broken for Solr because Solr replaced field collapsing with results grouping in version 3.3.

I have seen that Solrnet 0.4.0 alpha supports grouping however I don't think it is possible for me to utilize that for my current project as it is alpha and I would have a tough time justifying it to the customer. Unless someone can list some fairly compelling arguments to the contrary that an alpha would be 'unsafe'.

I have also tried adding the group parameters by setting the ExtraParams like so:

 ExtraParams = new Dictionary<string, string>{{"group", "true"}, {"group.field", "fieldName"}}

This throws a NullReferenceException:

         at SolrNet.Impl.ResponseParsers.ResultsResponseParser`1.Parse(XmlDocument xml, SolrQueryResults`1 results) in c:\prg\SolrNet\svn\SolrNet\Impl\ResponseParsers\ResultsResponseParser.cs:line 35
       at SolrNet.Impl.SolrQueryResultParser`1.Parse(String r) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrQueryResultParser.cs:line 46
       at SolrNet.Impl.SolrQueryExecuter`1.Execute(ISolrQuery q, QueryOptions options) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrQueryExecuter.cs:line 309
       at SolrNet.Impl.SolrBasicServer`1.Query(ISolrQuery query, QueryOptions options) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrBasicServer.cs:line 83
       at SolrNet.Impl.SolrServer`1.Query(String q, QueryOptions options) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrServer.cs:line 78
       at RSearch.Core.SearchIndex.Search(String term, Int32 page, Int32 pageSize) in D:\Development\LESA-LARIAT\LariatMapper\Core\SearchIndex.cs:line 153
       at RSearch.Controllers.SearchController.Index(SearchInfo searchInfo) in D:\Development\LESA-LARIAT\LariatWeb\Controllers\SearchController.cs:line 16
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.
<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)

My guess at why it does this is Solrnet doesn't understand the structure of results passed back to it so it throws this exception.

I would really like to be able to do this as I feel it's a little 'dirty' to use Solrnet to leverage all of Solr's features but have the grouping done via LINQ after the query is returned. If it is my only option I don't mind using it though.

Thank you for your help.

Was it helpful?

Solution

In short: no, there is no way with that combo of Solr/SolrNet versions. SolrNet 0.3.1 implemented field collapsing for a nightly build of Solr, when it just started implementing field collapsing (it wasn't called 'grouping' then). After that, field collapsing was completely overhauled in Solr (now called 'result grouping'), and the SolrNet 0.3.1 implementation was left obsolete.

Support for result grouping was added shortly after that and released with 0.4.0a1.

I recommend going with 0.4.0a1. It's not 'unsafe' as in 'unstable' at all:

Doing grouping client-side (i.e. LINQ) is not really an option, as you have to fetch all the documents to do so properly. It's just like wanting to to pagination + sorting client-side with a relational database.

You may also be able to backport result grouping to 0.3.1, but IMHO is really pointless and a waste of time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top