4

I have implemented Solr search in one of my .net application. Everything working fine except whenever I try to use the Solr's search functionalities, it's returning only 10 results, while I have more than 100 documents indexed. Can anyone please tell me how can I fixed this issue?

Some examples that demonstrate are:

http://117.55.242.204:8983/solr/select/?q=:&start=0&rows=10

returning 10 rows.

http://117.55.242.204:8983/solr/select/?q=.&start=20&rows=30

returning 0 rows but showing numFound 10.

nbro
  • 15,395
  • 32
  • 113
  • 196
Anu
  • 753
  • 2
  • 13
  • 22

3 Answers3

3

You have to pay attention to two variables here: start and rows.

In the first case, it is only returning 10 documents because rows is 10. In the second case, it is trying to return documents 21 through 30 (start is 20 and rows is 10) but there are only 10 matching documents so it's returning zero.

If you want all your documents to be returned, set rows to a high value like 1000 or 10000 or the number of documents in your index. If you're not paging, make sure start is set to 0.

Ansari
  • 8,168
  • 2
  • 23
  • 34
  • i have to display them in grid and implemented paging so i need to varry start index.. – Anu May 08 '12 at 05:43
  • So make sure to do that when you generate your Solr query. Make sure the sum of your `start` and `rows` variables don't go over `numFound`. – Ansari May 08 '12 at 05:46
  • yes i did but i couldn't understand if i have more than 80 docs indexed. and my query is matching with about 10 results thats why numFound is giving 10, but i still not getting response body as empty...00on20*.*30 – Anu May 08 '12 at 06:31
  • I don't understand what you're confused about. It says numFound is 10. The query is requesting documents 21-30 when only 10 exist, so the number of documents returned is going to be zero. As for why the response body is not empty, Solr responds with a header indicating different bits of information. The docs section is empty. – Ansari May 08 '12 at 06:36
  • see this query is saying 15 matching but returning only 1 doc 01 – Anu May 08 '12 at 07:26
  • i have given start index to it as 0. – Anu May 08 '12 at 07:27
  • Where is `rows`? Can you post the full query and full response? – Ansari May 08 '12 at 07:30
  • my query is http://117.55.242.204:8983/solr/select/?q=*.*&facet=on&facet.field=currentEmployer. solr response is 00currentEmployer*.*on – Anu May 08 '12 at 08:16
  • see all of my queries are returning just 10 rows. i just wanted to know from where the default limit of search results will change. – Anu May 08 '12 at 08:16
  • 1
    You have to set the `rows` variable in Solrnet. See @PaigeCook's answer on how to do that. – Ansari May 08 '12 at 19:30
2

As @Ansari stated in his answer, you need to pass the start and rows parameters to the Solr Query. In order to facilitate this using the SolrNet client, you need to set these as query options in your application. Here is the example code from the Pagination section of the Querying documentation for SolrNet.

 ISolrOperations<Product> solr = ...
 solr.Query("somequery", new QueryOptions{
   Start = 10,
   Rows = 25
 });

So in this example we are assuming more than 35 results will be found and it is stating to start with the 10th item and return 25 items. So this is returning items 10-35 of the total items found in the query.

Paige Cook
  • 22,415
  • 3
  • 57
  • 68
1

I agree with Ansari's answer, however I have one comment. You can't simply set rows to some obscenely high number, because pagination is a natural and intuitive way to use solr.

If it was a performance sensible operation or even logical operation, then there would be an easy way to return all documents. The fact that no such thing exists, this means that short iterative pagination rather then returning a large data set is the way to go.

AbuZubair
  • 1,236
  • 14
  • 20