You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Michael Dürr <al...@gmail.com> on 2017/02/26 06:08:06 UTC

Boolean expression for spatial query

Hi all,

I index documents containing a spatial field (rpt) that holds a wkt
multipolygon. In order to retrieve all documents for which a certain point
is contained within a polygon I issue the following query:

q=*:*&fq={!field f=regionGeometry}Contains(POINT(<x> <y>))

This works pretty good.

My question is: Is there any syntax to issue this query for multiple points
(i.e. return all documents for which at least one of the points is within
the document's polygon)?

E.g. something like this:

q=*:*&fq={!field f=regionGeometry}ContainsOR(POINT(<x1> <y1>),POINT(<x2>
<y2>),...)

If not - what other efficient options do you xuggest to do such a query?

Best regards,
Michael

Re: Boolean expression for spatial query

Posted by David Smiley <da...@gmail.com>.
I recommend the MULTIPOINT approach.

BTW if you go the route of multiple OR'ed sub-clauses, I recommend avoiding
the _query_ syntax which predates Solr 4.x's (4.2?) ability to embed fully
the sub-clauses more naturally; though you need to beware of the gotcha of
needing to add a leading space.  If Solr had this feature from the start
then that _query_ hack never would have been added.  For example:
fq=   {!field f=regionGeometry v="Intersects(POINT(x1, y1))"} OR
{!field f=regionGeometry v="Intersects(POINT(x2, y2))"}

Any way, MULTIPOINT is probably going to be much faster, plus it's more
intuitive to understand.  And avoid the "Contains" predicate when point
data is involved as it's slower yet semantically equivalent to "Intersects"
(for a single non-multi point any way)

On Mon, Feb 27, 2017 at 4:12 AM Emir Arnautovic <
emir.arnautovic@sematext.com> wrote:

> Hi Michael,
>
> I haven't been playing with spatial for a while, but if it fully
> supports WKT, you could use Intersects instead of Contains and
> MULTIPOINT instead of POINT. Something like:
>
> fq={!field f=regionGeometry}Intersects(MULTIPOINT((x1 y1), (x2, y2)))
>
> In any case you can use OR-ed _query_:
>
> fq=_query_:"{!field f=regionGeometry}Contains(POINT(x1, y1))" OR
> _query_:"{!field f=regionGeometry}Contains(POINT(x2, y2))"
>
>
> HTH
> Emir
>
>
> On 26.02.2017 07:08, Michael Dürr wrote:
> > Hi all,
> >
> > I index documents containing a spatial field (rpt) that holds a wkt
> > multipolygon. In order to retrieve all documents for which a certain
> point
> > is contained within a polygon I issue the following query:
> >
> > q=*:*&fq={!field f=regionGeometry}Contains(POINT(<x> <y>))
> >
> > This works pretty good.
> >
> > My question is: Is there any syntax to issue this query for multiple
> points
> > (i.e. return all documents for which at least one of the points is within
> > the document's polygon)?
> >
> > E.g. something like this:
> >
> > q=*:*&fq={!field f=regionGeometry}ContainsOR(POINT(<x1> <y1>),POINT(<x2>
> > <y2>),...)
> >
> > If not - what other efficient options do you xuggest to do such a query?
> >
> > Best regards,
> > Michael
> >
>
> --
> Monitoring * Alerting * Anomaly Detection * Centralized Log Management
> Solr & Elasticsearch Support * http://sematext.com/
>
> --
Lucene/Solr Search Committer, Consultant, Developer, Author, Speaker
LinkedIn: http://linkedin.com/in/davidwsmiley | Book:
http://www.solrenterprisesearchserver.com

Re: Boolean expression for spatial query

Posted by Emir Arnautovic <em...@sematext.com>.
Hi Michael,

I haven't been playing with spatial for a while, but if it fully 
supports WKT, you could use Intersects instead of Contains and 
MULTIPOINT instead of POINT. Something like:

fq={!field f=regionGeometry}Intersects(MULTIPOINT((x1 y1), (x2, y2)))

In any case you can use OR-ed _query_:

fq=_query_:"{!field f=regionGeometry}Contains(POINT(x1, y1))" OR 
_query_:"{!field f=regionGeometry}Contains(POINT(x2, y2))"


HTH
Emir


On 26.02.2017 07:08, Michael D�rr wrote:
> Hi all,
>
> I index documents containing a spatial field (rpt) that holds a wkt
> multipolygon. In order to retrieve all documents for which a certain point
> is contained within a polygon I issue the following query:
>
> q=*:*&fq={!field f=regionGeometry}Contains(POINT(<x> <y>))
>
> This works pretty good.
>
> My question is: Is there any syntax to issue this query for multiple points
> (i.e. return all documents for which at least one of the points is within
> the document's polygon)?
>
> E.g. something like this:
>
> q=*:*&fq={!field f=regionGeometry}ContainsOR(POINT(<x1> <y1>),POINT(<x2>
> <y2>),...)
>
> If not - what other efficient options do you xuggest to do such a query?
>
> Best regards,
> Michael
>

-- 
Monitoring * Alerting * Anomaly Detection * Centralized Log Management
Solr & Elasticsearch Support * http://sematext.com/