Using near in an any_of scope in Sunspot 1.1

18 views
Skip to first unread message

Ian Terrell

unread,
Aug 10, 2010, 2:04:43 PM8/10/10
to Sunspot
I'm build a site that involves searching through job candidates, and a
use case we're supporting is searching for candidates within X miles
of a zip code OR who are willing to relocate.

However, with the query DSL, it appears that near does not work within
an any_of scope. Is this not supported by solr-spatial-light, or can
I go around the DSL to get this functionality? (Maybe
adjust_solr_params?)

Thanks,
Ian

Mat Brown

unread,
Aug 10, 2010, 2:14:29 PM8/10/10
to ruby-s...@googlegroups.com
Hi Ian,

I don't think that's possible with the way solr-spatial-light works --
it recieves the spatial component in its own Solr param so it can't
readily be incorporated into a disjunction.

Sunspot 1.2's geohash approach makes that *more* possible, but the
Sunspot API doesn't support it at the moment. The reason for this is
that the geohash portion of a search is passed via the :q param,
whereas other scope is passed via :fq params. However, I'm now
thinking that in the case that you'd like to disjunct a near()
restriction with something else, you could just put them in the :fq
param and lose distance-based scoring (seems fine for your use case).

Mat

> --
> You received this message because you are subscribed to the Google Groups "Sunspot" group.
> To post to this group, send email to ruby-s...@googlegroups.com.
> To unsubscribe from this group, send email to ruby-sunspot...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ruby-sunspot?hl=en.
>
>

Ian Terrell

unread,
Aug 10, 2010, 2:33:24 PM8/10/10
to Sunspot
Hi Mat,

Thanks. It looks like even in the master branch where 1.2 lives
there's this comment on spatial searches:

# * It can only be called from the top-level query; it cannot be
nested
# in a `dynamic`, `any_of`, or `all_of` block. This is because
geohash
# queries are not sent to Solr as filter queries like other
scopes, but
# rather are part of the fulltext query sent to Solr.

This looks like a solr-spatial-light thing, unless I'm still not
interpreting it properly.

Thanks!
Ian

Mat Brown

unread,
Aug 10, 2010, 2:39:19 PM8/10/10
to ruby-s...@googlegroups.com
Hi Ian,

That comment is correct, but not because of solr-spatial-light -- the
new geohash search uses fulltext boost/scoring to get results in
(rough) order of geographic distance, which is why they have to go
into the :q parameter; :fq queries are always constant-score.

I mulled over a few different options for how to deal with that fact
-- including allowing multiple :q-parameter components in a
disjunction as long as there aren't any :fq-parameter ones -- but
coming up with a good API design and implementation was looking like
it would delay the 1.2 release more than I was willing to.

At this point, though, I'm thinking that a simplified near()
restriction -- no boosting, just a simple prefix on a lower-precision
geohash -- could be allowed inside a disjunction, with the caveat that
results in that case would not be scored/sorted by geographical
distance. Seems like a fairly easy win with no downside, despite not
necessarily being the ideal solution.

Mat

Ian Terrell

unread,
Aug 10, 2010, 3:04:18 PM8/10/10
to Sunspot
Hi Mat,

Thanks for the information. I'm diving into 1.2's approach a bit more
to see if I can pull something together, although I think for this
project I might just work around the limitations of 1.1. I'll keep an
eye out on 1.2's development, though!

Thanks,
Ian

On Aug 10, 11:39 am, Mat Brown <m...@patch.com> wrote:
> Hi Ian,
>
Reply all
Reply to author
Forward
0 new messages