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 Leo BRUVRY-LAGADEC <Le...@partenaire-exterieur.ifremer.fr> on 2016/09/19 12:48:02 UTC

request SOLR - spatial field with Intersect and Contains functions

Hi,

I am trying spatial search in SOLR 5.0 and I don't know how to implement 
a solution for the problem I will try to explain.

On a SOLR server I have indexed a collection of objects that contains 
spacial field :

<field name="geo" type="location_rpt" indexed="true" stored="true" 
multiValued="true" />
<fieldType name="location_rpt" 
class="solr.SpatialRecursivePrefixTreeFieldType"
                geo="true"
                distErrPct="0.025"
                maxDistErr="0.000009"
                distanceUnits="degrees" />

The spatial data indexed in the field named "geo" can be ENVELOPE or 
LINESTRING :

<field name="geo">LINESTRING(-4.6837 48.5792, -4.6835 48.5788, -4.684 
48.5788, -4.6832 48.579, -4.6837 48.5792, -4.6188 48.6265, -4.6122 
48.63, -4.615 48.6258, -4.6125 48.6215, -4.6112 48.6218)</field>

or

<field name="geo">ENVELOPE(-5.0, -4.0, 49.0, 48.0)</field>

Actually in my application, when I do a SOLR request to get objects that 
are in a spatial area, I do something like this :

q=:&fq=(geo:"Intersects(ENVELOPE(-116.894531, 107.402344, 57.433227, 
-42.146973))")

But I want to change how it work. Now, when the geo field contain an 
ENVELOPE I want to do an CONTAINS request and when it contain a 
LINESTRING I want to do an INTERSECTS request.

example :

If geo = ENVELOPE then q=*:*&fq=(geo:"Contains(ENVELOPE(-116.894531, 
107.402344, 57.433227, -42.146973))")

If geo = LINESTRING then q=*:*&fq=(geo:"Intersects(ENVELOPE(-116.894531, 
107.402344, 57.433227, -42.146973))")

How can my application know if the field contain ENVELOPE or LINESTRING ?

Any idea can this be done ?

Best reguards,
Leo.

Re: request SOLR - spatial field with Intersect and Contains functions

Posted by David Smiley <da...@gmail.com>.
Hi Leo,

You should use two spatial fields for this -- one is for an indexed
Box/Envelope, and another for an indexed LineString.  The indexed box
should use either BBoxField or RptWithGeometrySpatialField, and the
LineString field should use RptWithGeometrySpatialField.   If you have an
older installation 5.x version, RptWithGeometrySpatialField may not be
available in which case settle
for solr.SpatialRecursivePrefixTreeFieldType.  When you do a search, it'd
be a search for one field OR the other with the requirements you have for
each.

~ David

On Mon, Sep 19, 2016 at 8:48 AM Leo BRUVRY-LAGADEC <
Leo.Bruvry.Lagadec@partenaire-exterieur.ifremer.fr> wrote:

> Hi,
>
> I am trying spatial search in SOLR 5.0 and I don't know how to implement
> a solution for the problem I will try to explain.
>
> On a SOLR server I have indexed a collection of objects that contains
> spacial field :
>
> <field name="geo" type="location_rpt" indexed="true" stored="true"
> multiValued="true" />
> <fieldType name="location_rpt"
> class="solr.SpatialRecursivePrefixTreeFieldType"
>                 geo="true"
>                 distErrPct="0.025"
>                 maxDistErr="0.000009"
>                 distanceUnits="degrees" />
>
> The spatial data indexed in the field named "geo" can be ENVELOPE or
> LINESTRING :
>
> <field name="geo">LINESTRING(-4.6837 48.5792, -4.6835 48.5788, -4.684
> 48.5788, -4.6832 48.579, -4.6837 48.5792, -4.6188 48.6265, -4.6122
> 48.63, -4.615 48.6258, -4.6125 48.6215, -4.6112 48.6218)</field>
>
> or
>
> <field name="geo">ENVELOPE(-5.0, -4.0, 49.0, 48.0)</field>
>
> Actually in my application, when I do a SOLR request to get objects that
> are in a spatial area, I do something like this :
>
> q=:&fq=(geo:"Intersects(ENVELOPE(-116.894531, 107.402344, 57.433227,
> -42.146973))")
>
> But I want to change how it work. Now, when the geo field contain an
> ENVELOPE I want to do an CONTAINS request and when it contain a
> LINESTRING I want to do an INTERSECTS request.
>
> example :
>
> If geo = ENVELOPE then q=*:*&fq=(geo:"Contains(ENVELOPE(-116.894531,
> 107.402344, 57.433227, -42.146973))")
>
> If geo = LINESTRING then q=*:*&fq=(geo:"Intersects(ENVELOPE(-116.894531,
> 107.402344, 57.433227, -42.146973))")
>
> How can my application know if the field contain ENVELOPE or LINESTRING ?
>
> Any idea can this be done ?
>
> Best reguards,
> Leo.
>
-- 
Lucene/Solr Search Committer, Consultant, Developer, Author, Speaker
LinkedIn: http://linkedin.com/in/davidwsmiley | Book:
http://www.solrenterprisesearchserver.com

request SOLR - spatial field with Intersect and Contains functions

Posted by Leo BRUVRY-LAGADEC <Le...@partenaire-exterieur.ifremer.fr>.
Hi list,

I am trying spatial search in SOLR 5.0 and I don't know how to implement 
a solution for the problem I will try to explain.

On a SOLR server I have indexed a collection of objects that contains 
spacial field :

<field name="geo" type="location_rpt" indexed="true" stored="true" 
multiValued="true" />
<fieldType name="location_rpt" 
class="solr.SpatialRecursivePrefixTreeFieldType"
                geo="true"
                distErrPct="0.025"
                maxDistErr="0.000009"
                distanceUnits="degrees" />

The spatial data indexed in the field named "geo" can be ENVELOPE or 
LINESTRING :

<field name="geo">LINESTRING(-4.6837 48.5792, -4.6835 48.5788, -4.684 
48.5788, -4.6832 48.579, -4.6837 48.5792, -4.6188 48.6265, -4.6122 
48.63, -4.615 48.6258, -4.6125 48.6215, -4.6112 48.6218)</field>

or

<field name="geo">ENVELOPE(-5.0, -4.0, 49.0, 48.0)</field>

Actually in my application, when I do a SOLR request to get objects that 
are in a spatial area, I do something like this :

q=:&fq=(geo:"Intersects(ENVELOPE(-116.894531, 107.402344, 57.433227, 
-42.146973))")

But I want to change how it work. Now, when the geo field contain an 
ENVELOPE I want to do an CONTAINS request and when it contain a 
LINESTRING I want to do an INTERSECTS request.

example :

If geo = ENVELOPE then q=*:*&fq=(geo:"Contains(ENVELOPE(-116.894531, 
107.402344, 57.433227, -42.146973))")

If geo = LINESTRING then q=*:*&fq=(geo:"Intersects(ENVELOPE(-116.894531, 
107.402344, 57.433227, -42.146973))")

How can my application know if the field contain ENVELOPE or LINESTRING ?

Any idea can this be done ?

Best reguards,
Leo.