简体   繁体   中英

Setting pseudo fields (fl) in Solrj

I want to use a pseudo field to return the distance from the center of my solr (geo) spatial search, like it's explained here: http://wiki.apache.org/solr/SpatialSearch#geodist_-_The_distance_function when it says:

Returning the distance

Solr4.0

You can use the pseudo-field feature to return the distance along with the stored fields of each document by adding fl=geodist() to the request. Use an alias like fl= dist :geodist() to make the distance come back in the dist pseudo-field instead. Here is an example of sorting by distance ascending and returning the distance for each document in dist .

...&q= : &sfield=store&pt=45.15,-93.85&sort=geodist() asc&fl= dist :geodist()

Now, I'm using solrj (4.5.1) and I can't find a way to set the fl=_dist_:geodist() part properly. I can actually manage to add it to the solrQuery object doing:

solrQuery.setParam('fl', '_dist_:geodist()')

with no compilation errors, but for some reason this is messing up my returned documents.

Any ideas how it should be done?

Ps. code is in groovy language, don't freak out for no semi-colons or string within single quotes :)

* UPDATE *

Setting the fl param as explained above, actually results in returning documents which only contains the _dist_ field!

After a few minutes of search, i found this article: http://solr.pl/en/2011/11/22/solr-4-0-new-fl-parameter-functionalities-first-look/

It explains how to return the new alias field(s) in addition to all other parameters, simply like this (please note the * part):

fl=*,stock:sum(stockMain,stockShop)

So, in my example for solrj , it will be:

solrQuery.setParam('fl', '*,_dist_:geodist()')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM