title: How to return distance and score in spatial search using spring-data-solr
body: <p>I'm writing a Spring MVC based Search API using spring-data-solr 1.0.0.RELEASE with Solr 4.4.0 and Spring 3.2.4.RELEASE.</p>
  
  <p>I'm able to run basic queries but unable to find any good example how can I return score and distance:geodist() in the results. </p>
  
  <p>I know I can get results from Solr using query like </p>
  
  <pre><code>http://localhost:8983/solr/events/select?q=*:*&amp;spatial=true&amp;pt=51.435872%2C-0.427529&amp;sfield=position&amp;d=20&amp;facet=true&amp;facet.mincount=1&amp;facet.limit=-1&amp;facet.field=categoryIds&amp;fl=score,*,distance:geodist()&amp;sort=geodist()+asc
  </code></pre>
  
  <p>but I don't know how to get score and distance properties returned from Solr using spring-data-solr. I have tried following code </p>
  
  <pre><code>FacetQuery search = new SimpleFacetQuery();
  
  Criteria conditions;// = new Criteria();
  if(StringUtils.isNotBlank(searchCriteria.getSearchString()))
          conditions = new Criteria(EventDocument.FIELD_EVENT).contains(searchCriteria.getSearchString());
  
  if(searchCriteria.isLocationKnown()){
          conditions.and(new Criteria(EventDocument.FIELD_POSITION).within(new GeoLocation(searchCriteria.getLatitude(), searchCriteria.getLongitude()), new Distance(searchCriteria.getDistance(), Distance.Unit.MILES)));
          conditions.and(new Criteria(CommonParams.FL).is("score,distance:geodist(),*"));
      } else{
          conditions.and(new Criteria(CommonParams.FL).is("score,*"));
      }
  
  search.addCriteria(conditions);
  FacetPage page = solrTemplate.queryForFacetPage(search, EventDocument.class);
  </code></pre>
  
  <p>but getting following Exception:</p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.data.solr.UncategorizedSolrException: undefined field fl; nested exception is org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: undefined field fl
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
  org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
  org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  root cause
  
  org.springframework.data.solr.UncategorizedSolrException: undefined field fl; nested exception is org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: undefined field fl
  org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:122)
  org.springframework.data.solr.core.SolrTemplate.executeSolrQuery(SolrTemplate.java:330)
  org.springframework.data.solr.core.SolrTemplate.query(SolrTemplate.java:326)
  org.springframework.data.solr.core.SolrTemplate.queryForFacetPage(SolrTemplate.java:285)
  com.johnstonpress.api.repository.EventDocumentRepositoryImpl.search(EventDocumentRepositoryImpl.java:72)
  com.johnstonpress.api.service.SearchEventServiceImpl.search(SearchEventServiceImpl.java:106)
  com.johnstonpress.api.controller.EventsSearchController.searchEvents(EventsSearchController.java:124)
  com.johnstonpress.api.controller.EventsSearchController.search(EventsSearchController.java:68)
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  java.lang.reflect.Method.invoke(Method.java:601)
  org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
  org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
  org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
  org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
  org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
  org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  </code></pre>
  
  <p><strong>Thanks for any attention and help!!!</strong></p>