Search code examples
vb.netsolrsolrnet

Query results don't match NumFound when using SolrNet with VB.NET


I have implemented SolrNet in a VB.NET web site and it's working perfectly with one exception. My results object may tell me that 10 matching "documents" have been found but the collection only contains 9.

My collection always contains 1 less than the NumFound property states. I have run the queries directly through my Solr instance and I know that the NumFound property is reflecting the correct value. Having reviewed the returned documents I can see that the first document in each result set is missing from my collection i.e. the one at position 0.

This seems like a problem connected to a zero indexed collection.

I can't see that I'm doing anything wrong and suspect that this is a bug. Has anyone else experienced this or can you suggest where I may have gone wrong?

Source code is as follows

Private Prods As New SolrQueryResults(Of BLL.solrProduct)

Dim solr As ISolrOperations(Of BLL.solrProduct) = ServiceLocator.Current.GetInstance(Of ISolrOperations(Of BLL.solrProduct))() 

Dim SolrQueryOptions As New SolrNet.Commands.Parameters.QueryOptions() With {.Stats = New StatsParameters(), .Start = PagingCurrent, .Rows = PagingSize, .Facet = New FacetParameters() With { _ 
.MinCount = 1, .Queries = New SolrNet.ISolrFacetQuery() {New SolrFacetFieldQuery("brand")}}}  

SolrQueryOptions.Stats.AddField("selling_price")

SolrQueryOptions.FilterQueries.Add(New SolrQueryByField("brand", "puma"))

Prods = solr.Query("shirt", SolrQueryOptions)

PagingTotal = Prods.NumFound    'This returns 10
lv_prods.DataSource = Prods
lv_prods.DataBind()             'This renders 9 items

Solution

  • Solr pagination is zero-based, i.e. the first item corresponds to Start=0