Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to return distance with the returned solr documents [DATASOLR-122] #247

Closed
spring-projects-issues opened this issue Oct 31, 2013 · 2 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Oct 31, 2013

Divya A opened DATASOLR-122 and commented

In Solr we can pass a latitude and Longitude and if every solr document has a latitude and longitude , we can return the distance back.

e.g: fl=*,distance:geodist()&pt=34.13,-80.9&sfield=latlng

Currently there is an option to set the fields for the fl - addProjectionFields. But if i use that, there is no way to pass the pt and so solr returns errors.


Affects: 1.0 GA

Issue Links:

  • DATASOLR-132 Add support for solr functions
    ("depends on")
  • DATASOLR-130 geodist() cannot be used in projection
    ("is duplicated by")
@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Dec 8, 2013

Christoph Strobl commented

In order to retrieve distance you can add pt and sfield parameters to geodist().

SimpleQuery query = new SimpleQuery(conditions);
query.addProjectionOnField("*");
query.addProjectionOnField("distance:geodist(latlng," + GeoConverters.GeoLocationToStringConverter.INSTANCE.convert(new GeoLocation(34.13, -80.9)) + ")");
Page<EventDocument> result = template.queryForPage(query, YourDocument.class);

in your entity you'll need

@Indexed(readonly=true)
Float distance;

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 2, 2014

Christoph Strobl commented

Property has to be added to entity in order to allow passing value into it.

class SolrEntity {
  @Id
  private String id;
  
  //distance field not to be written when adding document to solr
  @Indexed(false)
  private Float distance;

Using DistanceField within query will make solr calculate distance.

Query q = new SimpleQuery("*:*");
q.addProjectionOnField(new DistanceField("distance", "store", new GeoLocation(45.15, -93.85)));
solrTemplate.queryForPage(q, SolrEntity.class);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants