Dealing with partial results

calaveraDeluxe edited this page Feb 23, 2017 · 2 revisions

Sometimes it is possible that Solr returns only partial results. It can be caused for example when you perform expensive query on a large index (more about this can be read on Websolr support page). To deal with that, first you have to do is to detect that you got partial results. If so, you may benefit from retrying your search additional time(s). This is effective because Solr caches results of previous searching.

def results
  retry_search = true
  search_count = 0

  # retry the same search if partial results
  while retry_search && search_count < 2
    search_count += 1
    search = { fulltext 'pizza' } 
    # Look for partialResults in response:
    solr_response = search.instance_eval("@solr_result")
    retry_search = solr_response["responseHeader"]["partialResults"] == true